timescaledb/test/sql/sql_query_results_optimized.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

7 lines
85 B
SQL

\o /dev/null
\ir include/create_single_db.sql
\o
\ir include/sql_query_results.sql