diff options
author | Pavan Deolasee | 2015-06-02 08:05:17 +0000 |
---|---|---|
committer | Pavan Deolasee | 2015-06-02 08:05:17 +0000 |
commit | 3165b5fde927ff766921270bd56d3236b6c09c21 (patch) | |
tree | 02223be0de19b09a9eea8ca6a4eb6bf6f3277cd3 | |
parent | 38aa5227ac14bbed2e5221ab52ab5c471b53cd94 (diff) |
Invalidate catalog snapshot upon starting a new global session
Also add a test case which demonstrates the problem of using wrong snapshot or
stale command id on datanode-to-datanode connection
-rw-r--r-- | src/backend/utils/init/miscinit.c | 7 | ||||
-rw-r--r-- | src/test/regress/expected/transactions.out | 42 | ||||
-rw-r--r-- | src/test/regress/sql/transactions.sql | 41 |
3 files changed, 90 insertions, 0 deletions
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index c3be358f45..f3693f332f 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -559,6 +559,13 @@ retry: MyFirstBackendId = firstBackend; } + /* + * Also invalidate any catalog snapshot which may become stale since this + * session may join some open transaction which may have done catalog + * changes that are not reflected in the current catalog snapshot + */ + InvalidateCatalogSnapshot(); + if (reset) { /* diff --git a/src/test/regress/expected/transactions.out b/src/test/regress/expected/transactions.out index fbf4a8430f..49d5407517 100644 --- a/src/test/regress/expected/transactions.out +++ b/src/test/regress/expected/transactions.out @@ -533,6 +533,48 @@ select * from xacttest order by a, b; 807 | 324.78 817 | 777.777 (5 rows) +rollback; +-- test case for relations which are created and accessed in the same +-- transaction, especially when the queries require datanode-to-datanode +-- connections. In the past we had failed to use the correct snapshot in such +-- cases +begin; +create table a_snap ( + code char not null, + constraint a_snap_pk primary key (code) +); +create table b_snap ( + a char not null, + num integer not null, + constraint b_snap_pk primary key (a, num) +); +create table c_snap ( + name char not null, + a char, + constraint c_snap_pk primary key (name) +); +insert into a_snap (code) values ('p'); +insert into a_snap (code) values ('q'); +insert into b_snap (a, num) values ('p', 1); +insert into b_snap (a, num) values ('p', 2); +insert into c_snap (name, a) values ('A', 'p'); +insert into c_snap (name, a) values ('B', 'q'); +insert into c_snap (name, a) values ('C', null); +select c_snap.name, ss.code, ss.b_cnt, ss.const +from c_snap left join + (select a_snap.code, coalesce(b_grp.cnt, 0) as b_cnt, -1 as const + from a_snap left join + (select count(1) as cnt, b_snap.a from b_snap group by b_snap.a) as b_grp + on a_snap.code = b_grp.a + ) as ss + on (c_snap.a = ss.code) +order by c_snap.name; + name | code | b_cnt | const +------+------+-------+------- + A | p | 2 | -1 + B | q | 0 | -1 + C | | | +(3 rows) rollback; -- test case for problems with dropping an open relation during abort diff --git a/src/test/regress/sql/transactions.sql b/src/test/regress/sql/transactions.sql index 7cdf41e283..d99fbf6500 100644 --- a/src/test/regress/sql/transactions.sql +++ b/src/test/regress/sql/transactions.sql @@ -315,6 +315,47 @@ update xacttest set a = max_xacttest() + 10 where a > 0; select * from xacttest order by a, b; rollback; +-- test case for relations which are created and accessed in the same +-- transaction, especially when the queries require datanode-to-datanode +-- connections. In the past we had failed to use the correct snapshot in such +-- cases + +begin; + +create table a_snap ( + code char not null, + constraint a_snap_pk primary key (code) +); +create table b_snap ( + a char not null, + num integer not null, + constraint b_snap_pk primary key (a, num) +); +create table c_snap ( + name char not null, + a char, + constraint c_snap_pk primary key (name) +); + +insert into a_snap (code) values ('p'); +insert into a_snap (code) values ('q'); +insert into b_snap (a, num) values ('p', 1); +insert into b_snap (a, num) values ('p', 2); +insert into c_snap (name, a) values ('A', 'p'); +insert into c_snap (name, a) values ('B', 'q'); +insert into c_snap (name, a) values ('C', null); + +select c_snap.name, ss.code, ss.b_cnt, ss.const +from c_snap left join + (select a_snap.code, coalesce(b_grp.cnt, 0) as b_cnt, -1 as const + from a_snap left join + (select count(1) as cnt, b_snap.a from b_snap group by b_snap.a) as b_grp + on a_snap.code = b_grp.a + ) as ss + on (c_snap.a = ss.code) +order by c_snap.name; + +rollback; -- test case for problems with dropping an open relation during abort BEGIN; |