解决继承表不支持select FOR UPDATE SKIP LOCKED 的问题
This commit is contained in:
@ -1602,6 +1602,7 @@ static void expand_inherited_rtentry(PlannerInfo* root, RangeTblEntry* rte, Inde
|
||||
newrc->waitPolicy = oldrc->waitPolicy;
|
||||
newrc->waitSec = oldrc->waitSec;
|
||||
newrc->isParent = false;
|
||||
newrc->bms_nodeids = oldrc->bms_nodeids;
|
||||
|
||||
root->rowMarks = lappend(root->rowMarks, newrc);
|
||||
}
|
||||
|
||||
12
src/test/regress/expected/skiplocked_inherits.out
Normal file
12
src/test/regress/expected/skiplocked_inherits.out
Normal file
@ -0,0 +1,12 @@
|
||||
select pg_sleep(1);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
(1 row)
|
||||
|
||||
select * from skiplocked_inherits_1 order by 1 desc limit 1 FOR UPDATE SKIP LOCKED;
|
||||
id | a1
|
||||
----+-------------------
|
||||
3 | {"name": "test3"}
|
||||
(1 row)
|
||||
|
||||
@ -4,3 +4,5 @@ drop view skiplocked_v3;
|
||||
drop table skiplocked_t1;
|
||||
drop table skiplocked_t2;
|
||||
drop table skiplocked_t3;
|
||||
drop table skiplocked_inherits_2;
|
||||
drop table skiplocked_inherits_1;
|
||||
|
||||
@ -23,3 +23,38 @@ create table IF NOT EXISTS skiplocked_t3(
|
||||
)with (ORIENTATION=COLUMN);
|
||||
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "skiplocked_t3_pkey" for table "skiplocked_t3"
|
||||
insert into skiplocked_t3 values (1, 'one');
|
||||
-- test skiplocked with inherited table
|
||||
drop table if exists skiplocked_inherits_1,skiplocked_inherits_2;
|
||||
NOTICE: table "skiplocked_inherits_1" does not exist, skipping
|
||||
NOTICE: table "skiplocked_inherits_2" does not exist, skipping
|
||||
create table skiplocked_inherits_1(
|
||||
id int unique,
|
||||
a1 jsonb check(a1!='{}')
|
||||
);
|
||||
NOTICE: CREATE TABLE / UNIQUE will create implicit index "skiplocked_inherits_1_id_key" for table "skiplocked_inherits_1"
|
||||
CREATE TABLE skiplocked_inherits_2 (
|
||||
a2 jsonb default '{"name": "John", "age": 30}',
|
||||
a3 jsonb not null
|
||||
) INHERITS (skiplocked_inherits_1);
|
||||
insert into skiplocked_inherits_2 values(1,'{"name":"test1"}','{"id":1001}','[null,"aaa"]');
|
||||
insert into skiplocked_inherits_2 values(2,'{"name":"test2"}',default,'["true"]');
|
||||
insert into skiplocked_inherits_2 values(3,'{"name":"test3"}','{"id":1003}','["a", {"b":1,"name": "John", "age": 30}]');
|
||||
insert into skiplocked_inherits_2 values(4,'{"name":"test"}',default,'["null","T"]');
|
||||
select * from skiplocked_inherits_1 order by id;
|
||||
id | a1
|
||||
----+-------------------
|
||||
1 | {"name": "test1"}
|
||||
2 | {"name": "test2"}
|
||||
3 | {"name": "test3"}
|
||||
4 | {"name": "test"}
|
||||
(4 rows)
|
||||
|
||||
select * from skiplocked_inherits_2 order by id;
|
||||
id | a1 | a2 | a3
|
||||
----+-------------------+-----------------------------+--------------------------------------------
|
||||
1 | {"name": "test1"} | {"id": 1001} | [null, "aaa"]
|
||||
2 | {"name": "test2"} | {"age": 30, "name": "John"} | ["true"]
|
||||
3 | {"name": "test3"} | {"id": 1003} | ["a", {"b": 1, "age": 30, "name": "John"}]
|
||||
4 | {"name": "test"} | {"age": 30, "name": "John"} | ["null", "T"]
|
||||
(4 rows)
|
||||
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
begin;
|
||||
update skiplocked_t1 set info = 'two2' where id = 2;
|
||||
select * from skiplocked_inherits_1 order by 1 desc limit 1 FOR UPDATE SKIP LOCKED;
|
||||
id | a1
|
||||
----+------------------
|
||||
4 | {"name": "test"}
|
||||
(1 row)
|
||||
|
||||
select pg_sleep(5);
|
||||
pg_sleep
|
||||
----------
|
||||
|
||||
@ -1016,7 +1016,7 @@ test: ledger_table_case
|
||||
|
||||
# select ... for update skip locked
|
||||
test: skiplocked_prep
|
||||
test: skiplocked_test1_1 skiplocked_test1_2
|
||||
test: skiplocked_test1_1 skiplocked_test1_2 skiplocked_inherits
|
||||
test: skiplocked_test1_1 skiplocked_test1_3
|
||||
test: skiplocked_post
|
||||
|
||||
|
||||
2
src/test/regress/sql/skiplocked_inherits.sql
Normal file
2
src/test/regress/sql/skiplocked_inherits.sql
Normal file
@ -0,0 +1,2 @@
|
||||
select pg_sleep(1);
|
||||
select * from skiplocked_inherits_1 order by 1 desc limit 1 FOR UPDATE SKIP LOCKED;
|
||||
@ -5,3 +5,5 @@ drop view skiplocked_v3;
|
||||
drop table skiplocked_t1;
|
||||
drop table skiplocked_t2;
|
||||
drop table skiplocked_t3;
|
||||
drop table skiplocked_inherits_2;
|
||||
drop table skiplocked_inherits_1;
|
||||
|
||||
@ -23,4 +23,21 @@ create table IF NOT EXISTS skiplocked_t3(
|
||||
info text,
|
||||
primary key (id)
|
||||
)with (ORIENTATION=COLUMN);
|
||||
insert into skiplocked_t3 values (1, 'one');
|
||||
insert into skiplocked_t3 values (1, 'one');
|
||||
|
||||
-- test skiplocked with inherited table
|
||||
drop table if exists skiplocked_inherits_1,skiplocked_inherits_2;
|
||||
create table skiplocked_inherits_1(
|
||||
id int unique,
|
||||
a1 jsonb check(a1!='{}')
|
||||
);
|
||||
CREATE TABLE skiplocked_inherits_2 (
|
||||
a2 jsonb default '{"name": "John", "age": 30}',
|
||||
a3 jsonb not null
|
||||
) INHERITS (skiplocked_inherits_1);
|
||||
insert into skiplocked_inherits_2 values(1,'{"name":"test1"}','{"id":1001}','[null,"aaa"]');
|
||||
insert into skiplocked_inherits_2 values(2,'{"name":"test2"}',default,'["true"]');
|
||||
insert into skiplocked_inherits_2 values(3,'{"name":"test3"}','{"id":1003}','["a", {"b":1,"name": "John", "age": 30}]');
|
||||
insert into skiplocked_inherits_2 values(4,'{"name":"test"}',default,'["null","T"]');
|
||||
select * from skiplocked_inherits_1 order by id;
|
||||
select * from skiplocked_inherits_2 order by id;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
begin;
|
||||
|
||||
update skiplocked_t1 set info = 'two2' where id = 2;
|
||||
|
||||
select * from skiplocked_inherits_1 order by 1 desc limit 1 FOR UPDATE SKIP LOCKED;
|
||||
select pg_sleep(5);
|
||||
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user