timescale / timescaledb

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.
https://www.timescale.com/
Other
17.9k stars 882 forks source link

Error creating primary key with many columns on existing hypertable #1131

Closed xvaara closed 5 years ago

xvaara commented 5 years ago

Relevant system information:

Describe the bug Was testing different primary key combinations for benchmarking. And noticed this when changing primary key.

It works if the primary key is created before create_hypertable.

ALTER TABLE data_cache ADD PRIMARY KEY (project_id, slot, "time",series_id);
ERROR:  hypertables do not support this operation: parsetree {INDEXSTMT :idxname <> :relation {RANGEVAR :schemaname <> :relname data_cache :inh true :relpersistence p :alias <> :location 12} :relationId 0 :accessMethod btree :tableSpace <> :indexParams ({INDEXELEM :name project_id :expr <> :indexcolname <> :collation <> :opclass <> :ordering 0 :nulls_ordering 0} {INDEXELEM :name slot :expr <> :indexcolname <> :collation <> :opclass <> :ordering 0 :nulls_ordering 0} {INDEXELEM :name time :expr <> :indexcolname <> :collation <> :opclass <> :ordering 0 :nulls_ordering 0} {INDEXELEM :name series_id :expr <> :indexcolname <> :collation <> :opclass <> :ordering 0 :nulls_ordering 0}) :indexIncludingParams <> :options <> :whereClause <> :excludeOpNames <> :idxcomment <> :indexOid 0 :oldNode 0 :unique true :primary true :isconstraint true :deferrable false :initdeferred false :transformed true :concurrent false :if_not_exists false}, type 1

To Reproduce Steps to reproduce the behavior:

drop table if exists data_cache_test;

CREATE TABLE data_cache_test (
    "time" timestamp with time zone NOT NULL,
    project_id int,
    slot int,
    series_id int,
    avg real,
    FOREIGN KEY (project_id) REFERENCES project(id)
);

SELECT create_hypertable('data_cache_test', 'time', create_default_indexes => false);

ALTER TABLE data_cache_test ADD PRIMARY KEY (project_id, slot, "time",series_id);

Expected behavior Primary key created.

Actual behavior Error.

svenklemm commented 5 years ago

@xvaara cannot reproduce on 1.3.0, feel free to reopen if you can reproduce on 1.3+