This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION colocated_placement_count(source_relation_name regclass, dest_relation_name regclass) | |
RETURNS INT | |
LANGUAGE plpgsql | |
SECURITY DEFINER | |
SET search_path = pg_catalog | |
AS $colocated_placement_count$ | |
DECLARE | |
shard_placement_count_val INT := 0; | |
BEGIN | |
PERFORM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Preprequiste: | |
* The followings are already added by 5.3 update. Hoever, in order to test non 5.3 clusters, do the following: | |
* Add a new sequence: | |
CREATE SEQUENCE citus.pg_dist_collocation_id | |
MINVALUE 1 | |
NO CYCLE; | |
ALTER SEQUENCE citus.pg_dist_collocation_id SET SCHEMA pg_catalog; | |
* Add a column to pg_dist_partition: | |
ALTER TABLE pg_dist_partition ADD COLUMN colocationId BIGINT DEFAULT 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/backend/distributed/executor/multi_router_executor.c b/src/backend/distributed/executor/multi_router_executor.c | |
index 58ffdb3..1202b18 100644 | |
--- a/src/backend/distributed/executor/multi_router_executor.c | |
+++ b/src/backend/distributed/executor/multi_router_executor.c | |
@@ -385,14 +385,28 @@ RouterExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long count) | |
Query *query = workerJob->jobQuery; | |
Oid relationId = ((RangeTblEntry *) linitial(query->rtable))->relid; | |
- ExecuteMasterEvaluableFunctions(query); | |
+ //ExecuteMasterEvaluableFunctions(query); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE http_request ( | |
site_id INT, | |
ingest_time TIMESTAMPTZ DEFAULT now(), | |
url TEXT, | |
request_country TEXT, | |
ip_address TEXT, | |
status_code INT, | |
response_time_msec INT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE table_1 (key int, value int); | |
CREATE TABLE table_2 (key int, value int); | |
CREATE TABLE table_3 (key int, value int); | |
SET citus.shard_count TO 4; | |
SET citus.shard_replication_factor TO 1; | |
SELECT create_distributed_table ('table_1', 'key'); | |
SELECT create_distributed_table ('table_2', 'key'); | |
SELECT create_distributed_table ('table_3', 'key'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TYPE user_composite_type AS (tenant_id bigint, user_id bigint); | |
CREATE FUNCTION user_composite_type_equal(user_composite_type, | |
user_composite_type) | |
returns boolean AS 'select $1.tenant_id = $2.tenant_id AND $1.user_id = $2.user_id;' language sql immutable | |
returns NULL ON NULL input; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
avg(array_length(events, 1)) AS event_average, | |
hasdone | |
FROM ( | |
SELECT | |
subquery_1.user_id, | |
array_agg(event) AS events, | |
COALESCE(hasdone, 'Has not done paying') AS hasdone | |
FROM | |
( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- join condition is TRUE | |
-- LATERAL example | |
INSERT INTO agg_events | |
( | |
user_id, | |
value_4_agg | |
) | |
SELECT outer_most.id, | |
Max(outer_most.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE events ( | |
user_id int, | |
event_id bigint, | |
event_type character varying(255), | |
event_time bigint | |
); | |
SELECT master_create_distributed_table('events', 'user_id', 'range'); |