I need to create index on hypertable that also includes time.
-
Create table
create table public.tab1 (mytime timestamptz not null, company int, value int);
-
Create index with include option
create index on public.tab1 (mytime desc) include (company);
-
Convert table to hypertable
SELECT create_hypertable('public.tab1', 'mytime');
-
Check table definition and indexes
\d public.tab1
Output:
Table "public.tab1"
Column | Type | Collation | Nullable | Default
---------+--------------------------+-----------+----------+---------
mytime | timestamp with time zone | | not null |
company | integer | | |
value | integer | | |
Indexes:
"tab1_mytime_company_idx" btree (mytime DESC) INCLUDE (company)
"tab1_mytime_idx" btree (mytime DESC)
Triggers:
ts_insert_blocker BEFORE INSERT ON tab1
FOR EACH ROW EXECUTE FUNCTION _timescaledb_internal.insert_blocker()
TimescaleDB created a new index despite my index already contains exactly the same time column as first column. I expected TimescaleDB to use my index instead of creating new one.
Is there an option TimescaleDB to force usage of already created index?
Now I have:
- chunks: 5 TB of data
- timescale index: 1 TB of data
- my index: 3 TB of data.
If I can force TimescaleDB to use already created index, I could spare 1 TB of data.
EDIT: Instead of “include” index I also tried:
create index on public.tab1 (mytime desc, company);
and TimescaleDB also does not uses already created index.