提交 974e78dc 编写于 作者: J Jimmy Yih 提交者: Xin Zhang

Fix ICW tests after introducing relfilenode counter change.

These tests assumed OID == relfilenode. We updated the tests to not assume it
anymore.
上级 3ba88f6d
......@@ -13,16 +13,18 @@
-- * Verify that at least two files were fsync'ed by checkpointer.
--
begin;
create function num_dirty(relfilenode oid) returns bigint as
create function num_dirty(relid oid) returns bigint as
$$
select count(*) from dirty_buffers()
as (tablespace oid, database oid, relfilenode oid, block int)
where relfilenode = $1;
where relfilenode in
(select relfilenode from pg_class
where oid=$1);
$$ language sql;
-- Wait until number of dirty buffers for the specified relfiles drops
-- to 0 or timeout occurs. Returns false if timeout occured.
create function wait_for_bgwriter(
relfilenode oid,
relid oid,
timeout int)
returns boolean as
$$
......
......@@ -14,17 +14,19 @@
--
begin;
create function num_dirty(relfilenode oid) returns bigint as
create function num_dirty(relid oid) returns bigint as
$$
select count(*) from dirty_buffers()
as (tablespace oid, database oid, relfilenode oid, block int)
where relfilenode = $1;
where relfilenode in
(select relfilenode from pg_class
where oid=$1);
$$ language sql;
-- Wait until number of dirty buffers for the specified relfiles drops
-- to 0 or timeout occurs. Returns false if timeout occured.
create function wait_for_bgwriter(
relfilenode oid,
relid oid,
timeout int)
returns boolean as
$$
......@@ -114,4 +116,4 @@ select dirty_buffers() from gp_dist_random('gp_id')
\!if [[ $(gpfaultinjector -f fsync_counter -m async -y status -o 0 --seg_dbid 2 | grep 'num times hit' | sed -e 's/^.*num times hit[^0-9]*\([0-9]*\)[^0-9]*$/\1/') -gt 2 ]]; then echo "PASS: buffers synced"; else echo "FAIL: buffers not synced"; fi
-- Reset all faults.
\!gpfaultinjector -f all -m async -y reset -o 0 -H ALL -r primary | grep -i 'error\|fail\|done' | sed -e 's/.*DONE$/DONE/'
\ No newline at end of file
\!gpfaultinjector -f all -m async -y reset -o 0 -H ALL -r primary | grep -i 'error\|fail\|done' | sed -e 's/.*DONE$/DONE/'
......@@ -7,3 +7,17 @@
-- comments at the end of each line thwarts that.
CREATE OR REPLACE FUNCTION gp_ao_or_aocs_seg_name(rel text, segno OUT integer, tupcount OUT bigint, modcount OUT bigint, formatversion OUT smallint, state OUT smallint) RETURNS SETOF record as $$ declare relstorage_var char; /* in func */ begin /* in func */ select relstorage into relstorage_var from pg_class where oid = rel::regclass; /* in func */ if relstorage_var = 'c' then /* in func */ for segno, tupcount, modcount, formatversion, state in SELECT DISTINCT x.segno, x.tupcount, x.modcount, x.formatversion, x.state FROM gp_toolkit.__gp_aocsseg_name(rel) x loop /* in func */ return next; /* in func */ end loop; /* in func */ else /* in func */ for segno, tupcount, modcount, formatversion, state in SELECT x.segno, x.tupcount, x.modcount, x.formatversion, x.state FROM gp_toolkit.__gp_aoseg_name(rel) x loop /* in func */ return next; /* in func */ end loop; /* in func */ end if; /* in func */ end; /* in func */ $$ LANGUAGE plpgsql;
CREATE
-- Show locks in master and in segments. Because the number of segments
-- in the cluster depends on configuration, we print only summary information
-- of the locks in segments. If a relation is locked only on one segment,
-- we print that as a special case, but otherwise we just print "n segments",
-- meaning the relation is locked on more than one segment.
create or replace view locktest_master as select coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' when relname like 'pg_aoseg%' then 'aoseg table' when relname like 'pg_aovisimap%index' then 'aovisimap index' when relname like 'pg_aovisimap%' then 'aovisimap table' else relname end, 'dropped table'), mode, locktype, 'master'::text as node from pg_locks l left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)), pg_database d where relation is not null and l.database = d.oid and (relname <> 'gp_fault_strategy' and relname != 'locktest_master' or relname is NULL) and d.datname = current_database() and l.gp_segment_id = -1 group by l.gp_segment_id, relation, relname, locktype, mode order by 1, 3, 2;
CREATE
create or replace view locktest_segments_dist as select relname, mode, locktype, l.gp_segment_id as node, relation from pg_locks l left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)), pg_database d where relation is not null and l.database = d.oid and (relname <> 'gp_fault_strategy' and relname != 'locktest_segments_dist' or relname is NULL) and d.datname = current_database() and l.gp_segment_id > -1 group by l.gp_segment_id, relation, relname, locktype, mode;
CREATE
create or replace view locktest_segments as SELECT coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' when relname like 'pg_aoseg%' then 'aoseg table' when relname like 'pg_aovisimap%index' then 'aovisimap index' when relname like 'pg_aovisimap%' then 'aovisimap table' else relname end, 'dropped table'), mode, locktype, case when count(*) = 1 then '1 segment' else 'n segments' end as node FROM gp_dist_random('locktest_segments_dist') group by relname, relation, mode, locktype;
CREATE
......@@ -5,24 +5,12 @@ DROP TABLE IF EXISTS ao;
CREATE TABLE ao (a INT) WITH (appendonly=true, orientation=@orientation@) DISTRIBUTED BY (a);
insert into ao select generate_series(1,100);
DROP VIEW IF EXISTS locktest;
create view locktest as select coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
else relname end, 'dropped table'),
mode,
locktype from
pg_locks l left outer join pg_class c on (l.relation = c.oid),
pg_database d where relation is not null and l.database = d.oid and
l.gp_segment_id = -1 and
relname != 'gp_fault_strategy' and
d.datname = current_database() order by 1, 3, 2;
-- The actual test begins
1: BEGIN;
2: BEGIN;
2: DELETE FROM ao WHERE a = 1;
2: SELECT * FROM locktest WHERE coalesce = 'ao';
2: SELECT * FROM locktest_master WHERE coalesce = 'ao';
2: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
1&: DELETE FROM ao WHERE a = 2;
2: COMMIT;
1<:
......
......@@ -5,24 +5,12 @@ DROP TABLE IF EXISTS ao;
CREATE TABLE ao (a INT, b INT) WITH (appendonly=true, orientation=@orientation@);
INSERT INTO ao SELECT i as a, i as b FROM generate_series(1,10) AS i;
DROP VIEW IF EXISTS locktest;
create view locktest as select coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
else relname end, 'dropped table'),
mode,
locktype from
pg_locks l left outer join pg_class c on (l.relation = c.oid),
pg_database d where relation is not null and l.database = d.oid and
l.gp_segment_id = -1 and
relname != 'gp_fault_strategy' and
d.datname = current_database() order by 1, 3, 2;
-- The actual test begins
1: BEGIN;
2: BEGIN;
2: UPDATE ao SET b = 42 WHERE a = 1;
2: SELECT * FROM locktest WHERE coalesce = 'ao';
2: SELECT * FROM locktest_master WHERE coalesce = 'ao';
2: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
1&: UPDATE ao SET b = 42 WHERE a = 2;
2: COMMIT;
1<:
......
......@@ -5,19 +5,6 @@ DROP TABLE IF EXISTS ao;
CREATE TABLE ao (a INT, b INT) WITH (appendonly=true, orientation=@orientation@);
INSERT INTO ao SELECT i as a, i as b FROM generate_series(1,10) AS i;
DROP VIEW IF EXISTS locktest;
create view locktest as select coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
else relname end, 'dropped table'),
mode,
locktype from
pg_locks l left outer join pg_class c on (l.relation = c.oid),
pg_database d where relation is not null and l.database = d.oid and
l.gp_segment_id = -1 and
relname != 'gp_fault_strategy' and
d.datname = current_database() order by 1, 3, 2;
-- The actual test begins
1: BEGIN;
2: BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
......
......@@ -27,19 +27,6 @@ insert into ao select generate_series(1,1000);
insert into ao select generate_series(1,1000);
insert into ao2 select generate_series(1,1000);
DROP VIEW IF EXISTS locktest;
create view locktest as select coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
else relname end, 'dropped table'),
mode,
locktype from
pg_locks l left outer join pg_class c on (l.relation = c.oid),
pg_database d where relation is not null and l.database = d.oid and
l.gp_segment_id = -1 and
relname != 'gp_fault_strategy' and
d.datname = current_database() order by 1, 3, 2;
-- The actual test begins
DELETE FROM ao WHERE a < 128;
1: BEGIN;
......@@ -47,7 +34,8 @@ DELETE FROM ao WHERE a < 128;
2U: SELECT segno, case when tupcount = 0 then 'zero' when tupcount = 1 then 'one' when tupcount <= 5 then 'few' else 'many' end FROM gp_ao_or_aocs_seg_name('ao');
2: VACUUM ao;
1: SELECT COUNT(*) FROM ao;
1: SELECT * FROM locktest WHERE coalesce = 'ao';
1: SELECT * FROM locktest_master WHERE coalesce = 'ao';
1: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
1: COMMIT;
1: SELECT COUNT(*) FROM ao;
3: INSERT INTO ao VALUES (0);
......
......@@ -24,23 +24,11 @@ insert into ao select generate_series(1,1000);
insert into ao select generate_series(1,1000);
insert into ao select generate_series(1,1000);
DROP VIEW IF EXISTS locktest;
create view locktest as select coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
else relname end, 'dropped table'),
mode,
locktype from
pg_locks l left outer join pg_class c on (l.relation = c.oid),
pg_database d where relation is not null and l.database = d.oid and
l.gp_segment_id = -1 and
relname != 'gp_fault_strategy' and
d.datname = current_database() order by 1, 3, 2;
DELETE FROM ao WHERE a < 128;
1: BEGIN;
1: SELECT COUNT(*) FROM ao;
1: SELECT * FROM locktest WHERE coalesce = 'ao';
1: SELECT * FROM locktest_master WHERE coalesce = 'ao';
1: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
2&: VACUUM ao;
1: COMMIT;
2<:
......
......@@ -8,11 +8,6 @@ CREATE
insert into ao select generate_series(1,100);
INSERT 100
DROP VIEW IF EXISTS locktest;
DROP
create view locktest as select coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' else relname end, 'dropped table'), mode, locktype from pg_locks l left outer join pg_class c on (l.relation = c.oid), pg_database d where relation is not null and l.database = d.oid and l.gp_segment_id = -1 and relname != 'gp_fault_strategy' and d.datname = current_database() order by 1, 3, 2;
CREATE
-- The actual test begins
1: BEGIN;
BEGIN
......@@ -20,12 +15,17 @@ BEGIN
BEGIN
2: DELETE FROM ao WHERE a = 1;
DELETE 1
2: SELECT * FROM locktest WHERE coalesce = 'ao';
coalesce|mode |locktype
--------+-------------------+------------------------
ao |AccessExclusiveLock|append-only segment file
ao |ExclusiveLock |relation
2: SELECT * FROM locktest_master WHERE coalesce = 'ao';
coalesce|mode |locktype |node
--------+-------------------+------------------------+------
ao |AccessExclusiveLock|append-only segment file|master
ao |ExclusiveLock |relation |master
(2 rows)
2: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
coalesce|mode |locktype|node
--------+----------------+--------+---------
ao |RowExclusiveLock|relation|1 segment
(1 row)
1&: DELETE FROM ao WHERE a = 2; <waiting ...>
2: COMMIT;
COMMIT
......
......@@ -8,11 +8,6 @@ CREATE
insert into ao select generate_series(1,100);
INSERT 100
DROP VIEW IF EXISTS locktest;
DROP
create view locktest as select coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' else relname end, 'dropped table'), mode, locktype from pg_locks l left outer join pg_class c on (l.relation = c.oid), pg_database d where relation is not null and l.database = d.oid and l.gp_segment_id = -1 and relname != 'gp_fault_strategy' and d.datname = current_database() order by 1, 3, 2;
CREATE
-- The actual test begins
1: BEGIN;
BEGIN
......@@ -20,12 +15,17 @@ BEGIN
BEGIN
2: DELETE FROM ao WHERE a = 1;
DELETE 1
2: SELECT * FROM locktest WHERE coalesce = 'ao';
coalesce|mode |locktype
--------+-------------------+------------------------
ao |AccessExclusiveLock|append-only segment file
ao |ExclusiveLock |relation
2: SELECT * FROM locktest_master WHERE coalesce = 'ao';
coalesce|mode |locktype |node
--------+-------------------+------------------------+------
ao |AccessExclusiveLock|append-only segment file|master
ao |ExclusiveLock |relation |master
(2 rows)
2: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
coalesce|mode |locktype|node
--------+----------------+--------+---------
ao |RowExclusiveLock|relation|1 segment
(1 row)
1&: DELETE FROM ao WHERE a = 2; <waiting ...>
2: COMMIT;
COMMIT
......
......@@ -8,11 +8,6 @@ CREATE
insert into ao select generate_series(1,100);
INSERT 100
DROP VIEW IF EXISTS locktest;
DROP
create view locktest as select coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' else relname end, 'dropped table'), mode, locktype from pg_locks l left outer join pg_class c on (l.relation = c.oid), pg_database d where relation is not null and l.database = d.oid and l.gp_segment_id = -1 and relname != 'gp_fault_strategy' and d.datname = current_database() order by 1, 3, 2;
CREATE
-- The actual test begins
1: BEGIN;
BEGIN
......@@ -20,13 +15,19 @@ BEGIN
BEGIN
2: DELETE FROM ao WHERE a = 1;
DELETE 1
2: SELECT * FROM locktest WHERE coalesce = 'ao';
coalesce|mode |locktype
--------+-------------------+------------------------
ao |AccessExclusiveLock|append-only segment file
ao |AccessShareLock |relation
ao |ExclusiveLock |relation
2: SELECT * FROM locktest_master WHERE coalesce = 'ao';
coalesce|mode |locktype |node
--------+-------------------+------------------------+------
ao |AccessExclusiveLock|append-only segment file|master
ao |AccessShareLock |relation |master
ao |ExclusiveLock |relation |master
(3 rows)
2: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
coalesce|mode |locktype|node
--------+----------------+--------+----------
ao |AccessShareLock |relation|n segments
ao |RowExclusiveLock|relation|n segments
(2 rows)
1&: DELETE FROM ao WHERE a = 2; <waiting ...>
2: COMMIT;
COMMIT
......
......@@ -8,11 +8,6 @@ CREATE
INSERT INTO ao SELECT i as a, i as b FROM generate_series(1,10) AS i;
INSERT 10
DROP VIEW IF EXISTS locktest;
DROP
create view locktest as select coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' else relname end, 'dropped table'), mode, locktype from pg_locks l left outer join pg_class c on (l.relation = c.oid), pg_database d where relation is not null and l.database = d.oid and l.gp_segment_id = -1 and relname != 'gp_fault_strategy' and d.datname = current_database() order by 1, 3, 2;
CREATE
-- The actual test begins
1: BEGIN;
BEGIN
......@@ -20,11 +15,17 @@ BEGIN
BEGIN
2: UPDATE ao SET b = 42 WHERE a = 1;
UPDATE 1
2: SELECT * FROM locktest WHERE coalesce = 'ao';
coalesce|mode |locktype
--------+-------------------+------------------------
ao |AccessExclusiveLock|append-only segment file
ao |ExclusiveLock |relation
2: SELECT * FROM locktest_master WHERE coalesce = 'ao';
coalesce|mode |locktype |node
--------+-------------------+------------------------+------
ao |AccessExclusiveLock|append-only segment file|master
ao |ExclusiveLock |relation |master
(2 rows)
2: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
coalesce|mode |locktype |node
--------+-------------------+------------------------+---------
ao |AccessExclusiveLock|append-only segment file|1 segment
ao |RowExclusiveLock |relation |1 segment
(2 rows)
1&: UPDATE ao SET b = 42 WHERE a = 2; <waiting ...>
2: COMMIT;
......
......@@ -8,11 +8,6 @@ CREATE
INSERT INTO ao SELECT i as a, i as b FROM generate_series(1,10) AS i;
INSERT 10
DROP VIEW IF EXISTS locktest;
DROP
create view locktest as select coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' else relname end, 'dropped table'), mode, locktype from pg_locks l left outer join pg_class c on (l.relation = c.oid), pg_database d where relation is not null and l.database = d.oid and l.gp_segment_id = -1 and relname != 'gp_fault_strategy' and d.datname = current_database() order by 1, 3, 2;
CREATE
-- The actual test begins
1: BEGIN;
BEGIN
......@@ -20,11 +15,17 @@ BEGIN
BEGIN
2: UPDATE ao SET b = 42 WHERE a = 1;
UPDATE 1
2: SELECT * FROM locktest WHERE coalesce = 'ao';
coalesce|mode |locktype
--------+-------------------+------------------------
ao |AccessExclusiveLock|append-only segment file
ao |ExclusiveLock |relation
2: SELECT * FROM locktest_master WHERE coalesce = 'ao';
coalesce|mode |locktype |node
--------+-------------------+------------------------+------
ao |AccessExclusiveLock|append-only segment file|master
ao |ExclusiveLock |relation |master
(2 rows)
2: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
coalesce|mode |locktype |node
--------+-------------------+------------------------+---------
ao |AccessExclusiveLock|append-only segment file|1 segment
ao |RowExclusiveLock |relation |1 segment
(2 rows)
1&: UPDATE ao SET b = 42 WHERE a = 2; <waiting ...>
2: COMMIT;
......
......@@ -8,11 +8,6 @@ CREATE
INSERT INTO ao SELECT i as a, i as b FROM generate_series(1,10) AS i;
INSERT 10
DROP VIEW IF EXISTS locktest;
DROP
create view locktest as select coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' else relname end, 'dropped table'), mode, locktype from pg_locks l left outer join pg_class c on (l.relation = c.oid), pg_database d where relation is not null and l.database = d.oid and l.gp_segment_id = -1 and relname != 'gp_fault_strategy' and d.datname = current_database() order by 1, 3, 2;
CREATE
-- The actual test begins
1: BEGIN;
BEGIN
......@@ -20,12 +15,19 @@ BEGIN
BEGIN
2: UPDATE ao SET b = 42 WHERE a = 1;
UPDATE 1
2: SELECT * FROM locktest WHERE coalesce = 'ao';
coalesce|mode |locktype
--------+-------------------+------------------------
ao |AccessExclusiveLock|append-only segment file
ao |AccessShareLock |relation
ao |ExclusiveLock |relation
2: SELECT * FROM locktest_master WHERE coalesce = 'ao';
coalesce|mode |locktype |node
--------+-------------------+------------------------+------
ao |AccessExclusiveLock|append-only segment file|master
ao |AccessShareLock |relation |master
ao |ExclusiveLock |relation |master
(3 rows)
2: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
coalesce|mode |locktype |node
--------+-------------------+------------------------+----------
ao |AccessExclusiveLock|append-only segment file|1 segment
ao |AccessShareLock |relation |n segments
ao |RowExclusiveLock |relation |n segments
(3 rows)
1&: UPDATE ao SET b = 42 WHERE a = 2; <waiting ...>
2: COMMIT;
......
......@@ -8,11 +8,6 @@ CREATE
INSERT INTO ao SELECT i as a, i as b FROM generate_series(1,10) AS i;
INSERT 10
DROP VIEW IF EXISTS locktest;
DROP
create view locktest as select coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' else relname end, 'dropped table'), mode, locktype from pg_locks l left outer join pg_class c on (l.relation = c.oid), pg_database d where relation is not null and l.database = d.oid and l.gp_segment_id = -1 and relname != 'gp_fault_strategy' and d.datname = current_database() order by 1, 3, 2;
CREATE
-- The actual test begins
1: BEGIN;
BEGIN
......
......@@ -53,11 +53,6 @@ INSERT 1000
insert into ao2 select generate_series(1,1000);
INSERT 1000
DROP VIEW IF EXISTS locktest;
DROP
create view locktest as select coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' else relname end, 'dropped table'), mode, locktype from pg_locks l left outer join pg_class c on (l.relation = c.oid), pg_database d where relation is not null and l.database = d.oid and l.gp_segment_id = -1 and relname != 'gp_fault_strategy' and d.datname = current_database() order by 1, 3, 2;
CREATE
-- The actual test begins
DELETE FROM ao WHERE a < 128;
DELETE 2667
......@@ -80,10 +75,15 @@ count
-----
18333
(1 row)
1: SELECT * FROM locktest WHERE coalesce = 'ao';
coalesce|mode |locktype
--------+---------------+--------
ao |AccessShareLock|relation
1: SELECT * FROM locktest_master WHERE coalesce = 'ao';
coalesce|mode |locktype|node
--------+---------------+--------+------
ao |AccessShareLock|relation|master
(1 row)
1: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
coalesce|mode |locktype|node
--------+---------------+--------+----------
ao |AccessShareLock|relation|n segments
(1 row)
1: COMMIT;
COMMIT
......
......@@ -53,11 +53,6 @@ INSERT 1000
insert into ao2 select generate_series(1,1000);
INSERT 1000
DROP VIEW IF EXISTS locktest;
DROP
create view locktest as select coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' else relname end, 'dropped table'), mode, locktype from pg_locks l left outer join pg_class c on (l.relation = c.oid), pg_database d where relation is not null and l.database = d.oid and l.gp_segment_id = -1 and relname != 'gp_fault_strategy' and d.datname = current_database() order by 1, 3, 2;
CREATE
-- The actual test begins
DELETE FROM ao WHERE a < 128;
DELETE 2667
......@@ -80,10 +75,16 @@ count
-----
18333
(1 row)
1: SELECT * FROM locktest WHERE coalesce = 'ao';
coalesce|mode |locktype
--------+---------------+--------
ao |AccessShareLock|relation
1: SELECT * FROM locktest_master WHERE coalesce = 'ao';
1: SELECT * FROM locktest_master WHERE coalesce = 'ao';
coalesce|mode |locktype|node
--------+---------------+--------+------
ao |AccessShareLock|relation|master
(1 row)
1: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
coalesce|mode |locktype|node
--------+---------------+--------+----------
ao |AccessShareLock|relation|n segments
(1 row)
1: COMMIT;
COMMIT
......
......@@ -47,11 +47,6 @@ INSERT 1000
insert into ao select generate_series(1,1000);
INSERT 1000
DROP VIEW IF EXISTS locktest;
DROP
create view locktest as select coalesce( case when relname like 'pg_toast%index' then 'toast index' when relname like 'pg_toast%' then 'toast table' else relname end, 'dropped table'), mode, locktype from pg_locks l left outer join pg_class c on (l.relation = c.oid), pg_database d where relation is not null and l.database = d.oid and l.gp_segment_id = -1 and relname != 'gp_fault_strategy' and d.datname = current_database() order by 1, 3, 2;
CREATE
DELETE FROM ao WHERE a < 128;
DELETE 2667
1: BEGIN;
......@@ -61,10 +56,15 @@ count
-----
18333
(1 row)
1: SELECT * FROM locktest WHERE coalesce = 'ao';
coalesce|mode |locktype
--------+---------------+--------
ao |AccessShareLock|relation
1: SELECT * FROM locktest_master WHERE coalesce = 'ao';
coalesce|mode |locktype|node
--------+---------------+--------+------
ao |AccessShareLock|relation|master
(1 row)
1: SELECT * FROM locktest_segments WHERE coalesce = 'ao';
coalesce|mode |locktype|node
--------+---------------+--------+----------
ao |AccessShareLock|relation|n segments
(1 row)
2&: VACUUM ao; <waiting ...>
1: COMMIT;
......
......@@ -27,3 +27,61 @@ begin /* in func */
end if; /* in func */
end; /* in func */
$$ LANGUAGE plpgsql;
-- Show locks in master and in segments. Because the number of segments
-- in the cluster depends on configuration, we print only summary information
-- of the locks in segments. If a relation is locked only on one segment,
-- we print that as a special case, but otherwise we just print "n segments",
-- meaning the relation is locked on more than one segment.
create or replace view locktest_master as
select coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
when relname like 'pg_aoseg%' then 'aoseg table'
when relname like 'pg_aovisimap%index' then 'aovisimap index'
when relname like 'pg_aovisimap%' then 'aovisimap table'
else relname end, 'dropped table'),
mode,
locktype,
'master'::text as node
from pg_locks l
left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)),
pg_database d
where relation is not null
and l.database = d.oid
and (relname <> 'gp_fault_strategy' and relname != 'locktest_master' or relname is NULL)
and d.datname = current_database()
and l.gp_segment_id = -1
group by l.gp_segment_id, relation, relname, locktype, mode
order by 1, 3, 2;
create or replace view locktest_segments_dist as
select relname,
mode,
locktype,
l.gp_segment_id as node,
relation
from pg_locks l
left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)),
pg_database d
where relation is not null
and l.database = d.oid
and (relname <> 'gp_fault_strategy' and relname != 'locktest_segments_dist' or relname is NULL)
and d.datname = current_database()
and l.gp_segment_id > -1
group by l.gp_segment_id, relation, relname, locktype, mode;
create or replace view locktest_segments as
SELECT coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
when relname like 'pg_aoseg%' then 'aoseg table'
when relname like 'pg_aovisimap%index' then 'aovisimap index'
when relname like 'pg_aovisimap%' then 'aovisimap table'
else relname end, 'dropped table'),
mode,
locktype,
case when count(*) = 1 then '1 segment'
else 'n segments' end as node
FROM gp_dist_random('locktest_segments_dist')
group by relname, relation, mode, locktype;
......@@ -4,7 +4,7 @@ CREATE TABLE ao (a INT, b INT) WITH (appendonly=true);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO ao SELECT i as a, i as b FROM generate_series(1, 100) AS i;
create or replace view locktest as
create or replace view locktest_master as
select coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
......@@ -14,70 +14,113 @@ select coalesce(
else relname end, 'dropped table'),
mode,
locktype,
case when l.gp_segment_id = -1 then 'master'
when COUNT(*) = 1 then '1 segment'
else 'n segments' end AS node
'master'::text as node
from pg_locks l
left outer join pg_class c on (l.relation = c.oid),
left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)),
pg_database d
where relation is not null
and l.database = d.oid
and (relname <> 'gp_fault_strategy' or relname IS NULL)
and (relname <> 'gp_fault_strategy' and relname != 'locktest_master' or relname is NULL)
and d.datname = current_database()
group by l.gp_segment_id = -1, relation, relname, locktype, mode
and l.gp_segment_id = -1
group by l.gp_segment_id, relation, relname, locktype, mode
order by 1, 3, 2;
create or replace view locktest_segments_dist as
select relname,
mode,
locktype,
l.gp_segment_id as node,
relation
from pg_locks l
left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)),
pg_database d
where relation is not null
and l.database = d.oid
and (relname <> 'gp_fault_strategy' and relname != 'locktest_segments_dist' or relname is NULL)
and d.datname = current_database()
and l.gp_segment_id > -1
group by l.gp_segment_id, relation, relname, locktype, mode;
create or replace view locktest_segments as
SELECT coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
when relname like 'pg_aoseg%' then 'aoseg table'
when relname like 'pg_aovisimap%index' then 'aovisimap index'
when relname like 'pg_aovisimap%' then 'aovisimap table'
else relname end, 'dropped table'),
mode,
locktype,
case when count(*) = 1 then '1 segment'
else 'n segments' end as node
FROM gp_dist_random('locktest_segments_dist')
group by relname, relation, mode, locktype;
-- Actual test begins
BEGIN;
INSERT INTO ao VALUES (200, 200);
SELECT * FROM locktest;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+-----------
ao | AccessExclusiveLock | append-only segment file | 1 segment
SELECT * FROM locktest_master;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+--------
ao | AccessExclusiveLock | append-only segment file | master
ao | RowExclusiveLock | relation | 1 segment
ao | RowExclusiveLock | relation | master
locktest | AccessShareLock | relation | master
pg_class | AccessShareLock | relation | master
pg_class_oid_index | AccessShareLock | relation | master
pg_class_relname_nsp_index | AccessShareLock | relation | master
pg_locks | AccessShareLock | relation | master
(9 rows)
(6 rows)
SELECT * FROM locktest_segments;
coalesce | mode | locktype | node
----------+---------------------+--------------------------+------------
ao | RowExclusiveLock | relation | 1 segment
ao | AccessExclusiveLock | append-only segment file | 1 segment
pg_class | AccessShareLock | relation | n segments
(3 rows)
COMMIT;
BEGIN;
DELETE FROM ao WHERE a = 1;
SELECT * FROM locktest;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+-----------
SELECT * FROM locktest_master;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+--------
ao | AccessExclusiveLock | append-only segment file | master
ao | ExclusiveLock | relation | master
ao | RowExclusiveLock | relation | 1 segment
aovisimap index | RowExclusiveLock | relation | 1 segment
aovisimap table | RowExclusiveLock | relation | 1 segment
locktest | AccessShareLock | relation | master
pg_class | AccessShareLock | relation | master
pg_class_oid_index | AccessShareLock | relation | master
pg_class_relname_nsp_index | AccessShareLock | relation | master
pg_locks | AccessShareLock | relation | master
(10 rows)
(6 rows)
SELECT * FROM locktest_segments;
coalesce | mode | locktype | node
-----------------+------------------+----------+------------
pg_class | AccessShareLock | relation | n segments
ao | RowExclusiveLock | relation | 1 segment
aovisimap index | RowExclusiveLock | relation | 1 segment
aovisimap table | RowExclusiveLock | relation | 1 segment
(4 rows)
COMMIT;
BEGIN;
UPDATE ao SET b = -1 WHERE a = 2;
SELECT * FROM locktest;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+-----------
ao | AccessExclusiveLock | append-only segment file | 1 segment
SELECT * FROM locktest_master;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+--------
ao | AccessExclusiveLock | append-only segment file | master
ao | ExclusiveLock | relation | master
ao | RowExclusiveLock | relation | 1 segment
aovisimap index | RowExclusiveLock | relation | 1 segment
aovisimap table | RowExclusiveLock | relation | 1 segment
locktest | AccessShareLock | relation | master
pg_class | AccessShareLock | relation | master
pg_class_oid_index | AccessShareLock | relation | master
pg_class_relname_nsp_index | AccessShareLock | relation | master
pg_locks | AccessShareLock | relation | master
(11 rows)
(6 rows)
SELECT * FROM locktest_segments;
coalesce | mode | locktype | node
-----------------+---------------------+--------------------------+------------
ao | AccessExclusiveLock | append-only segment file | 1 segment
ao | RowExclusiveLock | relation | 1 segment
aovisimap index | RowExclusiveLock | relation | 1 segment
aovisimap table | RowExclusiveLock | relation | 1 segment
pg_class | AccessShareLock | relation | n segments
(5 rows)
COMMIT;
......@@ -4,7 +4,7 @@ CREATE TABLE ao (a INT, b INT) WITH (appendonly=true);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'a' as the Greenplum Database data distribution key for this table.
HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew.
INSERT INTO ao SELECT i as a, i as b FROM generate_series(1, 100) AS i;
create or replace view locktest as
create or replace view locktest_master as
select coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
......@@ -14,74 +14,117 @@ select coalesce(
else relname end, 'dropped table'),
mode,
locktype,
case when l.gp_segment_id = -1 then 'master'
when COUNT(*) = 1 then '1 segment'
else 'n segments' end AS node
'master'::text as node
from pg_locks l
left outer join pg_class c on (l.relation = c.oid),
left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)),
pg_database d
where relation is not null
and l.database = d.oid
and (relname <> 'gp_fault_strategy' or relname IS NULL)
and (relname <> 'gp_fault_strategy' and relname != 'locktest_master' or relname is NULL)
and d.datname = current_database()
group by l.gp_segment_id = -1, relation, relname, locktype, mode
and l.gp_segment_id = -1
group by l.gp_segment_id, relation, relname, locktype, mode
order by 1, 3, 2;
create or replace view locktest_segments_dist as
select relname,
mode,
locktype,
l.gp_segment_id as node,
relation
from pg_locks l
left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)),
pg_database d
where relation is not null
and l.database = d.oid
and (relname <> 'gp_fault_strategy' and relname != 'locktest_segments_dist' or relname is NULL)
and d.datname = current_database()
and l.gp_segment_id > -1
group by l.gp_segment_id, relation, relname, locktype, mode;
create or replace view locktest_segments as
SELECT coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
when relname like 'pg_aoseg%' then 'aoseg table'
when relname like 'pg_aovisimap%index' then 'aovisimap index'
when relname like 'pg_aovisimap%' then 'aovisimap table'
else relname end, 'dropped table'),
mode,
locktype,
case when count(*) = 1 then '1 segment'
else 'n segments' end as node
FROM gp_dist_random('locktest_segments_dist')
group by relname, relation, mode, locktype;
-- Actual test begins
BEGIN;
INSERT INTO ao VALUES (200, 200);
SELECT * FROM locktest;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+-----------
ao | AccessExclusiveLock | append-only segment file | 1 segment
SELECT * FROM locktest_master;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+--------
ao | AccessExclusiveLock | append-only segment file | master
ao | RowExclusiveLock | relation | 1 segment
ao | RowExclusiveLock | relation | master
locktest | AccessShareLock | relation | master
pg_class | AccessShareLock | relation | master
pg_class_oid_index | AccessShareLock | relation | master
pg_class_relname_nsp_index | AccessShareLock | relation | master
pg_locks | AccessShareLock | relation | master
(9 rows)
(6 rows)
SELECT * FROM locktest_segments;
coalesce | mode | locktype | node
----------+---------------------+--------------------------+------------
ao | AccessExclusiveLock | append-only segment file | 1 segment
pg_class | AccessShareLock | relation | n segments
ao | RowExclusiveLock | relation | 1 segment
(3 rows)
COMMIT;
BEGIN;
DELETE FROM ao WHERE a = 1;
SELECT * FROM locktest;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+------------
SELECT * FROM locktest_master;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+--------
ao | AccessExclusiveLock | append-only segment file | master
ao | AccessShareLock | relation | n segments
ao | AccessShareLock | relation | master
ao | ExclusiveLock | relation | master
ao | RowExclusiveLock | relation | n segments
aovisimap index | RowExclusiveLock | relation | 1 segment
aovisimap table | RowExclusiveLock | relation | 1 segment
locktest | AccessShareLock | relation | master
pg_class | AccessShareLock | relation | master
pg_class_oid_index | AccessShareLock | relation | master
pg_class_relname_nsp_index | AccessShareLock | relation | master
pg_locks | AccessShareLock | relation | master
(12 rows)
(7 rows)
SELECT * FROM locktest_segments;
coalesce | mode | locktype | node
-----------------+------------------+----------+------------
ao | AccessShareLock | relation | n segments
ao | RowExclusiveLock | relation | n segments
aovisimap index | RowExclusiveLock | relation | 1 segment
aovisimap table | RowExclusiveLock | relation | 1 segment
pg_class | AccessShareLock | relation | n segments
(5 rows)
COMMIT;
BEGIN;
UPDATE ao SET b = -1 WHERE a = 2;
SELECT * FROM locktest;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+------------
SELECT * FROM locktest_master;
coalesce | mode | locktype | node
----------------------------+---------------------+--------------------------+--------
ao | AccessExclusiveLock | append-only segment file | master
ao | AccessExclusiveLock | append-only segment file | 1 segment
ao | AccessShareLock | relation | master
ao | AccessShareLock | relation | n segments
ao | ExclusiveLock | relation | master
ao | RowExclusiveLock | relation | n segments
aovisimap index | RowExclusiveLock | relation | 1 segment
aovisimap table | RowExclusiveLock | relation | 1 segment
locktest | AccessShareLock | relation | master
pg_class | AccessShareLock | relation | master
pg_class_oid_index | AccessShareLock | relation | master
pg_class_relname_nsp_index | AccessShareLock | relation | master
pg_locks | AccessShareLock | relation | master
(13 rows)
(7 rows)
SELECT * FROM locktest_segments;
coalesce | mode | locktype | node
-----------------+---------------------+--------------------------+------------
ao | AccessExclusiveLock | append-only segment file | 1 segment
pg_class | AccessShareLock | relation | n segments
ao | AccessShareLock | relation | n segments
aovisimap index | RowExclusiveLock | relation | 1 segment
aovisimap table | RowExclusiveLock | relation | 1 segment
ao | RowExclusiveLock | relation | n segments
(6 rows)
COMMIT;
......@@ -395,7 +395,7 @@ select relname,
sotusize > 50000 as sz_over50kb,
sotusize < 5000000 as sz_under5mb
from pg_class pg, gp_toolkit.gp_size_of_table_uncompressed sotu
where relname = 'toolkit_ao2' and pg.relfilenode=sotu.sotuoid;
where relname = 'toolkit_ao2' and pg.oid=sotu.sotuoid;
relname | sz_over50kb | sz_under5mb
-------------+-------------+-------------
toolkit_ao2 | t | t
......@@ -406,7 +406,7 @@ select pg.relname,
si.soisize > 50000 as sz_over50kb,
si.soisize < 5000000 as sz_under5mb
from pg_class pg, gp_toolkit.gp_size_of_index si
where relname = 'toolkit_ao2' and pg.relfilenode=si.soitableoid;
where relname = 'toolkit_ao2' and pg.oid=si.soitableoid;
relname | sz_over50kb | sz_under5mb
-------------+-------------+-------------
toolkit_ao2 | t | t
......@@ -420,7 +420,7 @@ select relname,
sotdadditionalsize > 50000 as daddsz_over_50kb,
sotdadditionalsize < 5000000 as daddsz_under_5mb
from pg_class pg, gp_toolkit.gp_size_of_table_disk st
where relname = 'toolkit_ao2' and pg.relfilenode=st.sotdoid;
where relname = 'toolkit_ao2' and pg.oid=st.sotdoid;
relname | dsz_over_50kb | dsz_under_500kb | sotdtoastsize | daddsz_over_50kb | daddsz_under_5mb
-------------+---------------+-----------------+---------------+------------------+------------------
toolkit_ao2 | t | t | 0 | t | t
......@@ -431,7 +431,7 @@ select relname,
sotusize > 500000 as uncomp_over_500kb,
sotusize < 5000000 as uncomp_below_5mb
from pg_class pg, gp_toolkit.gp_size_of_table_uncompressed sotu
where relname = 'toolkit_ao2' and pg.relfilenode=sotu.sotuoid;
where relname = 'toolkit_ao2' and pg.oid=sotu.sotuoid;
relname | uncomp_over_500kb | uncomp_below_5mb
-------------+-------------------+------------------
toolkit_ao2 | t | t
......@@ -441,7 +441,7 @@ where relname = 'toolkit_ao2' and pg.relfilenode=sotu.sotuoid;
select pg.relname,
ti.tiidxoid::regclass
from pg_class pg, gp_toolkit.gp_table_indexes ti
where relname = 'toolkit_ao2' and pg.relfilenode=ti.tireloid;
where relname = 'toolkit_ao2' and pg.oid=ti.tireloid;
relname | tiidxoid
-------------+--------------------
toolkit_ao2 | tookit_ao2_index_j
......@@ -452,7 +452,7 @@ select pg.relname,
soati.soatisize > 50000 as sz_over_50kb,
soati.soatisize < 5000000 as sz_under_5mb
from pg_class pg, gp_toolkit.gp_size_of_all_table_indexes soati
where relname = 'toolkit_ao2' and pg.relfilenode=soati.soatioid;
where relname = 'toolkit_ao2' and pg.oid=soati.soatioid;
relname | sz_over_50kb | sz_under_5mb
-------------+--------------+--------------
toolkit_ao2 | t | t
......@@ -463,7 +463,7 @@ select pg.relname,
sotai.sotaidtablesize > 500000 as tablesz_over_500kb,
sotai.sotaididxsize < 5000000 as tablesz_below_5mb
from pg_class pg, gp_toolkit.gp_size_of_table_and_indexes_disk sotai
where relname = 'toolkit_ao2' and pg.relfilenode=sotai.sotaidoid;
where relname = 'toolkit_ao2' and pg.oid=sotai.sotaidoid;
relname | tablesz_over_500kb | tablesz_below_5mb
-------------+--------------------+-------------------
toolkit_ao2 | t | t
......@@ -478,7 +478,7 @@ select pg.relname,
sotail.sotailindexessize > 50000 as indexes_over_500k,
sotail.sotailindexessize < 5000000 as uncompressed_below_5mb
from pg_class pg, gp_toolkit.gp_size_of_table_and_indexes_licensing sotail
where relname = 'toolkit_ao2' and pg.relfilenode=sotail.sotailoid;
where relname = 'toolkit_ao2' and pg.oid=sotail.sotailoid;
relname | tables_over_500kb | tables_below_5mb | uncompressed_over_500kb | uncompressed_below_5mb | indexes_over_500k | uncompressed_below_5mb
-------------+-------------------+------------------+-------------------------+------------------------+-------------------+------------------------
toolkit_ao2 | t | t | t | t | t | t
......@@ -511,7 +511,7 @@ select pg.relname,
sopaidpartitiontablesize < 5000000 as tblsz_under5mb,
sopaidpartitionindexessize
from pg_class pg,gp_toolkit.gp_size_of_partition_and_indexes_disk gsopai
where pg.relfilenode=gsopai.sopaidpartitionoid and pg.relname like 'gptoolkit_user_table_ao%';
where pg.oid=gsopai.sopaidpartitionoid and pg.relname like 'gptoolkit_user_table_ao%';
relname | tblsz_over50k | tblsz_under5mb | sopaidpartitionindexessize
------------------------------------------+---------------+----------------+----------------------------
gptoolkit_user_table_ao_1_prt_p2 | t | t | 0
......
......@@ -34,17 +34,19 @@ CREATE TYPE aoseg_pt_rec as (segno integer, tupcount bigint,
CREATE OR REPLACE FUNCTION gp_aotable_eof_dist_random(
IN relation_name text) RETURNS setof aoseg_pt_rec AS $$
DECLARE
aorelfilenode oid;
ao_oid oid;
ao_relfilenode oid;
result record;
BEGIN
select into aorelfilenode relfilenode from pg_class where relname=quote_ident(relation_name);
select into ao_oid oid from pg_class where relname=quote_ident(relation_name);
select into ao_relfilenode relfilenode from pg_class where relname=quote_ident(relation_name);
for result in
EXECUTE 'select aoseg.segno, aoseg.tupcount, aoseg.eofuncompressed,
pt.mirror_append_only_new_eof from pg_aoseg.pg_aoseg_' ||
aorelfilenode || ' aoseg inner join
ao_oid || ' aoseg inner join
gp_persistent_relation_node pt on aoseg.segno =
pt.segment_file_num and pt.relfilenode_oid = ' ||
aorelfilenode || ' and pt.mirror_append_only_new_eof =
ao_relfilenode || ' and pt.mirror_append_only_new_eof =
aoseg.eofuncompressed and aoseg.eofuncompressed != 0;'
loop
return next result;
......
......@@ -1393,7 +1393,7 @@ update pg_class set relfilenode=(select relfilenode from pg_class where relname=
where relname='same_relfilenode2';
reset allow_system_table_mods;
reset gp_permit_relation_node_change;
select relname from pg_class where relfilenode='same_relfilenode'::regclass;
select relname from pg_class where relfilenode=(select relfilenode from pg_class where relname='same_relfilenode');
-- try to drop the database which should work (previously failed due to unique check on relfilenode)
-- a warning will be given since we haven't renamed the actual segment file on all postgres
......
......@@ -2704,7 +2704,7 @@ update pg_class set relfilenode=(select relfilenode from pg_class where relname=
where relname='same_relfilenode2';
reset allow_system_table_mods;
reset gp_permit_relation_node_change;
select relname from pg_class where relfilenode='same_relfilenode'::regclass;
select relname from pg_class where relfilenode=(select relfilenode from pg_class where relname='same_relfilenode');
relname
-------------------
same_relfilenode
......
......@@ -4,7 +4,7 @@ DROP TABLE IF EXISTS ao;
CREATE TABLE ao (a INT, b INT) WITH (appendonly=true);
INSERT INTO ao SELECT i as a, i as b FROM generate_series(1, 100) AS i;
create or replace view locktest as
create or replace view locktest_master as
select coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
......@@ -14,31 +14,64 @@ select coalesce(
else relname end, 'dropped table'),
mode,
locktype,
case when l.gp_segment_id = -1 then 'master'
when COUNT(*) = 1 then '1 segment'
else 'n segments' end AS node
'master'::text as node
from pg_locks l
left outer join pg_class c on (l.relation = c.oid),
left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)),
pg_database d
where relation is not null
and l.database = d.oid
and (relname <> 'gp_fault_strategy' or relname IS NULL)
and (relname <> 'gp_fault_strategy' and relname != 'locktest_master' or relname is NULL)
and d.datname = current_database()
group by l.gp_segment_id = -1, relation, relname, locktype, mode
and l.gp_segment_id = -1
group by l.gp_segment_id, relation, relname, locktype, mode
order by 1, 3, 2;
create or replace view locktest_segments_dist as
select relname,
mode,
locktype,
l.gp_segment_id as node,
relation
from pg_locks l
left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)),
pg_database d
where relation is not null
and l.database = d.oid
and (relname <> 'gp_fault_strategy' and relname != 'locktest_segments_dist' or relname is NULL)
and d.datname = current_database()
and l.gp_segment_id > -1
group by l.gp_segment_id, relation, relname, locktype, mode;
create or replace view locktest_segments as
SELECT coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
when relname like 'pg_aoseg%' then 'aoseg table'
when relname like 'pg_aovisimap%index' then 'aovisimap index'
when relname like 'pg_aovisimap%' then 'aovisimap table'
else relname end, 'dropped table'),
mode,
locktype,
case when count(*) = 1 then '1 segment'
else 'n segments' end as node
FROM gp_dist_random('locktest_segments_dist')
group by relname, relation, mode, locktype;
-- Actual test begins
BEGIN;
INSERT INTO ao VALUES (200, 200);
SELECT * FROM locktest;
SELECT * FROM locktest_master;
SELECT * FROM locktest_segments;
COMMIT;
BEGIN;
DELETE FROM ao WHERE a = 1;
SELECT * FROM locktest;
SELECT * FROM locktest_master;
SELECT * FROM locktest_segments;
COMMIT;
BEGIN;
UPDATE ao SET b = -1 WHERE a = 2;
SELECT * FROM locktest;
SELECT * FROM locktest_master;
SELECT * FROM locktest_segments;
COMMIT;
......@@ -223,14 +223,14 @@ select relname,
sotusize > 50000 as sz_over50kb,
sotusize < 5000000 as sz_under5mb
from pg_class pg, gp_toolkit.gp_size_of_table_uncompressed sotu
where relname = 'toolkit_ao2' and pg.relfilenode=sotu.sotuoid;
where relname = 'toolkit_ao2' and pg.oid=sotu.sotuoid;
-- gp_size_of_index
select pg.relname,
si.soisize > 50000 as sz_over50kb,
si.soisize < 5000000 as sz_under5mb
from pg_class pg, gp_toolkit.gp_size_of_index si
where relname = 'toolkit_ao2' and pg.relfilenode=si.soitableoid;
where relname = 'toolkit_ao2' and pg.oid=si.soitableoid;
-- gp_size_of_table_disk
select relname,
......@@ -240,34 +240,34 @@ select relname,
sotdadditionalsize > 50000 as daddsz_over_50kb,
sotdadditionalsize < 5000000 as daddsz_under_5mb
from pg_class pg, gp_toolkit.gp_size_of_table_disk st
where relname = 'toolkit_ao2' and pg.relfilenode=st.sotdoid;
where relname = 'toolkit_ao2' and pg.oid=st.sotdoid;
-- gp_size_of_table_uncompressed
select relname,
sotusize > 500000 as uncomp_over_500kb,
sotusize < 5000000 as uncomp_below_5mb
from pg_class pg, gp_toolkit.gp_size_of_table_uncompressed sotu
where relname = 'toolkit_ao2' and pg.relfilenode=sotu.sotuoid;
where relname = 'toolkit_ao2' and pg.oid=sotu.sotuoid;
-- gp_table_indexes
select pg.relname,
ti.tiidxoid::regclass
from pg_class pg, gp_toolkit.gp_table_indexes ti
where relname = 'toolkit_ao2' and pg.relfilenode=ti.tireloid;
where relname = 'toolkit_ao2' and pg.oid=ti.tireloid;
-- gp_size_of_all_table_indexes
select pg.relname,
soati.soatisize > 50000 as sz_over_50kb,
soati.soatisize < 5000000 as sz_under_5mb
from pg_class pg, gp_toolkit.gp_size_of_all_table_indexes soati
where relname = 'toolkit_ao2' and pg.relfilenode=soati.soatioid;
where relname = 'toolkit_ao2' and pg.oid=soati.soatioid;
-- gp_size_of_table_and_indexes_disk
select pg.relname,
sotai.sotaidtablesize > 500000 as tablesz_over_500kb,
sotai.sotaididxsize < 5000000 as tablesz_below_5mb
from pg_class pg, gp_toolkit.gp_size_of_table_and_indexes_disk sotai
where relname = 'toolkit_ao2' and pg.relfilenode=sotai.sotaidoid;
where relname = 'toolkit_ao2' and pg.oid=sotai.sotaidoid;
-- gp_size_of_table_and_indexes_licensing
select pg.relname,
......@@ -278,7 +278,7 @@ select pg.relname,
sotail.sotailindexessize > 50000 as indexes_over_500k,
sotail.sotailindexessize < 5000000 as uncompressed_below_5mb
from pg_class pg, gp_toolkit.gp_size_of_table_and_indexes_licensing sotail
where relname = 'toolkit_ao2' and pg.relfilenode=sotail.sotailoid;
where relname = 'toolkit_ao2' and pg.oid=sotail.sotailoid;
-- gp_size_of_schema_disk
select sosdnsp,
......@@ -299,7 +299,7 @@ select pg.relname,
sopaidpartitiontablesize < 5000000 as tblsz_under5mb,
sopaidpartitionindexessize
from pg_class pg,gp_toolkit.gp_size_of_partition_and_indexes_disk gsopai
where pg.relfilenode=gsopai.sopaidpartitionoid and pg.relname like 'gptoolkit_user_table_ao%';
where pg.oid=gsopai.sopaidpartitionoid and pg.relname like 'gptoolkit_user_table_ao%';
-- Test __gp_localid and __gp_masterid functions. The output of __gp_localid
-- depends on the number of segments, so just check that it returns something.
......
......@@ -6,27 +6,59 @@
-- of the locks in segments. If a relation is locked only on one segment,
-- we print that as a special case, but otherwise we just print "n segments",
-- meaning the relation is locked on more than one segment.
create or replace view locktest as
create or replace view locktest_master as
select coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
when relname like 'pg_aoseg%' then 'aoseg table'
when relname like 'pg_aovisimap%index' then 'aovisimap index'
when relname like 'pg_aovisimap%' then 'aovisimap table'
else relname end, 'dropped table'),
mode,
locktype,
case when l.gp_segment_id = -1 then 'master'
when COUNT(*) = 1 then '1 segment'
else 'n segments' end AS node
'master'::text as node
from pg_locks l
left outer join pg_class c on (l.relation = c.oid),
left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)),
pg_database d
where relation is not null
and l.database = d.oid
and (relname <> 'gp_fault_strategy' or relname IS NULL)
and (relname <> 'gp_fault_strategy' and relname != 'locktest_master' or relname is NULL)
and d.datname = current_database()
group by l.gp_segment_id = -1, relation, relname, locktype, mode
and l.gp_segment_id = -1
group by l.gp_segment_id, relation, relname, locktype, mode
order by 1, 3, 2;
create or replace view locktest_segments_dist as
select relname,
mode,
locktype,
l.gp_segment_id as node,
relation
from pg_locks l
left outer join pg_class c on ((l.locktype = 'append-only segment file' and l.relation = c.relfilenode) or (l.locktype != 'append-only segment file' and l.relation = c.oid)),
pg_database d
where relation is not null
and l.database = d.oid
and (relname <> 'gp_fault_strategy' and relname != 'locktest_segments_dist' or relname is NULL)
and d.datname = current_database()
and l.gp_segment_id > -1
group by l.gp_segment_id, relation, relname, locktype, mode;
create or replace view locktest_segments as
SELECT coalesce(
case when relname like 'pg_toast%index' then 'toast index'
when relname like 'pg_toast%' then 'toast table'
when relname like 'pg_aoseg%' then 'aoseg table'
when relname like 'pg_aovisimap%index' then 'aovisimap index'
when relname like 'pg_aovisimap%' then 'aovisimap table'
else relname end, 'dropped table'),
mode,
locktype,
case when count(*) = 1 then '1 segment'
else 'n segments' end as node
FROM gp_dist_random('locktest_segments_dist')
group by relname, relation, mode, locktype;
-- Partitioned table with toast table
begin;
......@@ -34,13 +66,15 @@ begin;
create table g (i int, t text) partition by range(i)
(start(1) end(10) every(1));
select * from locktest;
select * from locktest_master;
select * from locktest_segments;
commit;
-- drop
begin;
drop table g;
select * from locktest;
select * from locktest_master;
select * from locktest_segments;
commit;
-- AO table (ao segments, block directory won't exist after create)
......@@ -50,7 +84,8 @@ create table g (i int, t text, n numeric)
with (appendonly = true)
partition by list(i)
(values(1), values(2), values(3));
select * from locktest;
select * from locktest_master;
select * from locktest_segments;
commit;
begin;
......@@ -60,13 +95,15 @@ insert into g values(1), (2), (3);
insert into g values(1), (2), (3);
insert into g values(1), (2), (3);
insert into g values(1), (2), (3);
select * from locktest;
select * from locktest_master;
select * from locktest_segments;
commit;
-- drop
begin;
drop table g;
select * from locktest;
select * from locktest_master;
select * from locktest_segments;
commit;
-- Indexing
......@@ -75,7 +112,8 @@ create table g (i int, t text) partition by range(i)
begin;
create index g_idx on g(i);
select * from locktest;
select * from locktest_master;
select * from locktest_segments;
commit;
-- Force use of the index in the select and delete below. We're not interested
......@@ -88,24 +126,28 @@ set enable_seqscan=off;
begin;
select * from g where i = 1;
-- Known_opt_diff: MPP-20936
select * from locktest;
select * from locktest_master;
select * from locktest_segments;
commit;
begin;
-- insert locking
insert into g values(3, 'f');
select * from locktest;
select * from locktest_master;
select * from locktest_segments;
commit;
-- delete locking
begin;
delete from g where i = 4;
-- Known_opt_diff: MPP-20936
select * from locktest;
select * from locktest_master;
select * from locktest_segments;
commit;
-- drop index
begin;
drop table g;
select * from locktest;
select * from locktest_master;
select * from locktest_segments;
commit;
......@@ -36,17 +36,19 @@ CREATE TYPE aoseg_pt_rec as (segno integer, tupcount bigint,
CREATE OR REPLACE FUNCTION gp_aotable_eof_dist_random(
IN relation_name text) RETURNS setof aoseg_pt_rec AS $$
DECLARE
aorelfilenode oid;
ao_oid oid;
ao_relfilenode oid;
result record;
BEGIN
select into aorelfilenode relfilenode from pg_class where relname=quote_ident(relation_name);
select into ao_oid oid from pg_class where relname=quote_ident(relation_name);
select into ao_relfilenode relfilenode from pg_class where relname=quote_ident(relation_name);
for result in
EXECUTE 'select aoseg.segno, aoseg.tupcount, aoseg.eofuncompressed,
pt.mirror_append_only_new_eof from pg_aoseg.pg_aoseg_' ||
aorelfilenode || ' aoseg inner join
ao_oid || ' aoseg inner join
gp_persistent_relation_node pt on aoseg.segno =
pt.segment_file_num and pt.relfilenode_oid = ' ||
aorelfilenode || ' and pt.mirror_append_only_new_eof =
ao_relfilenode || ' and pt.mirror_append_only_new_eof =
aoseg.eofuncompressed and aoseg.eofuncompressed != 0;'
loop
return next result;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册