diff --git a/src/common/backend/parser/analyze.cpp b/src/common/backend/parser/analyze.cpp index 8c9503e2a..094e4286f 100644 --- a/src/common/backend/parser/analyze.cpp +++ b/src/common/backend/parser/analyze.cpp @@ -907,8 +907,8 @@ static void transformLimitSortClause(ParseState* pstate, void* stmt, Query* qry, flag->consttype = INT8OID; flag->consttypmod = -1; qry->limitOffset = (Node*)flag; - qry->sortClause = rlist; } + qry->sortClause = rlist; } static void CheckUDRelations(ParseState* pstate, List* sortClause, Node* limitClause, List* returningList, diff --git a/src/gausskernel/runtime/executor/nodeModifyTable.cpp b/src/gausskernel/runtime/executor/nodeModifyTable.cpp index 8c4216711..8d87243fa 100644 --- a/src/gausskernel/runtime/executor/nodeModifyTable.cpp +++ b/src/gausskernel/runtime/executor/nodeModifyTable.cpp @@ -122,6 +122,10 @@ static bool has_dummy_targetlist(Plan* plan) case T_RowToVec: case T_Stream: case T_VecStream: + case T_Limit: + case T_VecLimit: + case T_Sort: + case T_VecSort: is_dummy = true; break; default: @@ -150,7 +154,11 @@ static void CheckPlanOutput(Plan* subPlan, Relation resultRel) case T_VecToRow: case T_RowToVec: case T_PartIterator: - case T_VecPartIterator: { + case T_VecPartIterator: + case T_Limit: + case T_VecLimit: + case T_Sort: + case T_VecSort: { #ifdef ENABLE_MULTIPLE_NODES if (!IS_PGXC_COORDINATOR) { break; diff --git a/src/test/regress/expected/sytcomp_del_upt4orderby.out b/src/test/regress/expected/sytcomp_del_upt4orderby.out index 0bb86b29b..96a71c969 100644 --- a/src/test/regress/expected/sytcomp_del_upt4orderby.out +++ b/src/test/regress/expected/sytcomp_del_upt4orderby.out @@ -199,11 +199,13 @@ WITH max_table as ( rollback; ----update table set col=xxx order by xxx limit xxx explain update sytc_t1 set f2 = 1000 order by f2 desc; - QUERY PLAN ------------------------------------------------------------------- - Update on sytc_t1 (cost=0.00..82.45 rows=5445 width=18) - -> Seq Scan on sytc_t1 (cost=0.00..82.45 rows=5445 width=18) -(2 rows) + QUERY PLAN +------------------------------------------------------------------------ + Update on sytc_t1 (cost=420.33..433.94 rows=5445 width=18) + -> Sort (cost=420.33..433.94 rows=5445 width=18) + Sort Key: f2 DESC + -> Seq Scan on sytc_t1 (cost=0.00..82.45 rows=5445 width=18) +(4 rows) explain update sytc_t1 set f2 = 1000 where f1 > 4900 order by f1 limit 10; QUERY PLAN @@ -545,3 +547,60 @@ select * from sytc_test_sql1 where id<6 order by NLSSORT(id, 'NLS_SORT = generic 5 | name | 5 (4 rows) +drop table if exists sytc_test_sql2; +NOTICE: table "sytc_test_sql2" does not exist, skipping +create table sytc_test_sql2(id1 int, id2 int); +insert into sytc_test_sql2 values(3,1),(2,1),(4,1),(6,1),(5,1); +alter table sytc_test_sql2 add (id2 int default 10); +ERROR: column "id2" of relation "sytc_test_sql2" already exists +begin; +update sytc_test_sql2 set id2 = 20 order by id1 returning *; + id1 | id2 +-----+----- + 2 | 20 + 3 | 20 + 4 | 20 + 5 | 20 + 6 | 20 +(5 rows) + +rollback; +begin; +delete from sytc_test_sql2 order by id1 returning *; + id1 | id2 +-----+----- + 2 | 1 + 3 | 1 + 4 | 1 + 5 | 1 + 6 | 1 +(5 rows) + +rollback; +drop table if exists sytc_test_sql3; +NOTICE: table "sytc_test_sql3" does not exist, skipping +create table sytc_test_sql3(id1 int, id2 int); +insert into sytc_test_sql3 values(1,1); +alter table sytc_test_sql3 drop column id2; +update sytc_test_sql3 set id1 = 1 limit 1; +update sytc_test_sql3 set id1 = 1 order by id1 returning *; + id1 +----- + 1 +(1 row) + +drop table if exists t1; +NOTICE: table "t1" does not exist, skipping +create table t1(a int primary key,b int); +NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "t1_pkey" for table "t1" +insert into t1 values(1,1),(2,2),(3,3),(4,4); +update t1 set a = a+1 order by a desc; +select * from t1; + a | b +---+--- + 5 | 4 + 4 | 3 + 3 | 2 + 2 | 1 +(4 rows) + diff --git a/src/test/regress/sql/sytcomp_del_upt4orderby.sql b/src/test/regress/sql/sytcomp_del_upt4orderby.sql index c4964bded..da342263d 100644 --- a/src/test/regress/sql/sytcomp_del_upt4orderby.sql +++ b/src/test/regress/sql/sytcomp_del_upt4orderby.sql @@ -137,3 +137,27 @@ select * from sytc_test_sql1 where id<6 order by NLSSORT(id, 'NLS_SORT = generic explain delete sytc_test_sql1 where id<6 order by NLSSORT(id,'NLS_SORT = generic_m_ci') limit 1; delete sytc_test_sql1 where id<6 order by NLSSORT(id,'NLS_SORT = generic_m_ci') limit 1; select * from sytc_test_sql1 where id<6 order by NLSSORT(id, 'NLS_SORT = generic_m_ci'); + +drop table if exists sytc_test_sql2; +create table sytc_test_sql2(id1 int, id2 int); +insert into sytc_test_sql2 values(3,1),(2,1),(4,1),(6,1),(5,1); +alter table sytc_test_sql2 add (id2 int default 10); +begin; +update sytc_test_sql2 set id2 = 20 order by id1 returning *; +rollback; +begin; +delete from sytc_test_sql2 order by id1 returning *; +rollback; + +drop table if exists sytc_test_sql3; +create table sytc_test_sql3(id1 int, id2 int); +insert into sytc_test_sql3 values(1,1); +alter table sytc_test_sql3 drop column id2; +update sytc_test_sql3 set id1 = 1 limit 1; +update sytc_test_sql3 set id1 = 1 order by id1 returning *; + +drop table if exists t1; +create table t1(a int primary key,b int); +insert into t1 values(1,1),(2,2),(3,3),(4,4); +update t1 set a = a+1 order by a desc; +select * from t1; \ No newline at end of file