mirror of https://github.com/citusdata/citus.git
148 lines
6.4 KiB
Plaintext
148 lines
6.4 KiB
Plaintext
CREATE SCHEMA citus_aggregated_stats;
|
|
SET search_path TO citus_aggregated_stats, public;
|
|
SET citus.shard_count = 2;
|
|
SET citus.next_shard_id TO 1870000;
|
|
CREATE USER user1;
|
|
GRANT ALL ON SCHEMA citus_aggregated_stats TO user1;
|
|
SET SESSION AUTHORIZATION user1;
|
|
CREATE TABLE current_check (currentid int, payload text, rlsuser text);
|
|
GRANT ALL ON current_check TO PUBLIC;
|
|
INSERT INTO current_check VALUES
|
|
(1, 'abc', 'user1'),
|
|
(3, 'cde', 'user1'),
|
|
(4, 'def', 'user1'),
|
|
(4, 'def', 'user1'),
|
|
(3, 'cde', 'user2'),
|
|
(5, NULL, NULL),
|
|
(4, 'def', 'user1');
|
|
ALTER TABLE current_check ENABLE ROW LEVEL SECURITY;
|
|
SET row_security TO ON;
|
|
ANALYZE current_check;
|
|
SELECT schemaname, tablename, attname, null_frac, most_common_vals, most_common_freqs FROM pg_stats
|
|
WHERE tablename IN ('current_check', 'dist_current_check', 'ref_current_check', 'citus_local_current_check')
|
|
ORDER BY 1;
|
|
schemaname | tablename | attname | null_frac | most_common_vals | most_common_freqs
|
|
---------------------------------------------------------------------
|
|
citus_aggregated_stats | current_check | currentid | 0 | {4,3} | {0.428571,0.285714}
|
|
citus_aggregated_stats | current_check | payload | 0.142857 | {def,cde} | {0.428571,0.285714}
|
|
citus_aggregated_stats | current_check | rlsuser | 0.142857 | {user1} | {0.714286}
|
|
(3 rows)
|
|
|
|
SELECT * FROM citus_stats
|
|
WHERE tablename IN ('current_check', 'dist_current_check', 'ref_current_check', 'citus_local_current_check')
|
|
ORDER BY 1;
|
|
schemaname | tablename | attname | null_frac | most_common_vals | most_common_freqs
|
|
---------------------------------------------------------------------
|
|
(0 rows)
|
|
|
|
-- test various Citus table types in citus_stats
|
|
CREATE TABLE dist_current_check (currentid int, payload text, rlsuser text);
|
|
CREATE TABLE ref_current_check (currentid int, payload text, rlsuser text);
|
|
CREATE TABLE citus_local_current_check (currentid int, payload text, rlsuser text);
|
|
SELECT create_distributed_table('dist_current_check', 'currentid');
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT create_reference_table('ref_current_check');
|
|
create_reference_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
SELECT citus_add_local_table_to_metadata('citus_local_current_check');
|
|
citus_add_local_table_to_metadata
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO dist_current_check VALUES
|
|
(1, 'abc', 'user1'),
|
|
(3, 'cde', 'user1'),
|
|
(4, 'def', 'user1'),
|
|
(4, 'def', 'user1'),
|
|
(3, 'cde', 'user2'),
|
|
(5, NULL, NULL),
|
|
(4, 'def', 'user1');
|
|
INSERT INTO ref_current_check VALUES
|
|
(1, 'abc', 'user1'),
|
|
(3, 'cde', 'user1'),
|
|
(4, 'def', 'user1'),
|
|
(4, 'def', 'user1'),
|
|
(3, 'cde', 'user2'),
|
|
(5, NULL, NULL),
|
|
(4, 'def', 'user1');
|
|
INSERT INTO citus_local_current_check VALUES
|
|
(1, 'abc', 'user1'),
|
|
(3, 'cde', 'user1'),
|
|
(4, 'def', 'user1'),
|
|
(4, 'def', 'user1'),
|
|
(3, 'cde', 'user2'),
|
|
(5, NULL, NULL),
|
|
(4, 'def', 'user1');
|
|
ANALYZE dist_current_check;
|
|
ANALYZE ref_current_check;
|
|
ANALYZE citus_local_current_check;
|
|
SELECT schemaname, tablename, attname, null_frac, most_common_vals, most_common_freqs FROM pg_stats
|
|
WHERE tablename IN ('current_check', 'dist_current_check', 'ref_current_check', 'citus_local_current_check')
|
|
ORDER BY 1;
|
|
schemaname | tablename | attname | null_frac | most_common_vals | most_common_freqs
|
|
---------------------------------------------------------------------
|
|
citus_aggregated_stats | current_check | currentid | 0 | {4,3} | {0.428571,0.285714}
|
|
citus_aggregated_stats | current_check | payload | 0.142857 | {def,cde} | {0.428571,0.285714}
|
|
citus_aggregated_stats | current_check | rlsuser | 0.142857 | {user1} | {0.714286}
|
|
(3 rows)
|
|
|
|
SELECT * FROM citus_stats
|
|
WHERE tablename IN ('current_check', 'dist_current_check', 'ref_current_check', 'citus_local_current_check')
|
|
ORDER BY 1;
|
|
schemaname | tablename | attname | null_frac | most_common_vals | most_common_freqs
|
|
---------------------------------------------------------------------
|
|
citus_aggregated_stats | dist_current_check | currentid | 0 | {4,3} | {0.428571,0.285714}
|
|
citus_aggregated_stats | dist_current_check | payload | 0.142857 | {def,cde} | {0.428571,0.285714}
|
|
citus_aggregated_stats | dist_current_check | rlsuser | 0.142857 | {user1} | {0.714286}
|
|
citus_aggregated_stats | ref_current_check | currentid | 0 | {4,3} | {0.428571,0.285714}
|
|
citus_aggregated_stats | ref_current_check | payload | 0.142857 | {def,cde} | {0.428571,0.285714}
|
|
citus_aggregated_stats | ref_current_check | rlsuser | 0.142857 | {user1} | {0.714286}
|
|
citus_aggregated_stats | citus_local_current_check | currentid | 0 | {4,3} | {0.428571,0.285714}
|
|
citus_aggregated_stats | citus_local_current_check | payload | 0.142857 | {def,cde} | {0.428571,0.285714}
|
|
citus_aggregated_stats | citus_local_current_check | rlsuser | 0.142857 | {user1} | {0.714286}
|
|
(9 rows)
|
|
|
|
-- create a dist table with million rows to simulate 3.729223e+06 in reltuples
|
|
-- this tests casting numbers like 3.729223e+06 to bigint
|
|
CREATE TABLE organizations (
|
|
org_id bigint,
|
|
id int
|
|
);
|
|
SELECT create_distributed_table('organizations', 'org_id');
|
|
create_distributed_table
|
|
---------------------------------------------------------------------
|
|
|
|
(1 row)
|
|
|
|
INSERT INTO organizations(org_id, id)
|
|
SELECT i, 1
|
|
FROM generate_series(1,2000000) i;
|
|
ANALYZE organizations;
|
|
SELECT attname, null_frac, most_common_vals, most_common_freqs FROM citus_stats
|
|
WHERE tablename IN ('organizations')
|
|
ORDER BY 1;
|
|
attname | null_frac | most_common_vals | most_common_freqs
|
|
---------------------------------------------------------------------
|
|
id | 0 | {1} | {1}
|
|
(1 row)
|
|
|
|
RESET SESSION AUTHORIZATION;
|
|
DROP SCHEMA citus_aggregated_stats CASCADE;
|
|
NOTICE: drop cascades to 7 other objects
|
|
DETAIL: drop cascades to table current_check
|
|
drop cascades to table dist_current_check
|
|
drop cascades to table ref_current_check
|
|
drop cascades to table citus_local_current_check_1870003
|
|
drop cascades to table ref_current_check_1870002
|
|
drop cascades to table citus_local_current_check
|
|
drop cascades to table organizations
|
|
DROP USER user1;
|