mirror of https://github.com/citusdata/citus.git
Switch to new API for colocation
parent
726ea93ca0
commit
101bb8f554
|
@ -3,60 +3,41 @@
|
|||
--
|
||||
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 13300000;
|
||||
ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 13300000;
|
||||
-- create co-located tables
|
||||
SET citus.shard_count = 4;
|
||||
SET citus.shard_replication_factor = 2;
|
||||
CREATE TABLE raw_events_first (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint, UNIQUE(user_id, value_1));
|
||||
SELECT master_create_distributed_table('raw_events_first', 'user_id', 'hash');
|
||||
master_create_distributed_table
|
||||
---------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT master_create_worker_shards('raw_events_first', 4, 2);
|
||||
master_create_worker_shards
|
||||
-----------------------------
|
||||
SELECT create_distributed_table('raw_events_first', 'user_id');
|
||||
create_distributed_table
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE TABLE raw_events_second (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint, UNIQUE(user_id, value_1));
|
||||
SELECT master_create_distributed_table('raw_events_second', 'user_id', 'hash');
|
||||
master_create_distributed_table
|
||||
---------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT master_create_worker_shards('raw_events_second', 4, 2);
|
||||
master_create_worker_shards
|
||||
-----------------------------
|
||||
SELECT create_distributed_table('raw_events_second', 'user_id');
|
||||
create_distributed_table
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
CREATE TABLE agg_events (user_id int, value_1_agg int, value_2_agg int, value_3_agg float, value_4_agg bigint, agg_time timestamp, UNIQUE(user_id, value_1_agg));
|
||||
SELECT master_create_distributed_table('agg_events', 'user_id', 'hash');
|
||||
master_create_distributed_table
|
||||
---------------------------------
|
||||
SELECT create_distributed_table('agg_events', 'user_id');;
|
||||
create_distributed_table
|
||||
--------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT master_create_worker_shards('agg_events', 4, 2);
|
||||
master_create_worker_shards
|
||||
-----------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- make tables as co-located
|
||||
UPDATE pg_dist_partition SET colocationid = 100000 WHERE logicalrelid IN ('raw_events_first', 'raw_events_second', 'agg_events');
|
||||
-- create the reference table as well
|
||||
CREATE TABLE reference_table (user_id int);
|
||||
SELECT master_create_distributed_table('reference_table', 'user_id', 'hash');
|
||||
master_create_distributed_table
|
||||
---------------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SELECT master_create_worker_shards('reference_table', 1, 2);
|
||||
master_create_worker_shards
|
||||
-----------------------------
|
||||
SELECT create_reference_table('reference_table');
|
||||
create_reference_table
|
||||
------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
-- set back to the defaults
|
||||
SET citus.shard_count = DEFAULT;
|
||||
SET citus.shard_replication_factor = DEFAULT;
|
||||
INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES
|
||||
(1, now(), 10, 100, 1000.1, 10000);
|
||||
INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES
|
||||
|
@ -133,7 +114,7 @@ WHERE
|
|||
INSERT INTO raw_events_second SELECT * FROM raw_events_first;
|
||||
ERROR: duplicate key value violates unique constraint "raw_events_second_user_id_value_1_key_13300004"
|
||||
DETAIL: Key (user_id, value_1)=(1, 10) already exists.
|
||||
CONTEXT: while executing command on localhost:57638
|
||||
CONTEXT: while executing command on localhost:57637
|
||||
-- add one more row
|
||||
INSERT INTO raw_events_first (user_id, time) VALUES
|
||||
(7, now());
|
||||
|
@ -365,7 +346,7 @@ DEBUG: ProcessQuery
|
|||
DEBUG: Plan is router executable
|
||||
ERROR: duplicate key value violates unique constraint "raw_events_second_user_id_value_1_key_13300007"
|
||||
DETAIL: Key (user_id, value_1)=(9, 90) already exists.
|
||||
CONTEXT: while executing command on localhost:57637
|
||||
CONTEXT: while executing command on localhost:57638
|
||||
-- now do some aggregations
|
||||
INSERT INTO agg_events
|
||||
SELECT
|
||||
|
|
|
@ -5,26 +5,26 @@
|
|||
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 13300000;
|
||||
ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 13300000;
|
||||
|
||||
-- create co-located tables
|
||||
SET citus.shard_count = 4;
|
||||
SET citus.shard_replication_factor = 2;
|
||||
|
||||
CREATE TABLE raw_events_first (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint, UNIQUE(user_id, value_1));
|
||||
SELECT master_create_distributed_table('raw_events_first', 'user_id', 'hash');
|
||||
SELECT master_create_worker_shards('raw_events_first', 4, 2);
|
||||
SELECT create_distributed_table('raw_events_first', 'user_id');
|
||||
|
||||
CREATE TABLE raw_events_second (user_id int, time timestamp, value_1 int, value_2 int, value_3 float, value_4 bigint, UNIQUE(user_id, value_1));
|
||||
SELECT master_create_distributed_table('raw_events_second', 'user_id', 'hash');
|
||||
SELECT master_create_worker_shards('raw_events_second', 4, 2);
|
||||
SELECT create_distributed_table('raw_events_second', 'user_id');
|
||||
|
||||
CREATE TABLE agg_events (user_id int, value_1_agg int, value_2_agg int, value_3_agg float, value_4_agg bigint, agg_time timestamp, UNIQUE(user_id, value_1_agg));
|
||||
SELECT master_create_distributed_table('agg_events', 'user_id', 'hash');
|
||||
SELECT master_create_worker_shards('agg_events', 4, 2);
|
||||
|
||||
-- make tables as co-located
|
||||
UPDATE pg_dist_partition SET colocationid = 100000 WHERE logicalrelid IN ('raw_events_first', 'raw_events_second', 'agg_events');
|
||||
|
||||
SELECT create_distributed_table('agg_events', 'user_id');;
|
||||
|
||||
-- create the reference table as well
|
||||
CREATE TABLE reference_table (user_id int);
|
||||
SELECT master_create_distributed_table('reference_table', 'user_id', 'hash');
|
||||
SELECT master_create_worker_shards('reference_table', 1, 2);
|
||||
SELECT create_reference_table('reference_table');
|
||||
|
||||
-- set back to the defaults
|
||||
SET citus.shard_count = DEFAULT;
|
||||
SET citus.shard_replication_factor = DEFAULT;
|
||||
|
||||
INSERT INTO raw_events_first (user_id, time, value_1, value_2, value_3, value_4) VALUES
|
||||
(1, now(), 10, 100, 1000.1, 10000);
|
||||
|
|
Loading…
Reference in New Issue