Skip to content

Commit

Permalink
[fix](partial update) Fix NPE when the query statement of an update s…
Browse files Browse the repository at this point in the history
…tatement is a point query in `OriginPlanner` (#26881)

close #26882
We should not use the singleNodePlan to generate the rootPlanFragment if the query is inside a insert statement or distributedPlanner will be null.
introduced in #15491
  • Loading branch information
bobhan1 authored Nov 13, 2023
1 parent 9bb46f4 commit 2853efd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void createPlanFragments(StatementBase statement, Analyzer analyzer, TQue
}
checkAndSetTopnOpt(singleNodePlan);

if (queryOptions.num_nodes == 1 || queryStmt.isPointQuery()) {
if ((queryOptions.num_nodes == 1 || queryStmt.isPointQuery()) && !(statement instanceof InsertStmt)) {
// single-node execution; we're almost done
singleNodePlan = addUnassignedConjuncts(analyzer, singleNodePlan);
fragments.add(new PlanFragment(plannerContext.getNextFragmentId(), singleNodePlan,
Expand Down
15 changes: 15 additions & 0 deletions regression-test/data/update/test_update_mow.out
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,18 @@ date_value DATE Yes false \N NONE
2 20 2 2000.0 2000-01-02
3 3 3 3.0 2000-01-03

-- !sql --
a 1 2023-11-12T00:00 test1 1
b 2 2023-11-12T00:00 test2 2
c 3 2023-11-12T00:00 test3 3

-- !sql --
a 1 2023-11-12T00:00 test1 999
b 2 2023-11-12T00:00 test2 2
c 3 2023-11-12T00:00 test3 3

-- !sql --
a 1 2023-11-12T00:00 test1 999
b 2 2023-11-12T00:00 test2 2
c 3 2022-01-01T00:00 update value 3

31 changes: 31 additions & 0 deletions regression-test/suites/update/test_update_mow.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,35 @@ suite("test_update_mow", "p0") {
sql "DROP TABLE IF EXISTS ${tbName2}"
sql "DROP TABLE IF EXISTS ${tbName3}"
sql "DROP TABLE IF EXISTS ${tbName4}"


sql "set experimental_enable_nereids_planner=false;"
sql "set enable_nereids_planner=false"
sql "sync"
def tableName5 = "test_update_mow_5"
sql "DROP TABLE IF EXISTS ${tableName5}"
sql """ CREATE TABLE ${tableName5} (
k1 varchar(100) NOT NULL,
k2 int(11) NOT NULL,
v1 datetime NULL,
v2 varchar(100) NULL,
v3 int NULL) ENGINE=OLAP UNIQUE KEY(k1, k2) COMMENT 'OLAP'
DISTRIBUTED BY HASH(k1, k2) BUCKETS 3
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"enable_unique_key_merge_on_write" = "true",
"light_schema_change" = "true",
"store_row_column" = "true",
"enable_single_replica_compaction" = "false");"""
sql """insert into ${tableName5} values
("a",1,"2023-11-12 00:00:00","test1",1),
("b",2,"2023-11-12 00:00:00","test2",2),
("c",3,"2023-11-12 00:00:00","test3",3);"""
qt_sql "select * from ${tableName5} order by k1,k2"
sql """update ${tableName5} set v3=999 where k1="a" and k2=1;"""
qt_sql "select * from ${tableName5} order by k1,k2"
sql """update ${tableName5} set v2="update value", v1="2022-01-01 00:00:00" where k1="c" and k2=3;"""
qt_sql "select * from ${tableName5} order by k1,k2"

sql "DROP TABLE IF EXISTS ${tableName5}"
}

0 comments on commit 2853efd

Please sign in to comment.