mirror of https://github.com/citusdata/citus.git
214 lines
6.1 KiB
Plaintext
214 lines
6.1 KiB
Plaintext
SELECT count(*) AS columnar_table_count FROM cstore.cstore_data_files \gset
|
|
CREATE TABLE t(a int, b int) USING cstore_tableam;
|
|
SELECT count(*) FROM cstore.cstore_stripes a, pg_class b WHERE a.relfilenode=b.relfilenode AND b.relname='t';
|
|
count
|
|
-------
|
|
0
|
|
(1 row)
|
|
|
|
INSERT INTO t SELECT i, i * i FROM generate_series(1, 10) i;
|
|
INSERT INTO t SELECT i, i * i FROM generate_series(11, 20) i;
|
|
INSERT INTO t SELECT i, i * i FROM generate_series(21, 30) i;
|
|
SELECT sum(a), sum(b) FROM t;
|
|
sum | sum
|
|
-----+------
|
|
465 | 9455
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM cstore.cstore_stripes a, pg_class b WHERE a.relfilenode=b.relfilenode AND b.relname='t';
|
|
count
|
|
-------
|
|
3
|
|
(1 row)
|
|
|
|
-- vacuum full should merge stripes together
|
|
VACUUM FULL t;
|
|
SELECT sum(a), sum(b) FROM t;
|
|
sum | sum
|
|
-----+------
|
|
465 | 9455
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM cstore.cstore_stripes a, pg_class b WHERE a.relfilenode=b.relfilenode AND b.relname='t';
|
|
count
|
|
-------
|
|
1
|
|
(1 row)
|
|
|
|
-- test the case when all data cannot fit into a single stripe
|
|
SET cstore.stripe_row_count TO 1000;
|
|
INSERT INTO t SELECT i, 2 * i FROM generate_series(1,2500) i;
|
|
SELECT sum(a), sum(b) FROM t;
|
|
sum | sum
|
|
---------+---------
|
|
3126715 | 6261955
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM cstore.cstore_stripes a, pg_class b WHERE a.relfilenode=b.relfilenode AND b.relname='t';
|
|
count
|
|
-------
|
|
4
|
|
(1 row)
|
|
|
|
VACUUM FULL t;
|
|
SELECT sum(a), sum(b) FROM t;
|
|
sum | sum
|
|
---------+---------
|
|
3126715 | 6261955
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM cstore.cstore_stripes a, pg_class b WHERE a.relfilenode=b.relfilenode AND b.relname='t';
|
|
count
|
|
-------
|
|
3
|
|
(1 row)
|
|
|
|
-- VACUUM FULL doesn't reclaim dropped columns, but converts them to NULLs
|
|
ALTER TABLE t DROP COLUMN a;
|
|
SELECT stripe, attr, block, minimum_value IS NULL, maximum_value IS NULL FROM cstore.cstore_skipnodes a, pg_class b WHERE a.relfilenode=b.relfilenode AND b.relname='t' ORDER BY 1, 2, 3;
|
|
stripe | attr | block | ?column? | ?column?
|
|
--------+------+-------+----------+----------
|
|
1 | 1 | 0 | f | f
|
|
1 | 2 | 0 | f | f
|
|
2 | 1 | 0 | f | f
|
|
2 | 2 | 0 | f | f
|
|
3 | 1 | 0 | f | f
|
|
3 | 2 | 0 | f | f
|
|
(6 rows)
|
|
|
|
VACUUM FULL t;
|
|
SELECT stripe, attr, block, minimum_value IS NULL, maximum_value IS NULL FROM cstore.cstore_skipnodes a, pg_class b WHERE a.relfilenode=b.relfilenode AND b.relname='t' ORDER BY 1, 2, 3;
|
|
stripe | attr | block | ?column? | ?column?
|
|
--------+------+-------+----------+----------
|
|
1 | 1 | 0 | t | t
|
|
1 | 2 | 0 | f | f
|
|
2 | 1 | 0 | t | t
|
|
2 | 2 | 0 | f | f
|
|
3 | 1 | 0 | t | t
|
|
3 | 2 | 0 | f | f
|
|
(6 rows)
|
|
|
|
-- Make sure we cleaned-up the transient table metadata after VACUUM FULL commands
|
|
SELECT count(*) - :columnar_table_count FROM cstore.cstore_data_files;
|
|
?column?
|
|
----------
|
|
1
|
|
(1 row)
|
|
|
|
-- do this in a transaction so concurrent autovacuum doesn't interfere with results
|
|
BEGIN;
|
|
SAVEPOINT s1;
|
|
SELECT count(*) FROM t;
|
|
count
|
|
-------
|
|
2530
|
|
(1 row)
|
|
|
|
SELECT pg_size_pretty(pg_relation_size('t'));
|
|
pg_size_pretty
|
|
----------------
|
|
32 kB
|
|
(1 row)
|
|
|
|
INSERT INTO t SELECT i FROM generate_series(1, 10000) i;
|
|
SELECT pg_size_pretty(pg_relation_size('t'));
|
|
pg_size_pretty
|
|
----------------
|
|
112 kB
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM t;
|
|
count
|
|
-------
|
|
12530
|
|
(1 row)
|
|
|
|
ROLLBACK TO SAVEPOINT s1;
|
|
-- not truncated by VACUUM or autovacuum yet (being in transaction ensures this),
|
|
-- so relation size should be same as before.
|
|
SELECT pg_size_pretty(pg_relation_size('t'));
|
|
pg_size_pretty
|
|
----------------
|
|
112 kB
|
|
(1 row)
|
|
|
|
COMMIT;
|
|
-- vacuum should truncate the relation to the usable space
|
|
VACUUM VERBOSE t;
|
|
INFO: statistics for "t":
|
|
total file size: 114688, total data size: 10754
|
|
total row count: 2530, stripe count: 3, average rows per stripe: 843
|
|
block count: 3, containing data for dropped columns: 0, none compressed: 3, pglz compressed: 0
|
|
|
|
INFO: "t": truncated 14 to 4 pages
|
|
DETAIL: CPU: user: 0.00 s, system: 0.00 s, elapsed: 0.00 s
|
|
SELECT pg_size_pretty(pg_relation_size('t'));
|
|
pg_size_pretty
|
|
----------------
|
|
32 kB
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM t;
|
|
count
|
|
-------
|
|
2530
|
|
(1 row)
|
|
|
|
-- add some stripes with different compression types and create some gaps,
|
|
-- then vacuum to print stats
|
|
BEGIN;
|
|
SET cstore.block_row_count TO 1000;
|
|
SET cstore.stripe_row_count TO 2000;
|
|
SET cstore.compression TO "pglz";
|
|
SAVEPOINT s1;
|
|
INSERT INTO t SELECT i FROM generate_series(1, 1500) i;
|
|
ROLLBACK TO SAVEPOINT s1;
|
|
INSERT INTO t SELECT i / 5 FROM generate_series(1, 1500) i;
|
|
SET cstore.compression TO "none";
|
|
SAVEPOINT s2;
|
|
INSERT INTO t SELECT i FROM generate_series(1, 1500) i;
|
|
ROLLBACK TO SAVEPOINT s2;
|
|
INSERT INTO t SELECT i / 5 FROM generate_series(1, 1500) i;
|
|
COMMIT;
|
|
VACUUM VERBOSE t;
|
|
INFO: statistics for "t":
|
|
total file size: 49152, total data size: 18808
|
|
total row count: 5530, stripe count: 5, average rows per stripe: 1106
|
|
block count: 7, containing data for dropped columns: 0, none compressed: 5, pglz compressed: 2
|
|
|
|
SELECT count(*) FROM t;
|
|
count
|
|
-------
|
|
5530
|
|
(1 row)
|
|
|
|
-- check that we report blocks with data for dropped columns
|
|
ALTER TABLE t ADD COLUMN c int;
|
|
INSERT INTO t SELECT 1, i / 5 FROM generate_series(1, 1500) i;
|
|
ALTER TABLE t DROP COLUMN c;
|
|
VACUUM VERBOSE t;
|
|
INFO: statistics for "t":
|
|
total file size: 65536, total data size: 31372
|
|
total row count: 7030, stripe count: 6, average rows per stripe: 1171
|
|
block count: 11, containing data for dropped columns: 2, none compressed: 9, pglz compressed: 2
|
|
|
|
-- vacuum full should remove blocks for dropped columns
|
|
-- note that, a block will be stored in non-compressed for if compression
|
|
-- doesn't reduce its size.
|
|
SET cstore.compression TO "pglz";
|
|
VACUUM FULL t;
|
|
VACUUM VERBOSE t;
|
|
INFO: statistics for "t":
|
|
total file size: 49152, total data size: 15728
|
|
total row count: 7030, stripe count: 4, average rows per stripe: 1757
|
|
block count: 8, containing data for dropped columns: 0, none compressed: 2, pglz compressed: 6
|
|
|
|
DROP TABLE t;
|
|
-- Make sure we cleaned the metadata for t too
|
|
SELECT count(*) - :columnar_table_count FROM cstore.cstore_data_files;
|
|
?column?
|
|
----------
|
|
0
|
|
(1 row)
|
|
|