提交 e374ee57 编写于 作者: A Ashwin Agrawal

Tests for compaction on CO tables.

Tests ported from Pivotal's TINC test suite.
上级 ba7523fe
-- @Description Checks analyze and drop column interaction
CREATE TABLE ck_ct_co_analyze1(
text_col text,
bigint_col bigint,
char_vary_col character varying(30),
numeric_col numeric,
int_col int4,
float_col float4,
int_array_col int[],
drop_col numeric,
before_rename_col int4,
change_datatype_col numeric,
a_ts_without timestamp without time zone,
b_ts_with timestamp with time zone,
date_column date) with (appendonly=true, orientation=column) distributed randomly;
INSERT INTO ck_ct_co_analyze1 values ('0_zero', 0, '0_zero', 0, 0, 0, '{0}', 0, 0, 0, '2004-10-19 10:23:54', '2004-10-19 10:23:54+02', '1-1-2000');
INSERT INTO ck_ct_co_analyze1 values ('1_zero', 1, '1_zero', 1, 1, 1, '{1}', 1, 1, 1, '2005-10-19 10:23:54', '2005-10-19 10:23:54+02', '1-1-2001');
INSERT INTO ck_ct_co_analyze1 values ('2_zero', 2, '2_zero', 2, 2, 2, '{2}', 2, 2, 2, '2006-10-19 10:23:54', '2006-10-19 10:23:54+02', '1-1-2002');
select count(*) AS only_visi_tups_ins from ck_ct_co_analyze1;
only_visi_tups_ins
--------------------
3
(1 row)
set gp_select_invisible = true;
select count(*) AS invisi_and_visi_tups_ins from ck_ct_co_analyze1;
invisi_and_visi_tups_ins
--------------------------
3
(1 row)
set gp_select_invisible = false;
update ck_ct_co_analyze1 set bigint_col = bigint_col + 1 where text_col = '0_zero';
select count(*) AS only_visi_tups_upd from ck_ct_co_analyze1;
only_visi_tups_upd
--------------------
3
(1 row)
set gp_select_invisible = true;
select count(*) AS invisi_and_visi_tups_upd from ck_ct_co_analyze1;
invisi_and_visi_tups_upd
--------------------------
4
(1 row)
set gp_select_invisible = false;
delete from ck_ct_co_analyze1 where int_col = 2;
select count(*) AS only_visi_tups_del from ck_ct_co_analyze1;
only_visi_tups_del
--------------------
2
(1 row)
set gp_select_invisible = true;
select count(*) AS invisi_and_visi_tups_del from ck_ct_co_analyze1;
invisi_and_visi_tups_del
--------------------------
4
(1 row)
set gp_select_invisible = false;
--
ALTER TABLE ck_ct_co_analyze1 ADD COLUMN added_col character varying(30) default 'test_value';
ALTER TABLE ck_ct_co_analyze1 DROP COLUMN drop_col ;
ALTER TABLE ck_ct_co_analyze1 RENAME COLUMN before_rename_col TO after_rename_col;
ALTER TABLE ck_ct_co_analyze1 ALTER COLUMN change_datatype_col TYPE int4;
ALTER TABLE ck_ct_co_analyze1 set with ( reorganize='true') distributed by (int_col);
-- @Description Basic lazy vacuum
CREATE TABLE uaocs_basic (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
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 uaocs_basic SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1, 10) AS i;
INSERT INTO uaocs_basic SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1, 10) AS i;
DELETE FROM uaocs_basic WHERE a < 4;
SELECT COUNT(*) FROM uaocs_basic;
count
-------
14
(1 row)
VACUUM uaocs_basic;
-- check if we get the same result afterwards
SELECT COUNT(*) FROM uaocs_basic;
count
-------
14
(1 row)
-- check if we can still insert into the relation
INSERT INTO uaocs_basic VALUES (11, 11);
SELECT COUNT(*) FROM uaocs_basic;
count
-------
15
(1 row)
-- @Description Tests dropping a column after a compaction
CREATE TABLE uaocs_drop (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_drop_index ON uaocs_drop(b);
INSERT INTO uaocs_drop SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1, 10) AS i;
DELETE FROM uaocs_drop WHERE a < 4;
SELECT COUNT(*) FROM uaocs_drop;
count
-------
7
(1 row)
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_drop';
relname | reltuples
------------+-----------
uaocs_drop | 10
(1 row)
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_drop_index';
relname | reltuples
------------------+-----------
uaocs_drop_index | 10
(1 row)
VACUUM uaocs_drop;
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_drop';
relname | reltuples
------------+-----------
uaocs_drop | 7
(1 row)
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_drop_index';
relname | reltuples
------------------+-----------
uaocs_drop_index | 7
(1 row)
ALTER TABLE uaocs_drop DROP COLUMN c;
SELECT * FROM uaocs_drop;
a | b
----+---
4 | 1
6 | 1
8 | 1
10 | 1
5 | 1
7 | 1
9 | 1
(7 rows)
INSERT INTO uaocs_drop VALUES (42, 42);
SELECT * FROM uaocs_drop;
a | b
----+----
5 | 1
7 | 1
9 | 1
42 | 42
4 | 1
6 | 1
8 | 1
10 | 1
(8 rows)
-- @Description Tests dropping a column after a compaction with update
CREATE TABLE uaocs_drop_column_update(
text_col text,
bigint_col bigint,
char_vary_col character varying(30),
int_array_col int[],
drop_col numeric) with (appendonly=true, orientation=column);
NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'text_col' 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 uaocs_drop_column_update values ('1_zero', 1, '1_zero', '{1}', 1);
ALTER TABLE uaocs_drop_column_update DROP COLUMN drop_col;
Select char_vary_col, int_array_col from uaocs_drop_column_update;
char_vary_col | int_array_col
---------------+---------------
1_zero | {1}
(1 row)
INSERT INTO uaocs_drop_column_update values ('2_zero', 2, '2_zero', '{2}');
update uaocs_drop_column_update set bigint_col = bigint_col + 1 where text_col = '1_zero';
Select char_vary_col, int_array_col from uaocs_drop_column_update;
char_vary_col | int_array_col
---------------+---------------
1_zero | {1}
2_zero | {2}
(2 rows)
-- @Description Tests the behavior while compacting is disabled
CREATE TABLE uaocs_eof_truncate (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
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.
CREATE INDEX uaocs_eof_truncate_index ON uaocs_eof_truncate(b);
BEGIN;
INSERT INTO uaocs_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,1000) AS i;
COMMIT;
BEGIN;
INSERT INTO uaocs_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1000,2000) AS i;
ROLLBACK;
SET gp_appendonly_compaction=false;
SELECT COUNT(*) FROM uaocs_eof_truncate;
count
-------
1000
(1 row)
VACUUM uaocs_eof_truncate;
SELECT COUNT(*) FROM uaocs_eof_truncate;
count
-------
1000
(1 row)
-- Insert afterwards
INSERT INTO uaocs_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,10) AS i;
SELECT COUNT(*) FROM uaocs_eof_truncate;
count
-------
1010
(1 row)
-- @Description Test the basic bahavior of vacuum full
CREATE TABLE uaocs_full (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
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.
CREATE INDEX uaocs_full_index ON uaocs_full(b);
INSERT INTO uaocs_full SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,10) AS i;
INSERT INTO uaocs_full SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,10) AS i;
DELETE FROM uaocs_full WHERE a < 4;
SELECT COUNT(*) FROM uaocs_full;
count
-------
14
(1 row)
VACUUM FULL uaocs_full;
-- check if we get the same result afterwards
SELECT COUNT(*) FROM uaocs_full;
count
-------
14
(1 row)
-- check if we can still insert into the relation
INSERT INTO uaocs_full VALUES (11, 11);
SELECT COUNT(*) FROM uaocs_full;
count
-------
15
(1 row)
-- @Description Tests the behavior while compacting is disabled
CREATE TABLE uaocs_full_eof_truncate (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
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.
CREATE INDEX uaocs_full_eof_truncate_index ON uaocs_full_eof_truncate(b);
BEGIN;
INSERT INTO uaocs_full_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,1000) AS i;
COMMIT;
BEGIN;
INSERT INTO uaocs_full_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1000,2000) AS i;
ROLLBACK;
SET gp_appendonly_compaction=false;
SELECT COUNT(*) FROM uaocs_full_eof_truncate;
count
-------
1000
(1 row)
VACUUM FULL uaocs_full_eof_truncate;
SELECT COUNT(*) FROM uaocs_full_eof_truncate;
count
-------
1000
(1 row)
-- Insert afterwards
INSERT INTO uaocs_full_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,10) AS i;
SELECT COUNT(*) FROM uaocs_full_eof_truncate;
count
-------
1010
(1 row)
-- @Description Tests the behavior of full vacuum w.r.t. the pg_class statistics
-- ensure that the scan go through the index
CREATE TABLE uaocs_full_stats (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_full_stats_index ON uaocs_full_stats(b);
INSERT INTO uaocs_full_stats SELECT i as a, i as b, 'hello world' as c FROM generate_series(1, 50) AS i;
INSERT INTO uaocs_full_stats SELECT i as a, i as b, 'hello world' as c FROM generate_series(51, 100) AS i;
ANALYZE uaocs_full_stats;
SET enable_seqscan=false;
SELECT COUNT(*) FROM uaocs_full_stats;
count
-------
100
(1 row)
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_full_stats';
relname | reltuples
------------------+-----------
uaocs_full_stats | 100
(1 row)
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_full_stats_index';
relname | reltuples
------------------------+-----------
uaocs_full_stats_index | 100
(1 row)
DELETE FROM uaocs_full_stats WHERE a < 16;
SELECT COUNT(*) FROM uaocs_full_stats;
count
-------
85
(1 row)
VACUUM FULL uaocs_full_stats;
SELECT COUNT(*) FROM uaocs_full_stats;
count
-------
85
(1 row)
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_full_stats';
relname | reltuples
------------------+-----------
uaocs_full_stats | 85
(1 row)
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_full_stats_index';
relname | reltuples
------------------------+-----------
uaocs_full_stats_index | 85
(1 row)
-- @Description Tests that that full vacuum is ignoring the threshold guc value.
CREATE TABLE uaocs_full_threshold (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_full_threshold_index ON uaocs_full_threshold(b);
INSERT INTO uaocs_full_threshold SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1, 100) AS i;
\set QUIET off
VACUUM FULL uaocs_full_threshold;
VACUUM
DELETE FROM uaocs_full_threshold WHERE a < 4;
DELETE 3
SET gp_appendonly_compaction_threshold=100;
SET
VACUUM FULL uaocs_full_threshold;
VACUUM
-- @Description Tests basic index usage behavior after vacuuming
CREATE TABLE uaocs_index (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
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.
CREATE INDEX uaocs_index_index ON uaocs_index(b);
INSERT INTO uaocs_index SELECT i as a, i as b, 'hello world' as c FROM generate_series(1,10) AS i;
INSERT INTO uaocs_index SELECT i as a, i as b, 'hello world' as c FROM generate_series(1,10) AS i;
VACUUM uaocs_index;
SELECT * FROM uaocs_index WHERE b = 5;
a | b | c
---+---+----------------------------------------------------------------------------------------------------------------------------------
5 | 5 | hello world
5 | 5 | hello world
(2 rows)
-- @Description Tests basic index stats after vacuuming
CREATE TABLE uaocs_index_stats(
col_int int,
col_text text,
col_numeric numeric,
col_unq int
) with(appendonly=true, orientation=column) DISTRIBUTED RANDOMLY;
Create index uaocs_index_stats_int_idx1 on uaocs_index_stats(col_int);
select * from uaocs_index_stats order by col_int;
col_int | col_text | col_numeric | col_unq
---------+----------+-------------+---------
(0 rows)
insert into uaocs_index_stats values(1,'aa',1001,101),(2,'bb',1002,102);
select * from uaocs_index_stats;
col_int | col_text | col_numeric | col_unq
---------+----------+-------------+---------
2 | bb | 1002 | 102
1 | aa | 1001 | 101
(2 rows)
update uaocs_index_stats set col_text=' new value' where col_int = 1;
select * from uaocs_index_stats;
col_int | col_text | col_numeric | col_unq
---------+------------+-------------+---------
2 | bb | 1002 | 102
1 | new value | 1001 | 101
(2 rows)
vacuum uaocs_index_stats;
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_index_stats';
relname | reltuples
-------------------+-----------
uaocs_index_stats | 2
(1 row)
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_index_stats_int_idx1';
relname | reltuples
----------------------------+-----------
uaocs_index_stats_int_idx1 | 2
(1 row)
-- @Description Tests the behavior when the index of an ao table
-- has not been cleaned in combination with a partial index.
CREATE TABLE uaocs_outdated_partialindex (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_outdated_partialindex_index ON uaocs_outdated_partialindex(b) WHERE b < 20;
INSERT INTO uaocs_outdated_partialindex SELECT i as a, i as b, 'hello world' as c FROM generate_series(1, 50) AS i;
INSERT INTO uaocs_outdated_partialindex SELECT i as a, i as b, 'hello world' as c FROM generate_series(51, 100) AS i;
ANALYZE uaocs_outdated_partialindex;
SET enable_seqscan=false;
DELETE FROM uaocs_outdated_partialindex WHERE a < 16;
VACUUM uaocs_outdated_partialindex;
SELECT * FROM uaocs_outdated_partialindex WHERE b = 20;
a | b | c
----+----+----------------------------------------------------------------------------------------------------------------------------------
20 | 20 | hello world
(1 row)
SELECT * FROM uaocs_outdated_partialindex WHERE b = 10;
a | b | c
---+---+---
(0 rows)
INSERT INTO uaocs_outdated_partialindex SELECT i as a, i as b, 'Good morning' as c FROM generate_series(101, 110) AS i;
SELECT * FROM uaocs_outdated_partialindex WHERE b = 10;
a | b | c
---+---+---
(0 rows)
SELECT * FROM uaocs_outdated_partialindex WHERE b = 102;
a | b | c
-----+-----+----------------------------------------------------------------------------------------------------------------------------------
102 | 102 | Good morning
(1 row)
-- @Description Tests the behavior when the index of an ao table
-- has not been cleaned.
CREATE TABLE uaocs_outdatedindex (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_outdatedindex_index ON uaocs_outdatedindex(b);
INSERT INTO uaocs_outdatedindex SELECT i as a, i as b, 'hello world' as c FROM generate_series(1, 50) AS i;
INSERT INTO uaocs_outdatedindex SELECT i as a, i as b, 'hello world' as c FROM generate_series(51, 100) AS i;
ANALYZE uaocs_outdatedindex;
SET enable_seqscan=false;
DELETE FROM uaocs_outdatedindex WHERE a < 16;
VACUUM uaocs_outdatedindex;
SELECT * FROM uaocs_outdatedindex WHERE b = 20;
a | b | c
----+----+----------------------------------------------------------------------------------------------------------------------------------
20 | 20 | hello world
(1 row)
SELECT * FROM uaocs_outdatedindex WHERE b = 10;
a | b | c
---+---+---
(0 rows)
INSERT INTO uaocs_outdatedindex SELECT i as a, i as b, 'Good morning' as c FROM generate_series(1, 10) AS i;
SELECT * FROM uaocs_outdatedindex WHERE b = 10;
a | b | c
----+----+----------------------------------------------------------------------------------------------------------------------------------
10 | 10 | Good morning
(1 row)
-- @Description Tests the behavior when the index of an ao table
-- has not been cleaned in combination with aborted inserts.
CREATE TABLE uaocs_outdatedindex_abort (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_outdatedindex_abort_index ON uaocs_outdatedindex_abort(b);
INSERT INTO uaocs_outdatedindex_abort SELECT i as a, i as b, 'hello world' as c FROM generate_series(1, 50) AS i;
INSERT INTO uaocs_outdatedindex_abort SELECT i as a, i as b, 'hello world' as c FROM generate_series(51, 100) AS i;
ANALYZE uaocs_outdatedindex_abort;
SET enable_seqscan=false;
DELETE FROM uaocs_outdatedindex_abort WHERE a < 16;
VACUUM uaocs_outdatedindex_abort;
SELECT * FROM uaocs_outdatedindex_abort WHERE b = 20;
a | b | c
----+----+----------------------------------------------------------------------------------------------------------------------------------
20 | 20 | hello world
(1 row)
SELECT * FROM uaocs_outdatedindex_abort WHERE b = 10;
a | b | c
---+---+---
(0 rows)
INSERT INTO uaocs_outdatedindex_abort SELECT i as a, i as b, 'Good morning' as c FROM generate_series(1, 4) AS i;
BEGIN;
INSERT INTO uaocs_outdatedindex_abort SELECT i as a, i as b, 'Good morning' as c FROM generate_series(5, 8) AS i;
INSERT INTO uaocs_outdatedindex_abort SELECT i as a, i as b, 'Good morning' as c FROM generate_series(9, 12) AS i;
ROLLBACK;
SELECT * FROM uaocs_outdatedindex_abort WHERE b < 16;
a | b | c
---+---+----------------------------------------------------------------------------------------------------------------------------------
2 | 2 | Good morning
4 | 4 | Good morning
1 | 1 | Good morning
3 | 3 | Good morning
(4 rows)
-- @Description Tests that the pg_class statistics are updated on
-- lazy vacuum.
CREATE TABLE uaocs_stats (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_stats_index ON uaocs_stats(b);
INSERT INTO uaocs_stats SELECT i as a, i as b, 'hello world' as c FROM generate_series(1, 50) AS i;
INSERT INTO uaocs_stats SELECT i as a, i as b, 'hello world' as c FROM generate_series(51, 100) AS i;
ANALYZE uaocs_stats;
-- ensure that the scan go through the index
SET enable_seqscan=false;
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_stats';
relname | reltuples
-------------+-----------
uaocs_stats | 100
(1 row)
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_stats_index';
relname | reltuples
-------------------+-----------
uaocs_stats_index | 100
(1 row)
DELETE FROM uaocs_stats WHERE a < 16;
VACUUM uaocs_stats;
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_stats';
relname | reltuples
-------------+-----------
uaocs_stats | 85
(1 row)
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_stats_index';
relname | reltuples
-------------------+-----------
uaocs_stats_index | 85
(1 row)
-- @Description Tests the basic behavior of (lazy) vacuum w.r.t. to the threshold guc.
-- The output depends on the number of segments as the skip decision and the
-- notify is done on the segments.
CREATE TABLE uaocs_threshold (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
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.
CREATE INDEX uaocs_threshold_index ON uaocs_threshold(b);
INSERT INTO uaocs_threshold SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1, 100) AS i;
\set QUIET off
VACUUM uaocs_threshold;
VACUUM
DELETE FROM uaocs_threshold WHERE a < 4;
DELETE 3
SELECT COUNT(*) FROM uaocs_threshold;
count
-------
97
(1 row)
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
segno | tupcount | state
-------+----------+-------
1 | 100 | 1
(1 row)
-- 97 visible tuples, no vacuum
VACUUM uaocs_threshold;
VACUUM
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
segno | tupcount | state
-------+----------+-------
1 | 100 | 1
(1 row)
DELETE FROM uaocs_threshold WHERE a < 12;
DELETE 8
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
segno | tupcount | state
-------+----------+-------
1 | 100 | 1
(1 row)
-- 89 visible tuples, do vacuum
VACUUM uaocs_threshold;
VACUUM
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
segno | tupcount | state
-------+----------+-------
1 | 50 | 1
2 | 44 | 1
(2 rows)
-- no invisible tuples, no vacuum
VACUUM uaocs_threshold;
VACUUM
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
segno | tupcount | state
-------+----------+-------
1 | 50 | 1
2 | 44 | 1
(2 rows)
DELETE FROM uaocs_threshold WHERE a < 15;
DELETE 3
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
segno | tupcount | state
-------+----------+-------
1 | 50 | 1
2 | 44 | 1
(2 rows)
-- 3 invisible tuples, no vacuum
VACUUM uaocs_threshold;
VACUUM
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
segno | tupcount | state
-------+----------+-------
2 | 44 | 1
1 | 0 | 1
3 | 43 | 1
(3 rows)
SET gp_appendonly_compaction_threshold=2;
SET
-- 3 invisible tuples, no vacuum
VACUUM uaocs_threshold;
VACUUM
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
segno | tupcount | state
-------+----------+-------
2 | 44 | 1
1 | 0 | 1
3 | 43 | 1
(3 rows)
......@@ -91,7 +91,7 @@ ignore: tpch500GB_orca
# Tests for "compaction", i.e. VACUUM, of updatable append-only tables
test: uao_compaction/full uao_compaction/alter_table_analyze2 uao_compaction/outdated_partialindex uao_compaction/drop_column_update uao_compaction/eof_truncate uao_compaction/basic uao_compaction/outdatedindex uao_compaction/update_toast uao_compaction/outdatedindex_abort uao_compaction/delete_toast uao_compaction/alter_table_analyze uao_compaction/full_eof_truncate uao_compaction/full_threshold
test: uao_compaction/full_stats
# TODO find why these tests fail in parellel, for now keeping them sequential
test: uao_compaction/stats
test: uao_compaction/threshold
test: uao_compaction/index_stats
......@@ -99,4 +99,14 @@ test: uao_compaction/index
test: uao_compaction/drop_column
test: uao_compaction/index2
# Tests for "compaction", i.e. VACUUM, of updatable append-only column oriented tables
test: uaocs_compaction/alter_table_analyze uaocs_compaction/basic uaocs_compaction/drop_column_update uaocs_compaction/eof_truncate uaocs_compaction/full uaocs_compaction/full_eof_truncate uaocs_compaction/full_threshold uaocs_compaction/outdated_partialindex uaocs_compaction/outdatedindex uaocs_compaction/outdatedindex_abort
# TODO find why these tests fail in parellel, for now keeping them sequential
test: uaocs_compaction/full_stats
test: uaocs_compaction/stats
test: uaocs_compaction/threshold
test: uaocs_compaction/index_stats
test: uaocs_compaction/index
test: uaocs_compaction/drop_column
# end of tests
-- @Description Checks analyze and drop column interaction
CREATE TABLE ck_ct_co_analyze1(
text_col text,
bigint_col bigint,
char_vary_col character varying(30),
numeric_col numeric,
int_col int4,
float_col float4,
int_array_col int[],
drop_col numeric,
before_rename_col int4,
change_datatype_col numeric,
a_ts_without timestamp without time zone,
b_ts_with timestamp with time zone,
date_column date) with (appendonly=true, orientation=column) distributed randomly;
INSERT INTO ck_ct_co_analyze1 values ('0_zero', 0, '0_zero', 0, 0, 0, '{0}', 0, 0, 0, '2004-10-19 10:23:54', '2004-10-19 10:23:54+02', '1-1-2000');
INSERT INTO ck_ct_co_analyze1 values ('1_zero', 1, '1_zero', 1, 1, 1, '{1}', 1, 1, 1, '2005-10-19 10:23:54', '2005-10-19 10:23:54+02', '1-1-2001');
INSERT INTO ck_ct_co_analyze1 values ('2_zero', 2, '2_zero', 2, 2, 2, '{2}', 2, 2, 2, '2006-10-19 10:23:54', '2006-10-19 10:23:54+02', '1-1-2002');
select count(*) AS only_visi_tups_ins from ck_ct_co_analyze1;
set gp_select_invisible = true;
select count(*) AS invisi_and_visi_tups_ins from ck_ct_co_analyze1;
set gp_select_invisible = false;
update ck_ct_co_analyze1 set bigint_col = bigint_col + 1 where text_col = '0_zero';
select count(*) AS only_visi_tups_upd from ck_ct_co_analyze1;
set gp_select_invisible = true;
select count(*) AS invisi_and_visi_tups_upd from ck_ct_co_analyze1;
set gp_select_invisible = false;
delete from ck_ct_co_analyze1 where int_col = 2;
select count(*) AS only_visi_tups_del from ck_ct_co_analyze1;
set gp_select_invisible = true;
select count(*) AS invisi_and_visi_tups_del from ck_ct_co_analyze1;
set gp_select_invisible = false;
--
ALTER TABLE ck_ct_co_analyze1 ADD COLUMN added_col character varying(30) default 'test_value';
ALTER TABLE ck_ct_co_analyze1 DROP COLUMN drop_col ;
ALTER TABLE ck_ct_co_analyze1 RENAME COLUMN before_rename_col TO after_rename_col;
ALTER TABLE ck_ct_co_analyze1 ALTER COLUMN change_datatype_col TYPE int4;
ALTER TABLE ck_ct_co_analyze1 set with ( reorganize='true') distributed by (int_col);
-- @Description Basic lazy vacuum
CREATE TABLE uaocs_basic (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
INSERT INTO uaocs_basic SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1, 10) AS i;
INSERT INTO uaocs_basic SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1, 10) AS i;
DELETE FROM uaocs_basic WHERE a < 4;
SELECT COUNT(*) FROM uaocs_basic;
VACUUM uaocs_basic;
-- check if we get the same result afterwards
SELECT COUNT(*) FROM uaocs_basic;
-- check if we can still insert into the relation
INSERT INTO uaocs_basic VALUES (11, 11);
SELECT COUNT(*) FROM uaocs_basic;
-- @Description Tests dropping a column after a compaction
CREATE TABLE uaocs_drop (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_drop_index ON uaocs_drop(b);
INSERT INTO uaocs_drop SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1, 10) AS i;
DELETE FROM uaocs_drop WHERE a < 4;
SELECT COUNT(*) FROM uaocs_drop;
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_drop';
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_drop_index';
VACUUM uaocs_drop;
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_drop';
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_drop_index';
ALTER TABLE uaocs_drop DROP COLUMN c;
SELECT * FROM uaocs_drop;
INSERT INTO uaocs_drop VALUES (42, 42);
SELECT * FROM uaocs_drop;
-- @Description Tests dropping a column after a compaction with update
CREATE TABLE uaocs_drop_column_update(
text_col text,
bigint_col bigint,
char_vary_col character varying(30),
int_array_col int[],
drop_col numeric) with (appendonly=true, orientation=column);
INSERT INTO uaocs_drop_column_update values ('1_zero', 1, '1_zero', '{1}', 1);
ALTER TABLE uaocs_drop_column_update DROP COLUMN drop_col;
Select char_vary_col, int_array_col from uaocs_drop_column_update;
INSERT INTO uaocs_drop_column_update values ('2_zero', 2, '2_zero', '{2}');
update uaocs_drop_column_update set bigint_col = bigint_col + 1 where text_col = '1_zero';
Select char_vary_col, int_array_col from uaocs_drop_column_update;
-- @Description Tests the behavior while compacting is disabled
CREATE TABLE uaocs_eof_truncate (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
CREATE INDEX uaocs_eof_truncate_index ON uaocs_eof_truncate(b);
BEGIN;
INSERT INTO uaocs_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,1000) AS i;
COMMIT;
BEGIN;
INSERT INTO uaocs_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1000,2000) AS i;
ROLLBACK;
SET gp_appendonly_compaction=false;
SELECT COUNT(*) FROM uaocs_eof_truncate;
VACUUM uaocs_eof_truncate;
SELECT COUNT(*) FROM uaocs_eof_truncate;
-- Insert afterwards
INSERT INTO uaocs_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,10) AS i;
SELECT COUNT(*) FROM uaocs_eof_truncate;
-- @Description Test the basic bahavior of vacuum full
CREATE TABLE uaocs_full (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
CREATE INDEX uaocs_full_index ON uaocs_full(b);
INSERT INTO uaocs_full SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,10) AS i;
INSERT INTO uaocs_full SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,10) AS i;
DELETE FROM uaocs_full WHERE a < 4;
SELECT COUNT(*) FROM uaocs_full;
VACUUM FULL uaocs_full;
-- check if we get the same result afterwards
SELECT COUNT(*) FROM uaocs_full;
-- check if we can still insert into the relation
INSERT INTO uaocs_full VALUES (11, 11);
SELECT COUNT(*) FROM uaocs_full;
-- @Description Tests the behavior while compacting is disabled
CREATE TABLE uaocs_full_eof_truncate (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
CREATE INDEX uaocs_full_eof_truncate_index ON uaocs_full_eof_truncate(b);
BEGIN;
INSERT INTO uaocs_full_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,1000) AS i;
COMMIT;
BEGIN;
INSERT INTO uaocs_full_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1000,2000) AS i;
ROLLBACK;
SET gp_appendonly_compaction=false;
SELECT COUNT(*) FROM uaocs_full_eof_truncate;
VACUUM FULL uaocs_full_eof_truncate;
SELECT COUNT(*) FROM uaocs_full_eof_truncate;
-- Insert afterwards
INSERT INTO uaocs_full_eof_truncate SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1,10) AS i;
SELECT COUNT(*) FROM uaocs_full_eof_truncate;
-- @Description Tests the behavior of full vacuum w.r.t. the pg_class statistics
-- ensure that the scan go through the index
CREATE TABLE uaocs_full_stats (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_full_stats_index ON uaocs_full_stats(b);
INSERT INTO uaocs_full_stats SELECT i as a, i as b, 'hello world' as c FROM generate_series(1, 50) AS i;
INSERT INTO uaocs_full_stats SELECT i as a, i as b, 'hello world' as c FROM generate_series(51, 100) AS i;
ANALYZE uaocs_full_stats;
SET enable_seqscan=false;
SELECT COUNT(*) FROM uaocs_full_stats;
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_full_stats';
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_full_stats_index';
DELETE FROM uaocs_full_stats WHERE a < 16;
SELECT COUNT(*) FROM uaocs_full_stats;
VACUUM FULL uaocs_full_stats;
SELECT COUNT(*) FROM uaocs_full_stats;
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_full_stats';
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_full_stats_index';
-- @Description Tests that that full vacuum is ignoring the threshold guc value.
CREATE TABLE uaocs_full_threshold (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_full_threshold_index ON uaocs_full_threshold(b);
INSERT INTO uaocs_full_threshold SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1, 100) AS i;
\set QUIET off
VACUUM FULL uaocs_full_threshold;
DELETE FROM uaocs_full_threshold WHERE a < 4;
SET gp_appendonly_compaction_threshold=100;
VACUUM FULL uaocs_full_threshold;
-- @Description Tests basic index usage behavior after vacuuming
CREATE TABLE uaocs_index (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
CREATE INDEX uaocs_index_index ON uaocs_index(b);
INSERT INTO uaocs_index SELECT i as a, i as b, 'hello world' as c FROM generate_series(1,10) AS i;
INSERT INTO uaocs_index SELECT i as a, i as b, 'hello world' as c FROM generate_series(1,10) AS i;
VACUUM uaocs_index;
SELECT * FROM uaocs_index WHERE b = 5;
-- @Description Tests basic index stats after vacuuming
CREATE TABLE uaocs_index_stats(
col_int int,
col_text text,
col_numeric numeric,
col_unq int
) with(appendonly=true, orientation=column) DISTRIBUTED RANDOMLY;
Create index uaocs_index_stats_int_idx1 on uaocs_index_stats(col_int);
select * from uaocs_index_stats order by col_int;
insert into uaocs_index_stats values(1,'aa',1001,101),(2,'bb',1002,102);
select * from uaocs_index_stats;
update uaocs_index_stats set col_text=' new value' where col_int = 1;
select * from uaocs_index_stats;
vacuum uaocs_index_stats;
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_index_stats';
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_index_stats_int_idx1';
-- @Description Tests the behavior when the index of an ao table
-- has not been cleaned in combination with a partial index.
CREATE TABLE uaocs_outdated_partialindex (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_outdated_partialindex_index ON uaocs_outdated_partialindex(b) WHERE b < 20;
INSERT INTO uaocs_outdated_partialindex SELECT i as a, i as b, 'hello world' as c FROM generate_series(1, 50) AS i;
INSERT INTO uaocs_outdated_partialindex SELECT i as a, i as b, 'hello world' as c FROM generate_series(51, 100) AS i;
ANALYZE uaocs_outdated_partialindex;
SET enable_seqscan=false;
DELETE FROM uaocs_outdated_partialindex WHERE a < 16;
VACUUM uaocs_outdated_partialindex;
SELECT * FROM uaocs_outdated_partialindex WHERE b = 20;
SELECT * FROM uaocs_outdated_partialindex WHERE b = 10;
INSERT INTO uaocs_outdated_partialindex SELECT i as a, i as b, 'Good morning' as c FROM generate_series(101, 110) AS i;
SELECT * FROM uaocs_outdated_partialindex WHERE b = 10;
SELECT * FROM uaocs_outdated_partialindex WHERE b = 102;
-- @Description Tests the behavior when the index of an ao table
-- has not been cleaned.
CREATE TABLE uaocs_outdatedindex (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_outdatedindex_index ON uaocs_outdatedindex(b);
INSERT INTO uaocs_outdatedindex SELECT i as a, i as b, 'hello world' as c FROM generate_series(1, 50) AS i;
INSERT INTO uaocs_outdatedindex SELECT i as a, i as b, 'hello world' as c FROM generate_series(51, 100) AS i;
ANALYZE uaocs_outdatedindex;
SET enable_seqscan=false;
DELETE FROM uaocs_outdatedindex WHERE a < 16;
VACUUM uaocs_outdatedindex;
SELECT * FROM uaocs_outdatedindex WHERE b = 20;
SELECT * FROM uaocs_outdatedindex WHERE b = 10;
INSERT INTO uaocs_outdatedindex SELECT i as a, i as b, 'Good morning' as c FROM generate_series(1, 10) AS i;
SELECT * FROM uaocs_outdatedindex WHERE b = 10;
-- @Description Tests the behavior when the index of an ao table
-- has not been cleaned in combination with aborted inserts.
CREATE TABLE uaocs_outdatedindex_abort (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_outdatedindex_abort_index ON uaocs_outdatedindex_abort(b);
INSERT INTO uaocs_outdatedindex_abort SELECT i as a, i as b, 'hello world' as c FROM generate_series(1, 50) AS i;
INSERT INTO uaocs_outdatedindex_abort SELECT i as a, i as b, 'hello world' as c FROM generate_series(51, 100) AS i;
ANALYZE uaocs_outdatedindex_abort;
SET enable_seqscan=false;
DELETE FROM uaocs_outdatedindex_abort WHERE a < 16;
VACUUM uaocs_outdatedindex_abort;
SELECT * FROM uaocs_outdatedindex_abort WHERE b = 20;
SELECT * FROM uaocs_outdatedindex_abort WHERE b = 10;
INSERT INTO uaocs_outdatedindex_abort SELECT i as a, i as b, 'Good morning' as c FROM generate_series(1, 4) AS i;
BEGIN;
INSERT INTO uaocs_outdatedindex_abort SELECT i as a, i as b, 'Good morning' as c FROM generate_series(5, 8) AS i;
INSERT INTO uaocs_outdatedindex_abort SELECT i as a, i as b, 'Good morning' as c FROM generate_series(9, 12) AS i;
ROLLBACK;
SELECT * FROM uaocs_outdatedindex_abort WHERE b < 16;
-- @Description Tests that the pg_class statistics are updated on
-- lazy vacuum.
CREATE TABLE uaocs_stats (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column) DISTRIBUTED BY (a);
CREATE INDEX uaocs_stats_index ON uaocs_stats(b);
INSERT INTO uaocs_stats SELECT i as a, i as b, 'hello world' as c FROM generate_series(1, 50) AS i;
INSERT INTO uaocs_stats SELECT i as a, i as b, 'hello world' as c FROM generate_series(51, 100) AS i;
ANALYZE uaocs_stats;
-- ensure that the scan go through the index
SET enable_seqscan=false;
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_stats';
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_stats_index';
DELETE FROM uaocs_stats WHERE a < 16;
VACUUM uaocs_stats;
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_stats';
SELECT relname, reltuples FROM pg_class WHERE relname = 'uaocs_stats_index';
-- @Description Tests the basic behavior of (lazy) vacuum w.r.t. to the threshold guc.
-- The output depends on the number of segments as the skip decision and the
-- notify is done on the segments.
CREATE TABLE uaocs_threshold (a INT, b INT, c CHAR(128)) WITH (appendonly=true, orientation=column);
CREATE INDEX uaocs_threshold_index ON uaocs_threshold(b);
INSERT INTO uaocs_threshold SELECT i as a, 1 as b, 'hello world' as c FROM generate_series(1, 100) AS i;
\set QUIET off
VACUUM uaocs_threshold;
DELETE FROM uaocs_threshold WHERE a < 4;
SELECT COUNT(*) FROM uaocs_threshold;
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
-- 97 visible tuples, no vacuum
VACUUM uaocs_threshold;
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
DELETE FROM uaocs_threshold WHERE a < 12;
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
-- 89 visible tuples, do vacuum
VACUUM uaocs_threshold;
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
-- no invisible tuples, no vacuum
VACUUM uaocs_threshold;
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
DELETE FROM uaocs_threshold WHERE a < 15;
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
-- 3 invisible tuples, no vacuum
VACUUM uaocs_threshold;
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
SET gp_appendonly_compaction_threshold=2;
-- 3 invisible tuples, no vacuum
VACUUM uaocs_threshold;
SELECT DISTINCT segno, tupcount, state FROM gp_toolkit.__gp_aocsseg_name('uaocs_threshold');
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册