citus/src/test/regress/expected/multi_size_queries.out

299 lines
9.9 KiB
Plaintext

--
-- MULTI_SIZE_QUERIES
--
-- Test checks whether size of distributed tables can be obtained with citus_table_size.
-- To find the relation size and total relation size citus_relation_size and
-- citus_total_relation_size are also tested.
SET citus.next_shard_id TO 1390000;
-- Tests with invalid relation IDs
SELECT citus_table_size(1);
ERROR: could not compute relation size: relation does not exist
SELECT citus_relation_size(1);
ERROR: could not compute relation size: relation does not exist
SELECT citus_total_relation_size(1);
ERROR: could not compute relation size: relation does not exist
-- Tests with non-distributed table
CREATE TABLE non_distributed_table (x int primary key);
-- table
SELECT citus_table_size('non_distributed_table');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
SELECT citus_relation_size('non_distributed_table');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
SELECT citus_total_relation_size('non_distributed_table');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
-- index
SELECT citus_table_size('non_distributed_table_pkey');
ERROR: cannot calculate the size because table 'non_distributed_table' for index 'non_distributed_table_pkey' is not distributed
SELECT citus_relation_size('non_distributed_table_pkey');
ERROR: cannot calculate the size because table 'non_distributed_table' for index 'non_distributed_table_pkey' is not distributed
SELECT citus_total_relation_size('non_distributed_table_pkey');
ERROR: cannot calculate the size because table 'non_distributed_table' for index 'non_distributed_table_pkey' is not distributed
DROP TABLE non_distributed_table;
-- fix broken placements via disabling the node
SET client_min_messages TO ERROR;
SELECT replicate_table_shards('lineitem_hash_part', shard_replication_factor:=2, shard_transfer_mode:='block_writes');
replicate_table_shards
---------------------------------------------------------------------
(1 row)
CREATE INDEX lineitem_hash_part_idx ON lineitem_hash_part(l_orderkey);
-- Tests on distributed table with replication factor > 1
VACUUM (FULL) lineitem_hash_part;
-- table
SELECT citus_table_size('lineitem_hash_part');
citus_table_size
---------------------------------------------------------------------
3801088
(1 row)
SELECT citus_relation_size('lineitem_hash_part');
citus_relation_size
---------------------------------------------------------------------
3801088
(1 row)
SELECT citus_total_relation_size('lineitem_hash_part');
citus_total_relation_size
---------------------------------------------------------------------
4259840
(1 row)
-- index
SELECT citus_table_size('lineitem_hash_part_idx');
citus_table_size
---------------------------------------------------------------------
458752
(1 row)
SELECT citus_relation_size('lineitem_hash_part_idx');
citus_relation_size
---------------------------------------------------------------------
458752
(1 row)
SELECT citus_total_relation_size('lineitem_hash_part_idx');
citus_total_relation_size
---------------------------------------------------------------------
458752
(1 row)
DROP INDEX lineitem_hash_part_idx;
CREATE INDEX customer_copy_hash_idx on customer_copy_hash(c_custkey);
VACUUM (FULL) customer_copy_hash;
-- Tests on distributed tables with streaming replication.
-- table
SELECT citus_table_size('customer_copy_hash');
citus_table_size
---------------------------------------------------------------------
548864
(1 row)
SELECT citus_relation_size('customer_copy_hash');
citus_relation_size
---------------------------------------------------------------------
548864
(1 row)
SELECT citus_total_relation_size('customer_copy_hash');
citus_total_relation_size
---------------------------------------------------------------------
2646016
(1 row)
-- index
SELECT citus_table_size('customer_copy_hash_idx');
citus_table_size
---------------------------------------------------------------------
1048576
(1 row)
SELECT citus_relation_size('customer_copy_hash_idx');
citus_relation_size
---------------------------------------------------------------------
1048576
(1 row)
SELECT citus_total_relation_size('customer_copy_hash_idx');
citus_total_relation_size
---------------------------------------------------------------------
1048576
(1 row)
VACUUM (FULL) supplier;
-- Make sure we can get multiple sizes in a single query
SELECT citus_table_size('customer_copy_hash'),
citus_table_size('customer_copy_hash'),
citus_table_size('supplier');
citus_table_size | citus_table_size | citus_table_size
---------------------------------------------------------------------
548864 | 548864 | 565248
(1 row)
-- Tests on reference table
-- table
SELECT citus_table_size('supplier');
citus_table_size
---------------------------------------------------------------------
565248
(1 row)
SELECT citus_relation_size('supplier');
citus_relation_size
---------------------------------------------------------------------
565248
(1 row)
SELECT citus_total_relation_size('supplier');
citus_total_relation_size
---------------------------------------------------------------------
565248
(1 row)
CREATE INDEX supplier_idx on supplier(s_suppkey);
-- table
SELECT citus_table_size('supplier');
citus_table_size
---------------------------------------------------------------------
565248
(1 row)
SELECT citus_relation_size('supplier');
citus_relation_size
---------------------------------------------------------------------
565248
(1 row)
SELECT citus_total_relation_size('supplier');
citus_total_relation_size
---------------------------------------------------------------------
688128
(1 row)
-- index
SELECT citus_table_size('supplier_idx');
citus_table_size
---------------------------------------------------------------------
122880
(1 row)
SELECT citus_relation_size('supplier_idx');
citus_relation_size
---------------------------------------------------------------------
122880
(1 row)
SELECT citus_total_relation_size('supplier_idx');
citus_total_relation_size
---------------------------------------------------------------------
122880
(1 row)
-- Test on partitioned table
CREATE TABLE split_me (dist_col int, partition_col timestamp) PARTITION BY RANGE (partition_col);
CREATE INDEX ON split_me(dist_col);
-- create 2 partitions
CREATE TABLE m PARTITION OF split_me FOR VALUES FROM ('2018-01-01') TO ('2019-01-01');
CREATE TABLE e PARTITION OF split_me FOR VALUES FROM ('2019-01-01') TO ('2020-01-01');
-- before citus
SELECT citus_relation_size('split_me');
ERROR: cannot calculate the size because relation 'split_me' is not distributed
SELECT citus_relation_size('split_me_dist_col_idx');
ERROR: cannot calculate the size because table 'split_me' for index 'split_me_dist_col_idx' is not distributed
SELECT citus_relation_size('m');
ERROR: cannot calculate the size because relation 'm' is not distributed
SELECT citus_relation_size('m_dist_col_idx');
ERROR: cannot calculate the size because table 'm' for index 'm_dist_col_idx' is not distributed
-- distribute the table(s)
SELECT create_distributed_table('split_me', 'dist_col');
create_distributed_table
---------------------------------------------------------------------
(1 row)
-- after citus
SELECT citus_relation_size('split_me');
citus_relation_size
---------------------------------------------------------------------
0
(1 row)
SELECT citus_relation_size('split_me_dist_col_idx');
citus_relation_size
---------------------------------------------------------------------
0
(1 row)
SELECT citus_relation_size('m');
citus_relation_size
---------------------------------------------------------------------
0
(1 row)
SELECT citus_relation_size('m_dist_col_idx');
citus_relation_size
---------------------------------------------------------------------
65536
(1 row)
-- And we should make sure that following always returns true:
SELECT citus_relation_size('split_me_dist_col_idx')
< citus_relation_size('split_me_dist_col_idx')
+ citus_relation_size('m_dist_col_idx')
+ citus_relation_size('e_dist_col_idx');
?column?
---------------------------------------------------------------------
t
(1 row)
DROP TABLE split_me;
-- Test inside the transaction
BEGIN;
ALTER TABLE supplier ALTER COLUMN s_suppkey SET NOT NULL;
select citus_table_size('supplier');
ERROR: citus size functions cannot be called in transaction blocks which contain multi-shard data modifications
END;
show citus.node_conninfo;
citus.node_conninfo
---------------------------------------------------------------------
sslmode=require
(1 row)
ALTER SYSTEM SET citus.node_conninfo = 'sslmode=require';
SELECT pg_reload_conf();
pg_reload_conf
---------------------------------------------------------------------
t
(1 row)
-- make sure that any invalidation to the connection info
-- wouldn't prevent future commands to fail
SELECT citus_total_relation_size('customer_copy_hash');
citus_total_relation_size
---------------------------------------------------------------------
2646016
(1 row)
SELECT pg_reload_conf();
pg_reload_conf
---------------------------------------------------------------------
t
(1 row)
SELECT citus_total_relation_size('customer_copy_hash');
citus_total_relation_size
---------------------------------------------------------------------
2646016
(1 row)
-- reset back to the original node_conninfo
ALTER SYSTEM RESET citus.node_conninfo;
SELECT pg_reload_conf();
pg_reload_conf
---------------------------------------------------------------------
t
(1 row)
DROP INDEX customer_copy_hash_idx;
DROP INDEX supplier_idx;