mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-17 19:13:16 +08:00
Update hypertable metadata table to include 'insert_temp_table' and keep the insert temp table in-sync with root in terms of fields.
This commit is contained in:
parent
ee36949beb
commit
ff7762ea9e
@ -40,6 +40,7 @@ CREATE TABLE IF NOT EXISTS hypertable (
|
||||
root_table_name NAME NOT NULL,
|
||||
distinct_schema_name NAME NOT NULL,
|
||||
distinct_table_name NAME NOT NULL,
|
||||
insert_temp_table_name NAME NOT NULL,
|
||||
replication_factor SMALLINT NOT NULL CHECK (replication_factor > 0),
|
||||
placement chunk_placement_type NOT NULL,
|
||||
time_field_name NAME NOT NULL,
|
||||
@ -85,8 +86,8 @@ CREATE TABLE IF NOT EXISTS default_replica_node (
|
||||
--so there can be multiple rows for one hypertable-replica on different nodes.
|
||||
--that way writes are local. Optimized reads are also local for many queries.
|
||||
--But, some read queries are cross-node.
|
||||
--Each row creates a table.
|
||||
-- Parent table: hypertable_replica.distinct_table
|
||||
--Each row creates a table.
|
||||
-- Parent table: hypertable_replica.distinct_table
|
||||
-- No children, created table contains data.
|
||||
CREATE TABLE IF NOT EXISTS distinct_replica_node (
|
||||
hypertable_name NAME NOT NULL,
|
||||
@ -115,7 +116,7 @@ CREATE TABLE IF NOT EXISTS partition_epoch (
|
||||
CHECK (start_time < end_time)
|
||||
);
|
||||
|
||||
-- A partition defines a partition in a partition_epoch.
|
||||
-- A partition defines a partition in a partition_epoch.
|
||||
-- For any partition the keyspace is defined as [0, partition_epoch.partitioning_mod]
|
||||
-- For any epoch, there must be a partition that covers every element in the keyspace.
|
||||
CREATE TABLE IF NOT EXISTS partition (
|
||||
@ -127,7 +128,7 @@ CREATE TABLE IF NOT EXISTS partition (
|
||||
CHECK (keyspace_end > keyspace_start)
|
||||
);
|
||||
|
||||
--Represents a replica for a partition.
|
||||
--Represents a replica for a partition.
|
||||
--Each row creates a table:
|
||||
-- Parent: "hypertable_replica.schema_name"."hypertable_replica.table_name"
|
||||
-- Children: "chunk_replica_node.schema_name"."chunk_replica_node.table_name"
|
||||
@ -158,7 +159,7 @@ CREATE TABLE IF NOT EXISTS chunk (
|
||||
|
||||
--A mapping between chunks, partition_replica, and node.
|
||||
--This represents the table where actual data is stored.
|
||||
--Each row represents a table:
|
||||
--Each row represents a table:
|
||||
-- Parent table: "partition_replica.schema_name"."partition_replica.table_name"
|
||||
CREATE TABLE IF NOT EXISTS chunk_replica_node (
|
||||
chunk_id INT NOT NULL REFERENCES chunk (id),
|
||||
@ -171,8 +172,8 @@ CREATE TABLE IF NOT EXISTS chunk_replica_node (
|
||||
UNIQUE (schema_name, table_name)
|
||||
);
|
||||
|
||||
--Represents a hypertable field.
|
||||
--TODO: remove is_partitioning. defined in partition_epoch table.
|
||||
--Represents a hypertable field.
|
||||
--TODO: remove is_partitioning. defined in partition_epoch table.
|
||||
CREATE TABLE IF NOT EXISTS field (
|
||||
hypertable_name NAME NOT NULL REFERENCES hypertable (name),
|
||||
name NAME NOT NULL,
|
||||
|
@ -7,6 +7,7 @@ CREATE OR REPLACE FUNCTION add_hypertable(
|
||||
number_partitions SMALLINT = NULL,
|
||||
associated_schema_name NAME = NULL,
|
||||
associated_table_prefix NAME = NULL,
|
||||
insert_temp_table_name NAME = NULL,
|
||||
hypertable_name NAME = NULL,
|
||||
placement chunk_placement_type = 'STICKY'
|
||||
)
|
||||
@ -21,11 +22,11 @@ DECLARE
|
||||
BEGIN
|
||||
SELECT relname, nspname
|
||||
INTO STRICT table_name, schema_name
|
||||
FROM pg_class c
|
||||
FROM pg_class c
|
||||
INNER JOIN pg_namespace n ON (n.OID = c.relnamespace)
|
||||
WHERE c.OID = main_table;
|
||||
|
||||
SELECT atttypid
|
||||
SELECT atttypid
|
||||
INTO STRICT time_field_type
|
||||
FROM pg_attribute
|
||||
WHERE attrelid = main_table AND attname = time_field_name;
|
||||
@ -36,9 +37,9 @@ BEGIN
|
||||
INTO hypertable_row
|
||||
FROM dblink(
|
||||
'meta_conn',
|
||||
format('SELECT t FROM _meta.add_hypertable(%L, %L, %L, %L, %L, %L, %L, %L, %L, %L, %L, %L) t ',
|
||||
format('SELECT t FROM _meta.add_hypertable(%L, %L, %L, %L, %L, %L, %L, %L, %L, %L, %L, %L, %L) t ',
|
||||
schema_name,
|
||||
table_name,
|
||||
table_name,
|
||||
time_field_name,
|
||||
time_field_type,
|
||||
partitioning_field,
|
||||
@ -46,24 +47,25 @@ BEGIN
|
||||
number_partitions,
|
||||
associated_schema_name,
|
||||
associated_table_prefix,
|
||||
insert_temp_table_name,
|
||||
hypertable_name,
|
||||
placement,
|
||||
current_database()
|
||||
)) AS t(r TEXT);
|
||||
|
||||
FOR att_row IN SELECT *
|
||||
FROM pg_attribute att
|
||||
FROM pg_attribute att
|
||||
WHERE attrelid = main_table AND attnum > 0 AND NOT attisdropped
|
||||
LOOP
|
||||
PERFORM _sysinternal.create_column_from_attribute(hypertable_row.name, att_row, 'meta_conn');
|
||||
END LOOP;
|
||||
END LOOP;
|
||||
|
||||
|
||||
PERFORM 1
|
||||
FROM pg_index,
|
||||
FROM pg_index,
|
||||
LATERAL dblink(
|
||||
'meta_conn',
|
||||
format('SELECT _meta.add_index(%L, %L,%L, %L, %L)',
|
||||
format('SELECT _meta.add_index(%L, %L,%L, %L, %L)',
|
||||
hypertable_row.name,
|
||||
hypertable_row.main_schema_name,
|
||||
(SELECT relname FROM pg_class WHERE oid = indexrelid::regclass),
|
||||
@ -71,7 +73,7 @@ BEGIN
|
||||
current_database()
|
||||
)) AS t(r TEXT)
|
||||
WHERE indrelid = main_table;
|
||||
|
||||
|
||||
PERFORM dblink_exec('meta_conn', 'COMMIT');
|
||||
PERFORM dblink_disconnect('meta_conn');
|
||||
RETURN hypertable_row;
|
||||
@ -98,19 +100,19 @@ DECLARE
|
||||
BEGIN
|
||||
SELECT relname, nspname
|
||||
INTO STRICT table_name, schema_name
|
||||
FROM pg_class c
|
||||
FROM pg_class c
|
||||
INNER JOIN pg_namespace n ON (n.OID = c.relnamespace)
|
||||
WHERE c.OID = main_table;
|
||||
|
||||
SELECT * INTO hypertable_row
|
||||
FROM hypertable h
|
||||
WHERE main_schema_name = schema_name AND
|
||||
WHERE main_schema_name = schema_name AND
|
||||
main_table_name = table_name;
|
||||
|
||||
PERFORM *
|
||||
FROM dblink(
|
||||
get_meta_server_name(),
|
||||
format('SELECT _meta.alter_column_set_is_distinct(%L, %L, %L, %L)',
|
||||
format('SELECT _meta.alter_column_set_is_distinct(%L, %L, %L, %L)',
|
||||
hypertable_row.name,
|
||||
field_name,
|
||||
is_distinct,
|
||||
|
@ -20,6 +20,8 @@ BEGIN
|
||||
END
|
||||
$BODY$;
|
||||
|
||||
-- Used to update a hypertable (or the insert temp table) when a new
|
||||
-- field is added.
|
||||
CREATE OR REPLACE FUNCTION _sysinternal.create_field_on_table(
|
||||
schema_name NAME,
|
||||
table_name NAME,
|
||||
@ -39,7 +41,7 @@ BEGIN
|
||||
IF NOT not_null THEN
|
||||
null_constraint = 'NULL';
|
||||
END IF;
|
||||
|
||||
|
||||
default_constraint = 'DEFAULT '|| default_value;
|
||||
|
||||
EXECUTE format(
|
||||
@ -48,14 +50,14 @@ BEGIN
|
||||
$$,
|
||||
schema_name, table_name, field, data_type_oid, default_constraint, null_constraint);
|
||||
|
||||
SELECT att.attnum INTO STRICT created_columns_att_num
|
||||
FROM pg_attribute att
|
||||
WHERE att.attrelid = format('%I.%I', schema_name, table_name)::regclass AND att.attname = field
|
||||
AND NOT attisdropped;
|
||||
SELECT att.attnum INTO STRICT created_columns_att_num
|
||||
FROM pg_attribute att
|
||||
WHERE att.attrelid = format('%I.%I', schema_name, table_name)::regclass AND att.attname = field
|
||||
AND NOT attisdropped;
|
||||
|
||||
IF created_columns_att_num IS DISTINCT FROM attnum THEN
|
||||
IF created_columns_att_num IS DISTINCT FROM attnum THEN
|
||||
RAISE EXCEPTION 'Inconsistent state: the attnum of newly created colum does not match (% vs %)', attnum, created_columns_att_num
|
||||
USING ERRCODE = 'IO501';
|
||||
USING ERRCODE = 'IO501';
|
||||
END IF;
|
||||
END
|
||||
$BODY$;
|
||||
@ -118,13 +120,13 @@ new_not_null BOOLEAN
|
||||
) RETURNS VOID LANGUAGE PLPGSQL VOLATILE AS
|
||||
$BODY$
|
||||
BEGIN
|
||||
IF new_not_null THEN
|
||||
IF new_not_null THEN
|
||||
EXECUTE format(
|
||||
$$
|
||||
ALTER TABLE %1$I.%2$I ALTER COLUMN %3$I SET NOT NULL
|
||||
$$,
|
||||
schema_name, table_name, field);
|
||||
ELSE
|
||||
ELSE
|
||||
EXECUTE format(
|
||||
$$
|
||||
ALTER TABLE %1$I.%2$I ALTER COLUMN %3$I DROP NOT NULL
|
||||
@ -143,14 +145,14 @@ DECLARE
|
||||
distinct_replica_node_row distinct_replica_node;
|
||||
chunk_replica_node_row chunk_replica_node;
|
||||
BEGIN
|
||||
FOR distinct_replica_node_row IN
|
||||
SELECT *
|
||||
FOR distinct_replica_node_row IN
|
||||
SELECT *
|
||||
FROM distinct_replica_node drn
|
||||
WHERE drn.hypertable_name = populate_distinct_table.hypertable_name AND
|
||||
drn.database_name = current_database()
|
||||
drn.database_name = current_database()
|
||||
LOOP
|
||||
FOR chunk_replica_node_row IN
|
||||
SELECT crn.*
|
||||
FOR chunk_replica_node_row IN
|
||||
SELECT crn.*
|
||||
FROM chunk_replica_node crn
|
||||
INNER JOIN partition_replica pr ON (pr.id = crn.partition_replica_id)
|
||||
WHERE pr.hypertable_name = distinct_replica_node_row.hypertable_name AND
|
||||
@ -180,14 +182,14 @@ $BODY$
|
||||
DECLARE
|
||||
distinct_replica_node_row distinct_replica_node;
|
||||
BEGIN
|
||||
FOR distinct_replica_node_row IN
|
||||
SELECT *
|
||||
FOR distinct_replica_node_row IN
|
||||
SELECT *
|
||||
FROM distinct_replica_node drn
|
||||
WHERE drn.hypertable_name = unpopulate_distinct_table.hypertable_name AND
|
||||
drn.database_name = current_database()
|
||||
drn.database_name = current_database()
|
||||
LOOP
|
||||
EXECUTE format($$
|
||||
DELETE FROM %I.%I WHERE field = %L
|
||||
DELETE FROM %I.%I WHERE field = %L
|
||||
$$,
|
||||
distinct_replica_node_row.schema_name, distinct_replica_node_row.table_name, field
|
||||
);
|
||||
@ -209,17 +211,23 @@ BEGIN
|
||||
FROM hypertable AS h
|
||||
WHERE h.name = NEW.hypertable_name;
|
||||
|
||||
-- update root table
|
||||
PERFORM _sysinternal.create_field_on_table(hypertable_row.root_schema_name, hypertable_row.root_table_name,
|
||||
NEW.name, NEW.attnum, NEW.data_type, NEW.default_value, NEW.not_null);
|
||||
IF new.created_on <> current_database() THEN
|
||||
PERFORM set_config('io.ignore_ddl_in_trigger', 'true', true);
|
||||
PERFORM _sysinternal.create_field_on_table(hypertable_row.main_schema_name, hypertable_row.main_table_name,
|
||||
-- update insert temp table
|
||||
PERFORM _sysinternal.create_field_on_table(hypertable_row.associated_schema_name, hypertable_row.insert_temp_table_name,
|
||||
NEW.name, NEW.attnum, NEW.data_type, NEW.default_value, NEW.not_null);
|
||||
|
||||
END IF;
|
||||
IF new.created_on <> current_database() THEN
|
||||
PERFORM set_config('io.ignore_ddl_in_trigger', 'true', true);
|
||||
-- update main table on others
|
||||
PERFORM _sysinternal.create_field_on_table(hypertable_row.main_schema_name, hypertable_row.main_table_name,
|
||||
NEW.name, NEW.attnum, NEW.data_type, NEW.default_value, NEW.not_null);
|
||||
END IF;
|
||||
|
||||
PERFORM _sysinternal.create_partition_constraint_for_field(NEW.hypertable_name, NEW.name);
|
||||
RETURN NEW;
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
ELSIF TG_OP = 'UPDATE' THEN
|
||||
SELECT *
|
||||
INTO STRICT hypertable_row
|
||||
FROM hypertable AS h
|
||||
@ -227,30 +235,46 @@ BEGIN
|
||||
|
||||
IF NEW.default_value IS DISTINCT FROM OLD.default_value THEN
|
||||
update_found = TRUE;
|
||||
-- update root table
|
||||
PERFORM _sysinternal.exec_alter_column_set_default(hypertable_row.root_schema_name, hypertable_row.root_table_name,
|
||||
NEW.name, NEW.default_value);
|
||||
-- update insert temp table
|
||||
PERFORM _sysinternal.exec_alter_column_set_default(hypertable_row.associated_schema_name, hypertable_row.insert_temp_table_name,
|
||||
NEW.name, NEW.default_value);
|
||||
|
||||
IF NEW.modified_on <> current_database() THEN
|
||||
PERFORM set_config('io.ignore_ddl_in_trigger', 'true', true);
|
||||
-- update main table on others
|
||||
PERFORM _sysinternal.exec_alter_column_set_default(hypertable_row.main_schema_name, hypertable_row.main_table_name,
|
||||
NEW.name, NEW.default_value);
|
||||
END IF;
|
||||
END IF;
|
||||
IF NEW.not_null IS DISTINCT FROM OLD.not_null THEN
|
||||
update_found = TRUE;
|
||||
-- update root table
|
||||
PERFORM _sysinternal.exec_alter_column_set_not_null(hypertable_row.root_schema_name, hypertable_row.root_table_name,
|
||||
NEW.name, NEW.not_null);
|
||||
-- update insert temp table
|
||||
PERFORM _sysinternal.exec_alter_column_set_not_null(hypertable_row.associated_schema_name, hypertable_row.insert_temp_table_name,
|
||||
NEW.name, NEW.not_null);
|
||||
IF NEW.modified_on <> current_database() THEN
|
||||
PERFORM set_config('io.ignore_ddl_in_trigger', 'true', true);
|
||||
-- update main table on others
|
||||
PERFORM _sysinternal.exec_alter_column_set_not_null(hypertable_row.main_schema_name, hypertable_row.main_table_name,
|
||||
NEW.name, NEW.not_null);
|
||||
END IF;
|
||||
END IF;
|
||||
IF NEW.name IS DISTINCT FROM OLD.name THEN
|
||||
update_found = TRUE;
|
||||
-- update root table
|
||||
PERFORM _sysinternal.exec_alter_table_rename_column(hypertable_row.root_schema_name, hypertable_row.root_table_name,
|
||||
OLD.name, NEW.name);
|
||||
-- update insert temp table
|
||||
PERFORM _sysinternal.exec_alter_table_rename_column(hypertable_row.associated_schema_name, hypertable_row.insert_temp_table_name,
|
||||
OLD.name, NEW.name);
|
||||
IF NEW.modified_on <> current_database() THEN
|
||||
PERFORM set_config('io.ignore_ddl_in_trigger', 'true', true);
|
||||
-- update main table on others
|
||||
PERFORM _sysinternal.exec_alter_table_rename_column(hypertable_row.main_schema_name, hypertable_row.main_table_name,
|
||||
OLD.name, NEW.name);
|
||||
END IF;
|
||||
@ -260,7 +284,7 @@ BEGIN
|
||||
update_found = TRUE;
|
||||
IF NEW.is_distinct THEN
|
||||
PERFORM _sysinternal.populate_distinct_table(NEW.hypertable_name, NEW.name);
|
||||
ELSE
|
||||
ELSE
|
||||
PERFORM _sysinternal.unpopulate_distinct_table(NEW.hypertable_name, NEW.name);
|
||||
END IF;
|
||||
END IF;
|
||||
@ -270,8 +294,8 @@ BEGIN
|
||||
USING ERRCODE = 'IO101';
|
||||
END IF;
|
||||
RETURN NEW;
|
||||
ELSIF TG_OP = 'DELETE' THEN
|
||||
--handled by deleted log
|
||||
ELSIF TG_OP = 'DELETE' THEN
|
||||
--handled by deleted log
|
||||
RETURN OLD;
|
||||
END IF;
|
||||
END
|
||||
@ -294,10 +318,16 @@ BEGIN
|
||||
FROM hypertable AS h
|
||||
WHERE h.name = NEW.hypertable_name;
|
||||
|
||||
-- update root table
|
||||
PERFORM _sysinternal.drop_field_on_table(hypertable_row.root_schema_name, hypertable_row.root_table_name,
|
||||
NEW.name);
|
||||
-- update insert temp table
|
||||
PERFORM _sysinternal.drop_field_on_table(hypertable_row.associated_schema_name, hypertable_row.insert_temp_table_name,
|
||||
NEW.name);
|
||||
|
||||
IF NEW.deleted_on <> current_database() THEN
|
||||
PERFORM set_config('io.ignore_ddl_in_trigger', 'true', true);
|
||||
-- update main table on others
|
||||
PERFORM _sysinternal.drop_field_on_table(hypertable_row.main_schema_name, hypertable_row.main_table_name,
|
||||
NEW.name);
|
||||
END IF;
|
||||
@ -306,4 +336,3 @@ BEGIN
|
||||
END
|
||||
$BODY$
|
||||
SET SEARCH_PATH = 'public';
|
||||
|
||||
|
@ -16,6 +16,7 @@ BEGIN
|
||||
|
||||
PERFORM _sysinternal.create_root_table(NEW.root_schema_name, NEW.root_table_name);
|
||||
PERFORM _sysinternal.create_root_distinct_table(NEW.distinct_schema_name, NEW.distinct_table_name);
|
||||
PERFORM _sysinternal.create_insert_temp_table(NEW.associated_schema_name, NEW.insert_temp_table_name);
|
||||
|
||||
IF NEW.created_on <> current_database() THEN
|
||||
PERFORM _sysinternal.create_main_table(NEW.main_schema_name, NEW.main_table_name);
|
||||
|
@ -41,6 +41,25 @@ BEGIN
|
||||
END
|
||||
$BODY$;
|
||||
|
||||
-- Creates the temporary table for INSERTs. INSERTs on the root table are
|
||||
-- redirected to the temporary table using a RULE. An associated trigger
|
||||
-- on this table then inserts all rows in bulk after all rows are INSERTed.
|
||||
-- The table is UNLOGGED for performance.
|
||||
CREATE OR REPLACE FUNCTION _sysinternal.create_insert_temp_table(
|
||||
schema_name NAME,
|
||||
table_name NAME
|
||||
)
|
||||
RETURNS VOID LANGUAGE PLPGSQL VOLATILE AS
|
||||
$BODY$
|
||||
BEGIN
|
||||
EXECUTE format(
|
||||
$$
|
||||
CREATE UNLOGGED TABLE IF NOT EXISTS %I.%I (
|
||||
)
|
||||
$$, schema_name, table_name);
|
||||
END
|
||||
$BODY$;
|
||||
|
||||
CREATE OR REPLACE FUNCTION _sysinternal.create_root_distinct_table(
|
||||
schema_name NAME,
|
||||
table_name NAME
|
||||
@ -197,7 +216,7 @@ BEGIN
|
||||
|
||||
EXECUTE format(
|
||||
$$
|
||||
ALTER TABLE %1$I.%2$I
|
||||
ALTER TABLE %1$I.%2$I
|
||||
ADD CONSTRAINT partition CHECK(%3$s(%4$I::text, %5$L) BETWEEN %6$L AND %7$L)
|
||||
$$,
|
||||
schema_name, table_name,
|
||||
@ -244,5 +263,3 @@ BEGIN
|
||||
END IF;
|
||||
END
|
||||
$BODY$;
|
||||
|
||||
|
||||
|
@ -54,7 +54,6 @@ BEGIN
|
||||
END
|
||||
$BODY$;
|
||||
|
||||
|
||||
CREATE OR REPLACE FUNCTION add_partition_epoch(
|
||||
hypertable_name NAME,
|
||||
keyspace_start SMALLINT [],
|
||||
@ -90,5 +89,3 @@ SELECT add_partition_epoch(
|
||||
partitioning_field
|
||||
)
|
||||
$BODY$;
|
||||
|
||||
|
||||
|
@ -13,6 +13,7 @@ CREATE OR REPLACE FUNCTION _meta.add_hypertable(
|
||||
number_partitions SMALLINT,
|
||||
associated_schema_name NAME,
|
||||
associated_table_prefix NAME,
|
||||
insert_temp_table_name NAME,
|
||||
hypertable_name NAME,
|
||||
placement chunk_placement_type,
|
||||
created_on NAME
|
||||
@ -34,6 +35,10 @@ BEGIN
|
||||
associated_table_prefix = format('_hyper_%s', id);
|
||||
END IF;
|
||||
|
||||
IF insert_temp_table_name IS NULL THEN
|
||||
insert_temp_table_name = format('_hyper_%s_insert_temp', id);
|
||||
END IF;
|
||||
|
||||
IF number_partitions IS NULL THEN
|
||||
SELECT COUNT(*)
|
||||
INTO number_partitions
|
||||
@ -50,8 +55,9 @@ BEGIN
|
||||
associated_schema_name, associated_table_prefix,
|
||||
root_schema_name, root_table_name,
|
||||
distinct_schema_name, distinct_table_name,
|
||||
insert_temp_table_name,
|
||||
replication_factor,
|
||||
placement,
|
||||
placement,
|
||||
time_field_name, time_field_type,
|
||||
created_on)
|
||||
VALUES (
|
||||
@ -60,7 +66,8 @@ BEGIN
|
||||
associated_schema_name, associated_table_prefix,
|
||||
associated_schema_name, format('%s_root', associated_table_prefix),
|
||||
associated_schema_name, format('%s_distinct', associated_table_prefix),
|
||||
replication_factor,
|
||||
insert_temp_table_name,
|
||||
replication_factor,
|
||||
placement,
|
||||
time_field_name, time_field_type,
|
||||
created_on
|
||||
@ -103,8 +110,8 @@ CREATE OR REPLACE FUNCTION _meta.drop_field(
|
||||
RETURNS VOID LANGUAGE SQL VOLATILE AS
|
||||
$BODY$
|
||||
SELECT set_config('io.deleting_node', modified_on, true);
|
||||
DELETE FROM field f
|
||||
WHERE f.hypertable_name = drop_field.hypertable_name AND f.NAME = field_name;
|
||||
DELETE FROM field f
|
||||
WHERE f.hypertable_name = drop_field.hypertable_name AND f.NAME = field_name;
|
||||
$BODY$;
|
||||
|
||||
--Sets the is_distinct flag for a field on a hypertable.
|
||||
@ -116,9 +123,9 @@ CREATE OR REPLACE FUNCTION _meta.alter_column_set_is_distinct(
|
||||
)
|
||||
RETURNS VOID LANGUAGE SQL VOLATILE AS
|
||||
$BODY$
|
||||
UPDATE field
|
||||
SET is_distinct = new_is_distinct, modified_on = modified_on_node
|
||||
WHERE hypertable_name = alter_column_set_is_distinct.hypertable_name AND name = field_name;
|
||||
UPDATE field
|
||||
SET is_distinct = new_is_distinct, modified_on = modified_on_node
|
||||
WHERE hypertable_name = alter_column_set_is_distinct.hypertable_name AND name = field_name;
|
||||
$BODY$;
|
||||
|
||||
--Sets the default for a column on a hypertable.
|
||||
@ -130,9 +137,9 @@ CREATE OR REPLACE FUNCTION _meta.alter_column_set_default(
|
||||
)
|
||||
RETURNS VOID LANGUAGE SQL VOLATILE AS
|
||||
$BODY$
|
||||
UPDATE field
|
||||
SET default_value = new_default_value, modified_on = modified_on_node
|
||||
WHERE hypertable_name = alter_column_set_default.hypertable_name AND name = field_name;
|
||||
UPDATE field
|
||||
SET default_value = new_default_value, modified_on = modified_on_node
|
||||
WHERE hypertable_name = alter_column_set_default.hypertable_name AND name = field_name;
|
||||
$BODY$;
|
||||
|
||||
--Sets the not null flag for a column on a hypertable.
|
||||
@ -144,9 +151,9 @@ CREATE OR REPLACE FUNCTION _meta.alter_column_set_not_null(
|
||||
)
|
||||
RETURNS VOID LANGUAGE SQL VOLATILE AS
|
||||
$BODY$
|
||||
UPDATE field
|
||||
SET not_null = new_not_null, modified_on = modified_on_node
|
||||
WHERE hypertable_name = alter_column_set_not_null.hypertable_name AND name = field_name;
|
||||
UPDATE field
|
||||
SET not_null = new_not_null, modified_on = modified_on_node
|
||||
WHERE hypertable_name = alter_column_set_not_null.hypertable_name AND name = field_name;
|
||||
$BODY$;
|
||||
|
||||
--Renames the column on a hypertable
|
||||
@ -158,9 +165,9 @@ CREATE OR REPLACE FUNCTION _meta.alter_table_rename_column(
|
||||
)
|
||||
RETURNS VOID LANGUAGE SQL VOLATILE AS
|
||||
$BODY$
|
||||
UPDATE field
|
||||
SET NAME = new_field_name, modified_on = modified_on_node
|
||||
WHERE hypertable_name = alter_table_rename_column.hypertable_name AND name = old_field_name;
|
||||
UPDATE field
|
||||
SET NAME = new_field_name, modified_on = modified_on_node
|
||||
WHERE hypertable_name = alter_table_rename_column.hypertable_name AND name = old_field_name;
|
||||
$BODY$;
|
||||
|
||||
--Add an index to a hypertable
|
||||
@ -180,7 +187,7 @@ $BODY$;
|
||||
|
||||
--Drops the index for a hypertable
|
||||
CREATE OR REPLACE FUNCTION _meta.drop_index(
|
||||
main_schema_name NAME,
|
||||
main_schema_name NAME,
|
||||
main_index_name NAME,
|
||||
modified_on NAME
|
||||
)
|
||||
@ -188,6 +195,5 @@ CREATE OR REPLACE FUNCTION _meta.drop_index(
|
||||
$BODY$
|
||||
SELECT set_config('io.deleting_node', modified_on, true);
|
||||
DELETE FROM hypertable_index i
|
||||
WHERE i.main_index_name = drop_index.main_index_name AND i.main_schema_name = drop_index.main_schema_name;
|
||||
WHERE i.main_index_name = drop_index.main_index_name AND i.main_schema_name = drop_index.main_schema_name;
|
||||
$BODY$;
|
||||
|
||||
|
@ -52,9 +52,9 @@ CREATE INDEX ON PUBLIC."testNs" (temp, time DESC NULLS LAST) WHERE temp IS NOT N
|
||||
CREATE INDEX ON PUBLIC."testNs" (really_long_field_goes_on_and_on_and_on_and_on_and_on_and_on_and_on_and_on, time DESC NULLS LAST) WHERE really_long_field_goes_on_and_on_and_on_and_on_and_on_and_on_and_on_and_on IS NOT NULL;
|
||||
CREATE INDEX ON PUBLIC."testNs" (time DESC NULLS LAST, really_long_field_goes_on_and_on_and_on_and_on_and_on_and_on_and_on_and_on) WHERE really_long_field_goes_on_and_on_and_on_and_on_and_on_and_on_and_on_and_on IS NOT NULL;
|
||||
SELECT * FROM add_hypertable('"public"."testNs"', 'time', 'Device_id', hypertable_name=>'testNs');
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
testNs | public | testNs | _sys_1_testNs | _hyper_1 | _sys_1_testNs | _hyper_1_root | _sys_1_testNs | _hyper_1_distinct | 1 | STICKY | time | bigint | Test1
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | insert_temp_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+------------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
testNs | public | testNs | _sys_1_testNs | _hyper_1 | _sys_1_testNs | _hyper_1_root | _sys_1_testNs | _hyper_1_distinct | _hyper_1_insert_temp | 1 | STICKY | time | bigint | Test1
|
||||
(1 row)
|
||||
|
||||
SELECT set_is_distinct_flag('"public"."testNs"', 'Device_id', TRUE);
|
||||
@ -96,9 +96,9 @@ FROM meta;
|
||||
|
||||
SELECT *
|
||||
FROM hypertable;
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
testNs | public | testNs | _sys_1_testNs | _hyper_1 | _sys_1_testNs | _hyper_1_root | _sys_1_testNs | _hyper_1_distinct | 1 | STICKY | time | bigint | Test1
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | insert_temp_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+------------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
testNs | public | testNs | _sys_1_testNs | _hyper_1 | _sys_1_testNs | _hyper_1_root | _sys_1_testNs | _hyper_1_distinct | _hyper_1_insert_temp | 1 | STICKY | time | bigint | Test1
|
||||
(1 row)
|
||||
|
||||
SELECT *
|
||||
@ -200,9 +200,9 @@ FROM meta;
|
||||
|
||||
SELECT *
|
||||
FROM hypertable;
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
testNs | public | testNs | _sys_1_testNs | _hyper_1 | _sys_1_testNs | _hyper_1_root | _sys_1_testNs | _hyper_1_distinct | 1 | STICKY | time | bigint | Test1
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | insert_temp_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+------------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
testNs | public | testNs | _sys_1_testNs | _hyper_1 | _sys_1_testNs | _hyper_1_root | _sys_1_testNs | _hyper_1_distinct | _hyper_1_insert_temp | 1 | STICKY | time | bigint | Test1
|
||||
(1 row)
|
||||
|
||||
SELECT *
|
||||
@ -411,6 +411,16 @@ Index "_sys_1_testNs._hyper_1_distinct_pkey"
|
||||
value | text | value | extended
|
||||
primary key, btree, for table "_sys_1_testNs._hyper_1_distinct"
|
||||
|
||||
Unlogged table "_sys_1_testNs._hyper_1_insert_temp"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-----------------------------------------------------------------+------------------+-----------+----------+--------------+-------------
|
||||
time | bigint | not null | plain | |
|
||||
Device_id | text | not null | extended | |
|
||||
temp | double precision | | plain | |
|
||||
occupied | boolean | | plain | |
|
||||
latitude | bigint | | plain | |
|
||||
really_long_field_goes_on_and_on_and_on_and_on_and_on_and_on_an | bigint | | plain | |
|
||||
|
||||
Table "_sys_1_testNs._hyper_1_root"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-----------------------------------------------------------------+------------------+-----------+----------+--------------+-------------
|
||||
@ -563,6 +573,16 @@ Index "_sys_1_testNs._hyper_1_distinct_pkey"
|
||||
value | text | value | extended
|
||||
primary key, btree, for table "_sys_1_testNs._hyper_1_distinct"
|
||||
|
||||
Unlogged table "_sys_1_testNs._hyper_1_insert_temp"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-----------------------------------------------------------------+------------------+-----------+----------+--------------+-------------
|
||||
time | bigint | not null | plain | |
|
||||
Device_id | text | not null | extended | |
|
||||
temp | double precision | | plain | |
|
||||
occupied | boolean | | plain | |
|
||||
latitude | bigint | | plain | |
|
||||
really_long_field_goes_on_and_on_and_on_and_on_and_on_and_on_an | bigint | | plain | |
|
||||
|
||||
Table "_sys_1_testNs._hyper_1_root"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-----------------------------------------------------------------+------------------+-----------+----------+--------------+-------------
|
||||
@ -787,6 +807,16 @@ Index "_sys_1_testNs._hyper_1_distinct_pkey"
|
||||
value | text | value | extended
|
||||
primary key, btree, for table "_sys_1_testNs._hyper_1_distinct"
|
||||
|
||||
Unlogged table "_sys_1_testNs._hyper_1_insert_temp"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-----------------------------------------------------------------+------------------+-----------+----------+--------------+-------------
|
||||
time | bigint | not null | plain | |
|
||||
Device_id | text | not null | extended | |
|
||||
temp | double precision | | plain | |
|
||||
occupied | boolean | | plain | |
|
||||
latitude | bigint | | plain | |
|
||||
really_long_field_goes_on_and_on_and_on_and_on_and_on_and_on_an | bigint | | plain | |
|
||||
|
||||
Table "_sys_1_testNs._hyper_1_root"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-----------------------------------------------------------------+------------------+-----------+----------+--------------+-------------
|
||||
|
@ -51,15 +51,15 @@ CREATE TABLE PUBLIC."Hypertable_1" (
|
||||
);
|
||||
CREATE INDEX ON PUBLIC."Hypertable_1" (time, "Device_id");
|
||||
SELECT * FROM add_hypertable('"public"."Hypertable_1"', 'time', 'Device_id');
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
-----------------------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
public."Hypertable_1" | public | Hypertable_1 | _sys_1_ | _hyper_1 | _sys_1_ | _hyper_1_root | _sys_1_ | _hyper_1_distinct | 1 | STICKY | time | bigint | Test1
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | insert_temp_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
-----------------------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+------------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
public."Hypertable_1" | public | Hypertable_1 | _sys_1_ | _hyper_1 | _sys_1_ | _hyper_1_root | _sys_1_ | _hyper_1_distinct | _hyper_1_insert_temp | 1 | STICKY | time | bigint | Test1
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM hypertable;
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
-----------------------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
public."Hypertable_1" | public | Hypertable_1 | _sys_1_ | _hyper_1 | _sys_1_ | _hyper_1_root | _sys_1_ | _hyper_1_distinct | 1 | STICKY | time | bigint | Test1
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | insert_temp_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
-----------------------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+------------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
public."Hypertable_1" | public | Hypertable_1 | _sys_1_ | _hyper_1 | _sys_1_ | _hyper_1_root | _sys_1_ | _hyper_1_distinct | _hyper_1_insert_temp | 1 | STICKY | time | bigint | Test1
|
||||
(1 row)
|
||||
|
||||
SELECT * FROM hypertable_index;
|
||||
|
@ -53,9 +53,9 @@ CREATE INDEX ON PUBLIC."testNs" (time DESC NULLS LAST, series_1) WHERE series_1
|
||||
CREATE INDEX ON PUBLIC."testNs" (time DESC NULLS LAST, series_2) WHERE series_2 IS NOT NULL;
|
||||
CREATE INDEX ON PUBLIC."testNs" (time DESC NULLS LAST, series_bool) WHERE series_bool IS NOT NULL;
|
||||
SELECT * FROM add_hypertable('"public"."testNs"', 'time', 'device_id', hypertable_name=>'testNs', associated_schema_name=>'testNs' );
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
testNs | public | testNs | testNs | _hyper_1 | testNs | _hyper_1_root | testNs | _hyper_1_distinct | 1 | STICKY | time | bigint | Test1
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | insert_temp_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+------------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
testNs | public | testNs | testNs | _hyper_1 | testNs | _hyper_1_root | testNs | _hyper_1_distinct | _hyper_1_insert_temp | 1 | STICKY | time | bigint | Test1
|
||||
(1 row)
|
||||
|
||||
SELECT set_is_distinct_flag('"public"."testNs"', 'device_id', TRUE);
|
||||
@ -319,6 +319,16 @@ Child tables: "testNs"._hyper_1_0_distinct
|
||||
value | text | value | extended
|
||||
primary key, btree, for table "testNs._hyper_1_distinct"
|
||||
|
||||
Unlogged table "testNs._hyper_1_insert_temp"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-------------+------------------+-----------+----------+--------------+-------------
|
||||
time | bigint | not null | plain | |
|
||||
device_id | text | not null | extended | |
|
||||
series_0 | double precision | | plain | |
|
||||
series_1 | double precision | | plain | |
|
||||
series_2 | double precision | | plain | |
|
||||
series_bool | boolean | | plain | |
|
||||
|
||||
Table "testNs._hyper_1_root"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-------------+------------------+-----------+----------+--------------+-------------
|
||||
@ -438,6 +448,16 @@ Child tables: "testNs"._hyper_1_0_distinct
|
||||
value | text | value | extended
|
||||
primary key, btree, for table "testNs._hyper_1_distinct"
|
||||
|
||||
Unlogged table "testNs._hyper_1_insert_temp"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-------------+------------------+-----------+----------+--------------+-------------
|
||||
time | bigint | not null | plain | |
|
||||
device_id | text | not null | extended | |
|
||||
series_0 | double precision | | plain | |
|
||||
series_1 | double precision | | plain | |
|
||||
series_2 | double precision | | plain | |
|
||||
series_bool | boolean | | plain | |
|
||||
|
||||
Table "testNs._hyper_1_root"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-------------+------------------+-----------+----------+--------------+-------------
|
||||
|
@ -53,9 +53,9 @@ CREATE INDEX ON PUBLIC."testNs" (time DESC NULLS LAST, series_1) WHERE series_1
|
||||
CREATE INDEX ON PUBLIC."testNs" (time DESC NULLS LAST, series_2) WHERE series_2 IS NOT NULL;
|
||||
CREATE INDEX ON PUBLIC."testNs" (time DESC NULLS LAST, series_bool) WHERE series_bool IS NOT NULL;
|
||||
SELECT * FROM add_hypertable('"public"."testNs"', 'time', 'device_id', hypertable_name=>'testNs', associated_schema_name=>'testNs' );
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
testNs | public | testNs | testNs | _hyper_1 | testNs | _hyper_1_root | testNs | _hyper_1_distinct | 1 | STICKY | time | bigint | Test1
|
||||
name | main_schema_name | main_table_name | associated_schema_name | associated_table_prefix | root_schema_name | root_table_name | distinct_schema_name | distinct_table_name | insert_temp_table_name | replication_factor | placement | time_field_name | time_field_type | created_on
|
||||
--------+------------------+-----------------+------------------------+-------------------------+------------------+-----------------+----------------------+---------------------+------------------------+--------------------+-----------+-----------------+-----------------+------------
|
||||
testNs | public | testNs | testNs | _hyper_1 | testNs | _hyper_1_root | testNs | _hyper_1_distinct | _hyper_1_insert_temp | 1 | STICKY | time | bigint | Test1
|
||||
(1 row)
|
||||
|
||||
SELECT set_is_distinct_flag('"public"."testNs"', 'device_id', TRUE);
|
||||
@ -319,6 +319,16 @@ Child tables: "testNs"._hyper_1_0_distinct
|
||||
value | text | value | extended
|
||||
primary key, btree, for table "testNs._hyper_1_distinct"
|
||||
|
||||
Unlogged table "testNs._hyper_1_insert_temp"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-------------+------------------+-----------+----------+--------------+-------------
|
||||
time | bigint | not null | plain | |
|
||||
device_id | text | not null | extended | |
|
||||
series_0 | double precision | | plain | |
|
||||
series_1 | double precision | | plain | |
|
||||
series_2 | double precision | | plain | |
|
||||
series_bool | boolean | | plain | |
|
||||
|
||||
Table "testNs._hyper_1_root"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-------------+------------------+-----------+----------+--------------+-------------
|
||||
@ -438,6 +448,16 @@ Child tables: "testNs"._hyper_1_0_distinct
|
||||
value | text | value | extended
|
||||
primary key, btree, for table "testNs._hyper_1_distinct"
|
||||
|
||||
Unlogged table "testNs._hyper_1_insert_temp"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-------------+------------------+-----------+----------+--------------+-------------
|
||||
time | bigint | not null | plain | |
|
||||
device_id | text | not null | extended | |
|
||||
series_0 | double precision | | plain | |
|
||||
series_1 | double precision | | plain | |
|
||||
series_2 | double precision | | plain | |
|
||||
series_bool | boolean | | plain | |
|
||||
|
||||
Table "testNs._hyper_1_root"
|
||||
Column | Type | Modifiers | Storage | Stats target | Description
|
||||
-------------+------------------+-----------+----------+--------------+-------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user