9 Commits

Author SHA1 Message Date
Jan Nidzwetzki
e99832727a Place data in first/last function in correct mctx
So far, the ts_bookend_deserializefunc() function has allocated the
deserialized data in the current memory context. This data could be
removed before the aggregation is finished. This patch moves the data
into the aggregation memory context.
2023-08-22 08:08:31 +02:00
Lakshmi Narayanan Sreethar
c3a9f90fdd Merge PG12 specific testfiles
Merged testfiles that were split out due to their output differing only
in PG12.
2023-07-25 16:00:18 +05:30
niksa
019971c402 Optimize FIRST/LAST aggregate functions
If possible replace aggregate functions FIRST/LAST with subqueries of the form
(SELECT value FROM table WHERE sort IS NOT NULL AND existing-quals ORDER BY sort ASC/DESC
LIMIT 1).
Given a suitable index on sort column, this plan can be much faster then scanning all the
rows and running an aggregate function.
The optimization can't be performed if:
- query uses GROUP BY or WINDOW function
- query contains CTEs
- query contains other aggregate functions (eg. Combining MIN/MAX with FIRST/LAST. We can't
	optimize accross different aggregate functions)
- query uses JOIN
- FIRST/LAST used in ORDER BY

Optimization also works with subqueries, or if FIRST/LAST is used in CTE subquery.

In order to standardize existing FIRST/LAST aggregate function with PostgreSQL and
FIRST/LAST optimization, we exclude NULL values in sort by column.
2018-12-10 09:50:55 +01:00
Joshua Lockerman
20ec6914c0 Add license headers to SQL files and test code 2018-10-29 13:28:19 -04:00
Erik Nordström
500563ffe5 Add support for PostgreSQL 10
The extension now works with PostgreSQL 10, while
retaining compatibility with version 9.6.

PostgreSQL 10 has numerous internal changes to functions and
APIs, which necessitates various glue code and compatibility
wrappers to seamlessly retain backwards compatiblity with older
versions.

Test output might also differ between versions. In particular,
the psql client generates version-specific output with `\d` and
EXPLAINs might differ due to new query optimizations. The test
suite has been modified as follows to handle these issues. First,
tests now use version-independent functions to query system
catalogs instead of using `\d`. Second, changes have been made to
the test suite to be able to verify some test outputs against
version-dependent reference files.
2017-11-10 09:44:20 +01:00
Matvey Arye
543a75f865 Refactor regression tests
This commit moves a lot of test setup logic to runner.sh. Also
passes the right commands to the regression infrastructure to create
appropriate users and run tests as a regular user.
2017-10-05 15:56:33 -04:00
Matvey Arye
afcb0b11da Fix NULL handling in first/last functions.
There are 2 separate fixes:
1) Fix for NULL value handling when values are numeric types.
   This fixes #209. Thanks to @raycheung for reporting this bug.
2) Correct handling for NULLs in compare/ordering elements.
   The functions will now always return NULL if any comparison element
   in group was NULL.
2017-09-19 17:12:06 -04:00
Matvey Arye
db01c84c2d Make time-bucket function parallel safe
There was no reason for it not to be parallel safe before.
2017-06-02 16:15:51 -04:00
Matvey Arye
662be94d69 Add the first(value, time),last(value, time) aggregates
Add the first and last aggregate functions, which allows for getting
the first and last value, by time, per group. Addresses issue #30.
2017-05-16 09:46:49 -04:00