Quantcast
Channel: TimescaleDB and PostgreSQL - Timescale Community Forum
Viewing all articles
Browse latest Browse all 294

Partition by additional dimension and query is 10-times slower instead of expected to run much faster

$
0
0

On PostgreSQL 15.6 and TimescaleDB 2.14.2 self-host on prem.

TEST 1: Hyper-table partitioned by time

  1. Create PostgreSQL table.
  2. Convert table to hypertable with: SELECT CREATE_HYPERTABLE('mytable', BY_RANGE('time', INTERVAL '3 day'));
  3. Insert the data into a table and create index: CREATE UNIQUE INDEX myindex ON mytable (deviceid, companyid, time);
  4. Execute query it takes: 300 ms (when no data are in PostgreSQL cache).
  5. Execute the query again it takes: 51 ms (data are in PostgreSQL cache).
  6. Did an SQL explain and at the top of explain is: “Chunks excluded during startup: 190” and with total 360 chunks that is more then half of chunks where excluded. This is just like expected.

TEST 2: Hyper-table partitioned by time and company
Now I though adding additional dimension would speed up the querys.
1 and 2 The same as above.
2a SELECT ADD_DIMENSION('mytable', BY_RANGE('company', 1)); → Each company data in its own chunk.
3,4,5,6 The same steps as above.

At 4) But to my a surprise in step 4 query takes 4 seconds, which is 10-times comparing to previous test.
At 5) When SQL is run for the second time (data are in PostgreSQL cache) it still executes 150 ms, which is 3-times above test.
At 6) I did explain and at the top of explain is: “Chunks excluded during startup: 1”. I expected to see at least 70% of chunks should be excluded during startup.

Like I see the culprit of the problem is, that database does not exclude 70% of chunks during startup.

QUESTION: Is there something additionally I need to set, that database eliminates 70% of chunks chunks during startup?

EDIT: I checked the catalog and here are more info:

select id, hypertable_id, column_name, column_type, interval_length from _timescaledb_catalog.dimension where hypertable_id = 37;

 id | hypertable_id |  column_name   |       column_type        | interval_length                                                           
----+---------------+----------------+--------------------------+-----------------                                                          
 32 |            37 | time           | timestamp with time zone |    259200000000                                                           
 33 |            37 | company        | smallint                 |               1                                                           
(2 rows)

select * from _timescaledb_catalog.dimension_slice where dimension_id = 33;

  id   | dimension_id | range_start | range_end                                                                                             
-------+--------------+-------------+-----------                                                                                            
 34539 |           33 |           2 |         3                                                                                             
 34541 |           33 |           3 |         4                                                                                             
 34543 |           33 |           4 |         5                                                                                             
 34544 |           33 |           6 |         7                                                                                             
 34542 |           33 |           7 |         8                                                                                             
 34741 |           33 |          11 |        12                                                                                             
(6 rows)

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 294

Trending Articles