!2333 解决(update order by必须在有limit子句时起作用)的问题
Merge pull request !2333 from 魏文韬/issue_fix
This commit is contained in:
@ -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,
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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;
|
||||
Reference in New Issue
Block a user