timescaledb/test/sql/sql_query_results_x_diff.sql
Matvey Arye ea0c97d590 Optimize queries with date_trunc in ORDER BY and a LIMIT.
Common time-series rollups are of the form SELECT date_trunc(const,
time) as t, aggregates... GROUP BY t ORDER BY t DESC LIMIT const2.
Previously, Postgres would not optimize such queries because it
could not match date_trunc(const, time) to any indexes on time, since
it has no way to know that a sort on time is always a valid sort on
date_trunc(const, time).

This commit implements this optimization for date_trunc but it could
apply to a wider range of functions, to be implemented later.
2017-04-05 16:35:14 -04:00

3 lines
156 B
SQL

--make sure diff only has explain output not result output
\! diff ../results/sql_query_results_optimized.out ../results/sql_query_results_unoptimized.out