Сould not find pathkey item to sort

Hi, all!

Postgres version: PostgreSQL 15.3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
TimscaleDB version: 2.12.1
Hypertable is compressed.

If the query joins compressed hypertable with regular postgres table and period is larger then few days then exception is threw

SELECT date_trunc('day', a.date_col) AS col_date,
	COUNT(DISTINCT a.id_account),
	SUM(a.num_col1 - a.num_col2)
FROM compressed_hypert AS a
	INNER JOIN postgres_table AS b ON b.id = a.id
WHERE a.col_date >= TIMESTAMP '2023-10-01' AND a.col_date < TIMESTAMP '2023-11-15'
GROUP BY date_trunc('day', a.date_col), a.col2, b.col3

SQL Error [XX000]: ERROR: could not find pathkey item to sort

If I reduce period to few days then the query gives the result successfully.

About this I found issue on github but the decision I did not find.

Is there a workaround to do the query like above working?

Thanks in advance.

Hi Lux, not sure if I can answer it but any reason to not use time_bucket instead of date_trunc? Have you tried it?

Unfortunately, it is not matter: time_bucket gives the same result.

Can it be related to the timescaledb.compress_orderby? It’s very important for performance too. Not sure if you have it configured or not.

Yes, I configured both parameters:

timescaledb.compress_orderby = 'id',
timescaledb.compress_segmentby = 'another_col1, another_col2'

And one more thing: the table has been partitioned by month since 2017, the data in the partitions since 2019 is constantly updated.