timescaledb/sql/main/chunk_replica_node_index.sql
Matvey Arye 42ee7c8586 starting refactor of clustering and naming logic
This fix allows more flexible placement of tables on a node; better
and more flexible logic for remote placement of chunks on nodes.
2016-11-22 16:41:27 -05:00

28 lines
876 B
PL/PgSQL

CREATE OR REPLACE FUNCTION _sysinternal.create_chunk_replica_node_index(
schema_name NAME,
table_name NAME,
field_name NAME,
index_type field_index_type
)
RETURNS VOID LANGUAGE PLPGSQL AS
$BODY$
DECLARE
index_name NAME;
prefix BIGINT;
BEGIN
prefix = nextval('chunk_replica_node_index_name_prefix');
IF index_type = 'TIME-VALUE' THEN
index_name := format('%s-time-%s', prefix, field_name);
ELSIF index_type = 'VALUE-TIME' THEN
index_name := format('%s-%s-time', prefix, field_name);
ELSE
RAISE EXCEPTION 'Unknown index type %', index_type
USING ERRCODE = 'IO103';
END IF;
INSERT INTO chunk_replica_node_index (schema_name, table_name, field_name, index_name, index_type) VALUES
(schema_name, table_name, field_name, index_name, index_type)
ON CONFLICT DO NOTHING;
END
$BODY$;