1-- columnar--9.5-1--10.0-1.sql 2 3CREATE SCHEMA columnar; 4SET search_path TO columnar; 5 6CREATE SEQUENCE storageid_seq MINVALUE 10000000000 NO CYCLE; 7 8CREATE TABLE options ( 9 regclass regclass NOT NULL PRIMARY KEY, 10 chunk_group_row_limit int NOT NULL, 11 stripe_row_limit int NOT NULL, 12 compression_level int NOT NULL, 13 compression name NOT NULL 14) WITH (user_catalog_table = true); 15 16COMMENT ON TABLE options IS 'columnar table specific options, maintained by alter_columnar_table_set'; 17 18CREATE TABLE stripe ( 19 storage_id bigint NOT NULL, 20 stripe_num bigint NOT NULL, 21 file_offset bigint NOT NULL, 22 data_length bigint NOT NULL, 23 column_count int NOT NULL, 24 chunk_row_count int NOT NULL, 25 row_count bigint NOT NULL, 26 chunk_group_count int NOT NULL, 27 PRIMARY KEY (storage_id, stripe_num) 28) WITH (user_catalog_table = true); 29 30COMMENT ON TABLE stripe IS 'Columnar per stripe metadata'; 31 32CREATE TABLE chunk_group ( 33 storage_id bigint NOT NULL, 34 stripe_num bigint NOT NULL, 35 chunk_group_num int NOT NULL, 36 row_count bigint NOT NULL, 37 PRIMARY KEY (storage_id, stripe_num, chunk_group_num), 38 FOREIGN KEY (storage_id, stripe_num) REFERENCES stripe(storage_id, stripe_num) ON DELETE CASCADE 39); 40 41COMMENT ON TABLE chunk_group IS 'Columnar chunk group metadata'; 42 43CREATE TABLE chunk ( 44 storage_id bigint NOT NULL, 45 stripe_num bigint NOT NULL, 46 attr_num int NOT NULL, 47 chunk_group_num int NOT NULL, 48 minimum_value bytea, 49 maximum_value bytea, 50 value_stream_offset bigint NOT NULL, 51 value_stream_length bigint NOT NULL, 52 exists_stream_offset bigint NOT NULL, 53 exists_stream_length bigint NOT NULL, 54 value_compression_type int NOT NULL, 55 value_compression_level int NOT NULL, 56 value_decompressed_length bigint NOT NULL, 57 value_count bigint NOT NULL, 58 PRIMARY KEY (storage_id, stripe_num, attr_num, chunk_group_num), 59 FOREIGN KEY (storage_id, stripe_num, chunk_group_num) REFERENCES chunk_group(storage_id, stripe_num, chunk_group_num) ON DELETE CASCADE 60) WITH (user_catalog_table = true); 61 62COMMENT ON TABLE chunk IS 'Columnar per chunk metadata'; 63 64DO $proc$ 65BEGIN 66 67-- from version 12 and up we have support for tableam's if installed on pg11 we can't 68-- create the objects here. Instead we rely on citus_finish_pg_upgrade to be called by the 69-- user instead to add the missing objects 70IF substring(current_Setting('server_version'), '\d+')::int >= 12 THEN 71 EXECUTE $$ 72#include "udfs/columnar_handler/10.0-1.sql" 73#include "udfs/alter_columnar_table_set/10.0-1.sql" 74#include "udfs/alter_columnar_table_reset/10.0-1.sql" 75 $$; 76END IF; 77END$proc$; 78 79#include "udfs/columnar_ensure_objects_exist/10.0-1.sql" 80 81RESET search_path; 82