mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-16 02:23:49 +08:00
Merge test files that after the removal of PG11 support need to be no longer version specific.
405 lines
28 KiB
Plaintext
405 lines
28 KiB
Plaintext
-- This file and its contents are licensed under the Apache License 2.0.
|
|
-- Please see the included NOTICE for copyright information and
|
|
-- LICENSE-APACHE for a copy of the license.
|
|
CREATE TABLE index_test(id serial, time timestamptz, device integer, temp float);
|
|
SELECT * FROM test.show_columns('index_test');
|
|
Column | Type | NotNull
|
|
--------+--------------------------+---------
|
|
id | integer | t
|
|
time | timestamp with time zone | f
|
|
device | integer | f
|
|
temp | double precision | f
|
|
(4 rows)
|
|
|
|
-- Test that we can handle difference in attnos across hypertable and
|
|
-- chunks by dropping the ID column
|
|
ALTER TABLE index_test DROP COLUMN id;
|
|
SELECT * FROM test.show_columns('index_test');
|
|
Column | Type | NotNull
|
|
--------+--------------------------+---------
|
|
time | timestamp with time zone | f
|
|
device | integer | f
|
|
temp | double precision | f
|
|
(3 rows)
|
|
|
|
-- No pre-existing UNIQUE index, so partitioning on two columns should work
|
|
SELECT create_hypertable('index_test', 'time', 'device', 2);
|
|
NOTICE: adding not-null constraint to column "time"
|
|
create_hypertable
|
|
-------------------------
|
|
(1,public,index_test,t)
|
|
(1 row)
|
|
|
|
INSERT INTO index_test VALUES ('2017-01-20T09:00:01', 1, 17.5);
|
|
\set ON_ERROR_STOP 0
|
|
-- cannot create a UNIQUE index with transaction_per_chunk
|
|
CREATE UNIQUE INDEX index_test_time_device_idx ON index_test (time) WITH (timescaledb.transaction_per_chunk);
|
|
ERROR: cannot use timescaledb.transaction_per_chunk with UNIQUE or PRIMARY KEY
|
|
CREATE UNIQUE INDEX index_test_time_device_idx ON index_test (time, device) WITH(timescaledb.transaction_per_chunk);
|
|
ERROR: cannot use timescaledb.transaction_per_chunk with UNIQUE or PRIMARY KEY
|
|
\set ON_ERROR_STOP 1
|
|
CREATE INDEX index_test_time_device_idx ON index_test (time, device) WITH (timescaledb.transaction_per_chunk);
|
|
-- Regular index need not cover all partitioning columns
|
|
CREATE INDEX ON index_test (time, temp) WITH (timescaledb.transaction_per_chunk);
|
|
-- Create another chunk
|
|
INSERT INTO index_test VALUES ('2017-04-20T09:00:01', 1, 17.5);
|
|
-- New index should have been recursed to chunks
|
|
SELECT * FROM test.show_indexes('index_test');
|
|
Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------+---------------+------+--------+---------+-----------+------------
|
|
index_test_device_time_idx | {device,time} | | f | f | f |
|
|
index_test_time_device_idx | {time,device} | | f | f | f |
|
|
index_test_time_idx | {time} | | f | f | f |
|
|
index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(4 rows)
|
|
|
|
SELECT * FROM test.show_indexesp('_timescaledb_internal._hyper%_chunk') ORDER BY 1,2;
|
|
Table | Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------------------+-------------------------------------------------------------------+---------------+------+--------+---------+-----------+------------
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_time_idx | {time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_time_device_idx | {time,device} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_time_idx | {time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_time_device_idx | {time,device} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(8 rows)
|
|
|
|
SELECT * FROM _timescaledb_catalog.chunk_index ORDER BY index_name;
|
|
chunk_id | index_name | hypertable_id | hypertable_index_name
|
|
----------+---------------------------------------------+---------------+----------------------------
|
|
1 | _hyper_1_1_chunk_index_test_device_time_idx | 1 | index_test_device_time_idx
|
|
1 | _hyper_1_1_chunk_index_test_time_device_idx | 1 | index_test_time_device_idx
|
|
1 | _hyper_1_1_chunk_index_test_time_idx | 1 | index_test_time_idx
|
|
1 | _hyper_1_1_chunk_index_test_time_temp_idx | 1 | index_test_time_temp_idx
|
|
2 | _hyper_1_2_chunk_index_test_device_time_idx | 1 | index_test_device_time_idx
|
|
2 | _hyper_1_2_chunk_index_test_time_device_idx | 1 | index_test_time_device_idx
|
|
2 | _hyper_1_2_chunk_index_test_time_idx | 1 | index_test_time_idx
|
|
2 | _hyper_1_2_chunk_index_test_time_temp_idx | 1 | index_test_time_temp_idx
|
|
(8 rows)
|
|
|
|
ALTER INDEX index_test_time_idx RENAME TO index_test_time_idx2;
|
|
-- Metadata and index should have changed name
|
|
SELECT * FROM test.show_indexes('index_test');
|
|
Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------+---------------+------+--------+---------+-----------+------------
|
|
index_test_device_time_idx | {device,time} | | f | f | f |
|
|
index_test_time_device_idx | {time,device} | | f | f | f |
|
|
index_test_time_idx2 | {time} | | f | f | f |
|
|
index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(4 rows)
|
|
|
|
SELECT * FROM test.show_indexesp('_timescaledb_internal._hyper%_chunk') ORDER BY 1,2;
|
|
Table | Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------------------+-------------------------------------------------------------------+---------------+------+--------+---------+-----------+------------
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_time_idx2 | {time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_time_device_idx | {time,device} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_time_idx2 | {time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_time_device_idx | {time,device} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(8 rows)
|
|
|
|
SELECT * FROM _timescaledb_catalog.chunk_index ORDER BY index_name;
|
|
chunk_id | index_name | hypertable_id | hypertable_index_name
|
|
----------+---------------------------------------------+---------------+----------------------------
|
|
1 | _hyper_1_1_chunk_index_test_device_time_idx | 1 | index_test_device_time_idx
|
|
1 | _hyper_1_1_chunk_index_test_time_device_idx | 1 | index_test_time_device_idx
|
|
1 | _hyper_1_1_chunk_index_test_time_idx2 | 1 | index_test_time_idx2
|
|
1 | _hyper_1_1_chunk_index_test_time_temp_idx | 1 | index_test_time_temp_idx
|
|
2 | _hyper_1_2_chunk_index_test_device_time_idx | 1 | index_test_device_time_idx
|
|
2 | _hyper_1_2_chunk_index_test_time_device_idx | 1 | index_test_time_device_idx
|
|
2 | _hyper_1_2_chunk_index_test_time_idx2 | 1 | index_test_time_idx2
|
|
2 | _hyper_1_2_chunk_index_test_time_temp_idx | 1 | index_test_time_temp_idx
|
|
(8 rows)
|
|
|
|
DROP INDEX index_test_time_idx2;
|
|
DROP INDEX index_test_time_device_idx;
|
|
-- Index should have been dropped
|
|
SELECT * FROM test.show_indexes('index_test');
|
|
Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------+---------------+------+--------+---------+-----------+------------
|
|
index_test_device_time_idx | {device,time} | | f | f | f |
|
|
index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(2 rows)
|
|
|
|
SELECT * FROM test.show_indexesp('_timescaledb_internal._hyper%_chunk');
|
|
Table | Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------------------+-------------------------------------------------------------------+---------------+------+--------+---------+-----------+------------
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(4 rows)
|
|
|
|
SELECT * FROM _timescaledb_catalog.chunk_index;
|
|
chunk_id | index_name | hypertable_id | hypertable_index_name
|
|
----------+---------------------------------------------+---------------+----------------------------
|
|
1 | _hyper_1_1_chunk_index_test_device_time_idx | 1 | index_test_device_time_idx
|
|
1 | _hyper_1_1_chunk_index_test_time_temp_idx | 1 | index_test_time_temp_idx
|
|
2 | _hyper_1_2_chunk_index_test_device_time_idx | 1 | index_test_device_time_idx
|
|
2 | _hyper_1_2_chunk_index_test_time_temp_idx | 1 | index_test_time_temp_idx
|
|
(4 rows)
|
|
|
|
-- Create index with long name to see how this is handled on chunks
|
|
CREATE INDEX a_hypertable_index_with_a_very_very_long_name_that_truncates ON index_test (time, temp) WITH (timescaledb.transaction_per_chunk);
|
|
CREATE INDEX a_hypertable_index_with_a_very_very_long_name_that_truncates_2 ON index_test (time, temp) WITH (timescaledb.transaction_per_chunk);
|
|
SELECT * FROM test.show_indexes('index_test');
|
|
Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------------------------------------------+---------------+------+--------+---------+-----------+------------
|
|
a_hypertable_index_with_a_very_very_long_name_that_truncates | {time,temp} | | f | f | f |
|
|
a_hypertable_index_with_a_very_very_long_name_that_truncates_2 | {time,temp} | | f | f | f |
|
|
index_test_device_time_idx | {device,time} | | f | f | f |
|
|
index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(4 rows)
|
|
|
|
SELECT * FROM test.show_indexesp('_timescaledb_internal._hyper%_chunk');
|
|
Table | Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------------------+---------------------------------------------------------------------------------------+---------------+------+--------+---------+-----------+------------
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_a_hypertable_index_with_a_very_very_long_name_ | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_a_hypertable_index_with_a_very_very_long_nam_1 | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_a_hypertable_index_with_a_very_very_long_name_ | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_a_hypertable_index_with_a_very_very_long_nam_1 | {time,temp} | | f | f | f |
|
|
(8 rows)
|
|
|
|
DROP INDEX a_hypertable_index_with_a_very_very_long_name_that_truncates;
|
|
DROP INDEX a_hypertable_index_with_a_very_very_long_name_that_truncates_2;
|
|
SELECT * FROM test.show_indexes('index_test');
|
|
Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------+---------------+------+--------+---------+-----------+------------
|
|
index_test_device_time_idx | {device,time} | | f | f | f |
|
|
index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(2 rows)
|
|
|
|
SELECT * FROM test.show_indexesp('_timescaledb_internal._hyper%_chunk');
|
|
Table | Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------------------+-------------------------------------------------------------------+---------------+------+--------+---------+-----------+------------
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(4 rows)
|
|
|
|
SELECT * FROM test.show_indexes('index_test');
|
|
Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------+---------------+------+--------+---------+-----------+------------
|
|
index_test_device_time_idx | {device,time} | | f | f | f |
|
|
index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(2 rows)
|
|
|
|
SELECT * FROM test.show_indexesp('_timescaledb_internal._hyper%_chunk');
|
|
Table | Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------------------+-------------------------------------------------------------------+---------------+------+--------+---------+-----------+------------
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(4 rows)
|
|
|
|
-- Add constraint index
|
|
ALTER TABLE index_test ADD UNIQUE (time, device);
|
|
SELECT * FROM test.show_indexes('index_test');
|
|
Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------+---------------+------+--------+---------+-----------+------------
|
|
index_test_device_time_idx | {device,time} | | f | f | f |
|
|
index_test_time_device_key | {time,device} | | t | f | f |
|
|
index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
(3 rows)
|
|
|
|
SELECT * FROM test.show_indexesp('_timescaledb_internal._hyper%_chunk');
|
|
Table | Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------------------+-------------------------------------------------------------------+---------------+------+--------+---------+-----------+------------
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal._hyper_1_1_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_1_chunk | _timescaledb_internal."1_1_index_test_time_device_key" | {time,device} | | t | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_device_time_idx | {device,time} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal._hyper_1_2_chunk_index_test_time_temp_idx | {time,temp} | | f | f | f |
|
|
_timescaledb_internal._hyper_1_2_chunk | _timescaledb_internal."2_2_index_test_time_device_key" | {time,device} | | t | f | f |
|
|
(6 rows)
|
|
|
|
-- Constraint indexes are added to chunk_index table.
|
|
SELECT * FROM _timescaledb_catalog.chunk_index;
|
|
chunk_id | index_name | hypertable_id | hypertable_index_name
|
|
----------+---------------------------------------------+---------------+----------------------------
|
|
1 | _hyper_1_1_chunk_index_test_device_time_idx | 1 | index_test_device_time_idx
|
|
1 | _hyper_1_1_chunk_index_test_time_temp_idx | 1 | index_test_time_temp_idx
|
|
2 | _hyper_1_2_chunk_index_test_device_time_idx | 1 | index_test_device_time_idx
|
|
2 | _hyper_1_2_chunk_index_test_time_temp_idx | 1 | index_test_time_temp_idx
|
|
1 | 1_1_index_test_time_device_key | 1 | index_test_time_device_key
|
|
2 | 2_2_index_test_time_device_key | 1 | index_test_time_device_key
|
|
(6 rows)
|
|
|
|
SELECT * FROM _timescaledb_catalog.chunk_constraint;
|
|
chunk_id | dimension_slice_id | constraint_name | hypertable_constraint_name
|
|
----------+--------------------+--------------------------------+----------------------------
|
|
1 | 1 | constraint_1 |
|
|
1 | 2 | constraint_2 |
|
|
2 | 3 | constraint_3 |
|
|
2 | 2 | constraint_2 |
|
|
1 | | 1_1_index_test_time_device_key | index_test_time_device_key
|
|
2 | | 2_2_index_test_time_device_key | index_test_time_device_key
|
|
(6 rows)
|
|
|
|
DROP TABLE index_test;
|
|
-- Metadata removed
|
|
SELECT * FROM _timescaledb_catalog.chunk_index;
|
|
chunk_id | index_name | hypertable_id | hypertable_index_name
|
|
----------+------------+---------------+-----------------------
|
|
(0 rows)
|
|
|
|
-- Test that indexes are planned correctly
|
|
CREATE TABLE index_expr_test(id serial, time timestamptz, temp float, meta int);
|
|
select create_hypertable('index_expr_test', 'time');
|
|
NOTICE: adding not-null constraint to column "time"
|
|
create_hypertable
|
|
------------------------------
|
|
(2,public,index_expr_test,t)
|
|
(1 row)
|
|
|
|
-- Screw up the attribute numbers
|
|
ALTER TABLE index_expr_test DROP COLUMN id;
|
|
CREATE INDEX ON index_expr_test (meta) WITH (timescaledb.transaction_per_chunk);
|
|
INSERT INTO index_expr_test VALUES ('2017-01-20T09:00:01', 17.5, 1);
|
|
INSERT INTO index_expr_test VALUES ('2017-01-20T09:00:01', 17.5, 2);
|
|
SET enable_seqscan TO false;
|
|
SET enable_bitmapscan TO false;
|
|
EXPLAIN (verbose, costs off)
|
|
SELECT * FROM index_expr_test WHERE meta = 1;
|
|
QUERY PLAN
|
|
------------------------------------------------------------------------------------------------------
|
|
Index Scan using _hyper_2_3_chunk_index_expr_test_meta_idx on _timescaledb_internal._hyper_2_3_chunk
|
|
Output: _hyper_2_3_chunk."time", _hyper_2_3_chunk.temp, _hyper_2_3_chunk.meta
|
|
Index Cond: (_hyper_2_3_chunk.meta = 1)
|
|
(3 rows)
|
|
|
|
SELECT * FROM index_expr_test WHERE meta = 1;
|
|
time | temp | meta
|
|
------------------------------+------+------
|
|
Fri Jan 20 09:00:01 2017 PST | 17.5 | 1
|
|
(1 row)
|
|
|
|
SET enable_seqscan TO default;
|
|
SET enable_bitmapscan TO default;
|
|
\set ON_ERROR_STOP 0
|
|
-- cannot create a transaction_per_chunk index within a transaction block
|
|
BEGIN;
|
|
CREATE INDEX ON index_expr_test (temp) WITH (timescaledb.transaction_per_chunk);
|
|
ERROR: CREATE INDEX ... WITH (timescaledb.transaction_per_chunk) cannot run inside a transaction block
|
|
ROLLBACK;
|
|
\set ON_ERROR_STOP 1
|
|
DROP TABLE index_expr_test CASCADE;
|
|
CREATE TABLE partial_index_test(time INTEGER);
|
|
SELECT create_hypertable('partial_index_test', 'time', chunk_time_interval => 1, create_default_indexes => false);
|
|
NOTICE: adding not-null constraint to column "time"
|
|
create_hypertable
|
|
---------------------------------
|
|
(3,public,partial_index_test,t)
|
|
(1 row)
|
|
|
|
-- create 3 chunks
|
|
INSERT INTO partial_index_test(time) SELECT generate_series(0, 2);
|
|
select * from partial_index_test order by 1;
|
|
time
|
|
------
|
|
0
|
|
1
|
|
2
|
|
(3 rows)
|
|
|
|
-- create indexes on only 1 of the chunks
|
|
CREATE INDEX ON partial_index_test (time) WITH (timescaledb.transaction_per_chunk, timescaledb.max_chunks='1');
|
|
SELECT * FROM test.show_indexes('partial_index_test');
|
|
Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
-----------------------------+---------+------+--------+---------+-----------+------------
|
|
partial_index_test_time_idx | {time} | | f | f | f |
|
|
(1 row)
|
|
|
|
SELECT * FROM test.show_indexesp('_timescaledb_internal._hyper%_chunk');
|
|
Table | Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
----------------------------------------+--------------------------------------------------------------------+---------+------+--------+---------+-----------+------------
|
|
_timescaledb_internal._hyper_3_4_chunk | _timescaledb_internal._hyper_3_4_chunk_partial_index_test_time_idx | {time} | | f | f | f |
|
|
(1 row)
|
|
|
|
-- regerssion test for bug fixed by PR #1008.
|
|
-- this caused an assertion failure when a MergeAppend node contained unsorted children
|
|
SET enable_seqscan TO false;
|
|
SET enable_bitmapscan TO false;
|
|
EXPLAIN (verbose, costs off) SELECT * FROM partial_index_test WHERE time < 2 ORDER BY time LIMIT 2;
|
|
QUERY PLAN
|
|
--------------------------------------------------------------------------------------------------------------------------
|
|
Limit
|
|
Output: partial_index_test."time"
|
|
-> Custom Scan (ChunkAppend) on public.partial_index_test
|
|
Output: partial_index_test."time"
|
|
Order: partial_index_test."time"
|
|
Startup Exclusion: false
|
|
Runtime Exclusion: false
|
|
-> Index Only Scan using _hyper_3_4_chunk_partial_index_test_time_idx on _timescaledb_internal._hyper_3_4_chunk
|
|
Output: _hyper_3_4_chunk."time"
|
|
Index Cond: (_hyper_3_4_chunk."time" < 2)
|
|
-> Sort
|
|
Output: _hyper_3_5_chunk."time"
|
|
Sort Key: _hyper_3_5_chunk."time"
|
|
-> Seq Scan on _timescaledb_internal._hyper_3_5_chunk
|
|
Output: _hyper_3_5_chunk."time"
|
|
Filter: (_hyper_3_5_chunk."time" < 2)
|
|
(16 rows)
|
|
|
|
SELECT * FROM partial_index_test WHERE time < 2 ORDER BY time LIMIT 2;
|
|
time
|
|
------
|
|
0
|
|
1
|
|
(2 rows)
|
|
|
|
-- we can drop the partially created index
|
|
DROP INDEX partial_index_test_time_idx;
|
|
SELECT * FROM test.show_indexes('partial_index_test');
|
|
Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
-------+---------+------+--------+---------+-----------+------------
|
|
(0 rows)
|
|
|
|
SELECT * FROM test.show_indexesp('_timescaledb_internal._hyper%_chunk');
|
|
Table | Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
|
|
-------+-------+---------+------+--------+---------+-----------+------------
|
|
(0 rows)
|
|
|
|
EXPLAIN (verbose, costs off) SELECT * FROM partial_index_test WHERE time < 2 ORDER BY time LIMIT 2;
|
|
QUERY PLAN
|
|
----------------------------------------------------------------------
|
|
Limit
|
|
Output: _hyper_3_4_chunk."time"
|
|
-> Sort
|
|
Output: _hyper_3_4_chunk."time"
|
|
Sort Key: _hyper_3_4_chunk."time"
|
|
-> Append
|
|
-> Seq Scan on _timescaledb_internal._hyper_3_4_chunk
|
|
Output: _hyper_3_4_chunk."time"
|
|
Filter: (_hyper_3_4_chunk."time" < 2)
|
|
-> Seq Scan on _timescaledb_internal._hyper_3_5_chunk
|
|
Output: _hyper_3_5_chunk."time"
|
|
Filter: (_hyper_3_5_chunk."time" < 2)
|
|
(12 rows)
|
|
|
|
SELECT * FROM partial_index_test WHERE time < 2 ORDER BY time LIMIT 2;
|
|
time
|
|
------
|
|
0
|
|
1
|
|
(2 rows)
|
|
|
|
SET enable_seqscan TO true;
|
|
SET enable_bitmapscan TO true;
|
|
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER_2
|
|
\set ON_ERROR_STOP 0
|
|
CREATE INDEX ON partial_index_test (time) WITH (timescaledb.transaction_per_chunk, timescaledb.max_chunks='1');
|
|
ERROR: must be owner of hypertable "partial_index_test"
|
|
\set ON_ERROR_STOP 1
|