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