Skip to content

Instantly share code, notes, and snippets.

View onderkalaci's full-sized avatar

Önder Kalacı onderkalaci

View GitHub Profile
CREATE TABLE columnar_test(col_int integer, col_text text, col_text_compressed text COMPRESSION pglz, col_json_b jsonb) USING COLUMNAR;
BEGIN;
insert into columnar_test SELECT i, i::text, i::text, test_jsonb() FROM generate_series(0,1000000)i;
CREATE INDEX i1 ON columnar_test(col_int, col_text, col_text_compressed, col_json_b);
set enable_seqscan to off; set columnar.enable_custom_scan to off;
EXPLAIN SELECT count(*) FROM columnar_test WHERE col_int = random();
@onderkalaci
onderkalaci / citus_10_2.txt
Last active September 6, 2021 10:19
Citus 10.2
1) Postgres 14 support - https://github.com/citusdata/citus/pull/5209
1.1) Lots of newly supported features, see here for all the new imporovements: https://www.postgresql.org/docs/14/release-14.html
1.2) Major known unsupported PG 14 features on Citus 10.2:
- COPY progress report when COPY dist/ref TO ...
- Re-index partitioned tables: https://github.com/citusdata/citus/pull/5238
- OUT parameters on procedure pushdown delegation - https://github.com/citusdata/citus/pull/5228
- Extended statistics objects on expressions: https://github.com/citusdata/citus/pull/5224
@onderkalaci
onderkalaci / 10_1_adaptive_executor_enhancements_benchmark.sql
Last active July 30, 2021 08:32
Citus 10.1 Adaptive Executor Enhancements Benchmark
-- tables and load 1M rows
CREATE TABLE table_1 (key int primary key, value int);
SELECT create_distributed_table('table_1', 'key');
INSERT INTO table_1 SELECT i, i % 1000 FROM generate_series(0, 1000000)i;
-- create index on the table that we'll use as an index
CREATE INDEX table_1_value ON table_1 (value);
-- create the second table and populate it
CREATE TABLE table_2 (key int primary key, value int);
-- tables and load 1M rows
CREATE TABLE table_1 (key int primary key, value int);
SELECT create_distributed_table('table_1', 'key');
INSERT INTO table_1 SELECT i, i % 1000 FROM generate_series(0, 1000000)i;
-- create index on the table that we'll use as an index
CREATE INDEX table_1_value ON table_1 (value);
-- create the second table and populate it
CREATE TABLE table_2 (key int primary key, value int);
@onderkalaci
onderkalaci / rebalance_helper.sql
Created April 1, 2021 13:16
Rebalance helpers
-- shows the current data size on the TARGET nodes of online rebalance
-- update "nodename" in the query with the host address of the target node
-- or not have a nodename filter to see all the nodes
SELECT * FROM run_command_on_workers($$
SELECT pg_size_pretty(sum(pg_total_relation_size(srrelid)))
FROM pg_subscription_rel,pg_stat_subscription
WHERE srsubid = subid AND subname = 'citus_shard_move_subscription';$$) WHERE nodename = '10.0.0.21';
@onderkalaci
onderkalaci / union_all.sql
Last active March 23, 2021 16:33
union all
CREATE TABLE users_table_part(user_id bigint, value_1 int, value_2 int) PARTITION BY RANGE (value_1);
CREATE TABLE users_table_part_0 PARTITION OF users_table_part FOR VALUES FROM (0) TO (1);
CREATE TABLE users_table_part_1 PARTITION OF users_table_part FOR VALUES FROM (1) TO (2);
CREATE TABLE users_table_part_2 PARTITION OF users_table_part FOR VALUES FROM (2) TO (3);
CREATE TABLE users_table_part_3 PARTITION OF users_table_part FOR VALUES FROM (3) TO (4);
CREATE TABLE users_table_part_4 PARTITION OF users_table_part FOR VALUES FROM (4) TO (5);
CREATE TABLE users_table_part_5 PARTITION OF users_table_part FOR VALUES FROM (5) TO (6);
CREATE TABLE users_table_part_6 PARTITION OF users_table_part FOR VALUES FROM (6) TO (7);
CREATE TABLE users_table_part_7 PARTITION OF users_table_part FOR VALUES FROM (7) TO (8);
@onderkalaci
onderkalaci / alias.sql
Created February 16, 2021 11:34
Alias same with column name
CREATE TABLE test (a int, b text);
EXPLAIN (ANALYZE, VERBOSE)
SELECT
a,
case when b = '1' then '-'
when b is null then '-'
else b end as b,
@onderkalaci
onderkalaci / create_table.sql
Created January 31, 2021 17:57
On-call process
CREATE TABLE on_call_updated
(
source text,
citus_version text,
postgres_version text,
"Issue description" text,
Resolved text,
Resolution text,
"Relevant Links" text,
@onderkalaci
onderkalaci / undist_basics.sql
Last active January 20, 2021 16:25
Undistribute basic
-- regression tests regarding foreign key
-- drops cascading into undistributing Citus
-- local tables to Postgres local tables
CREATE SCHEMA drop_fkey_cascade;
SET search_patch TO drop_fkey_cascade;
SET client_min_messages TO WARNING;
-- show that DROP CONSTRAINT cascades to undistributing citus_local_table
CREATE TABLE citus_local_table(l1 int);
SELECT create_citus_local_table('citus_local_table');
SET citus.replication_model to statement ;
set citus.shard_replication_factor TO 2;
CREATE SCHEMA sc1;
CREATE TABLE sc1.test (a int);
SELECT create_distributed_table('sc1.test', 'a');