timescaledb/tsl/test/sql/compression_create_compressed_table.sql
Sven Klemm b2a91494a1 Move ddl_internal functions to _timescaledb_functions schema
To increase schema security we do not want to mix our own internal
objects with user objects. Since chunks are created in the
_timescaledb_internal schema our internal functions should live in
a different dedicated schema. This patch make the necessary
adjustments for the following functions:

- chunk_constraint_add_table_constraint(_timescaledb_catalog.chunk_constraint)
- chunk_drop_replica(regclass,name)
- chunk_index_clone(oid)
- chunk_index_replace(oid,oid)
- create_chunk_replica_table(regclass,name)
- drop_stale_chunks(name,integer[])
- health()
- hypertable_constraint_add_table_fk_constraint(name,name,name,integer)
- process_ddl_event()
- wait_subscription_sync(name,name,integer,numeric)
2023-08-29 11:15:39 +02:00

51 lines
1.8 KiB
SQL

-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
\c :TEST_DBNAME :ROLE_SUPERUSER
-- create compressed hypertable
CREATE TABLE "public"."metrics" (
"time" timestamp with time zone NOT NULL,
"device_id" "text",
"val" double precision
);
SELECT create_hypertable('public.metrics', 'time');
ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby = 'time', timescaledb.compress_segmentby = 'device_id');
-- insert uncompressed row into hypertable
INSERT INTO metrics (time, device_id, val)
VALUES('2023-05-01T00:00:00Z'::timestamptz, 1, 1.0);
SELECT count(*) FROM _timescaledb_internal._hyper_1_1_chunk;
-- compress these rows, we do this to get compressed row data for the test
SELECT compress_chunk('_timescaledb_internal._hyper_1_1_chunk');
-- create custom compressed chunk table
CREATE TABLE "_timescaledb_internal"."custom_compressed_chunk"() INHERITS ("_timescaledb_internal"."_compressed_hypertable_2");
-- copy compressed row from compressed table into custom compressed chunk table
INSERT INTO "_timescaledb_internal"."custom_compressed_chunk" SELECT * FROM "_timescaledb_internal"."compress_hyper_2_2_chunk";
-- decompress the rows, moving them back to uncompressed space
SELECT decompress_chunk('"_timescaledb_internal"."_hyper_1_1_chunk"');
-- attach compressed chunk to parent chunk
SELECT _timescaledb_functions.create_compressed_chunk(
'"_timescaledb_internal"."_hyper_1_1_chunk"'::TEXT::REGCLASS,
'"_timescaledb_internal"."custom_compressed_chunk"'::TEXT::REGCLASS,
8192,
8192,
16384,
8192,
8192,
16384,
1,
1
);
-- select total rows in chunk (should be 2)
SELECT count(*) FROM "_timescaledb_internal"."_hyper_1_1_chunk";