blob: af0916cb293912bf6edfaf722a3214c9ca9c7e2b [file] [log] [blame]
-- Test if ALTER RENAME followed by ANALYZE executed concurrently with
-- DROP does not introduce inconsistency between master and segments.
-- DROP should be blocked because of ALTER-ANALYZE. After being
-- unblocked, DROP should lookup the old name again and fail with
-- relation does not exist error.
1:drop table if exists t1;
DROP
1:drop table if exists newt1;
DROP
1:create table t1 (a int, b text) distributed by (a);
CREATE
1:insert into t1 select i, 'abc '||i from generate_series(1,10)i;
INSERT 10
1:begin;
BEGIN
1:alter table t1 rename to newt1;
ALTER
1:analyze newt1;
ANALYZE
-- this drop should block to acquire AccessExclusive lock on t1's OID.
2&:drop table t1; <waiting ...>
1:commit;
COMMIT
2<: <... completed>
ERROR: table "t1" does not exist
2:select count(*) from newt1;
count
-------
10
(1 row)
-- DROP is executed concurrently with ALTER RENAME but not ANALYZE.
1:drop table if exists t2;
DROP
1:drop table if exists newt2;
DROP
1:create table t2 (a int, b text) distributed by (a);
CREATE
1:insert into t2 select i, 'pqr '||i from generate_series(1,10)i;
INSERT 10
1:begin;
BEGIN
1:alter table t2 rename to newt2;
ALTER
2&:drop table t2; <waiting ...>
1:commit;
COMMIT
2<: <... completed>
ERROR: table "t2" does not exist
2:select count(*) from newt2;
count
-------
10
(1 row)
-- The same, but with DROP IF EXISTS. (We used to have a bug, where the DROP
-- command found and drop the relation in the segments, but not in master.)
1:drop table if exists t3;
DROP
1:create table t3 (a int, b text) distributed by (a);
CREATE
1:insert into t3 select i, '123 '||i from generate_series(1,10)i;
INSERT 10
1:begin;
BEGIN
1:alter table t3 rename to t3_new;
ALTER
2&:drop table if exists t3; <waiting ...>
1:commit;
COMMIT
2<: <... completed>
DROP
2:select count(*) from t3;
ERROR: relation "t3" does not exist
LINE 1: select count(*) from t3;
^
2:select relname from pg_class where relname like 't3%';
relname
---------
t3_new
(1 row)
2:select relname from gp_dist_random('pg_class') where relname like 't3%';
relname
---------
t3_new
t3_new
t3_new
(3 rows)
1:drop table if exists t3;
DROP
1:create table t3 (a int, b text) distributed by (a);
CREATE
1:insert into t3 select i, '123 '||i from generate_series(1,10)i;
INSERT 10
1:begin;
BEGIN
1:drop table t3;
DROP
2&:drop table if exists t3; <waiting ...>
3&:drop table t3; <waiting ...>
1:commit;
COMMIT
3<: <... completed>
ERROR: table "t3" does not exist
2<: <... completed>
DROP
2:select count(*) from t3;
ERROR: relation "t3" does not exist
LINE 1: select count(*) from t3;
^