mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-20 12:47:40 +08:00
This PR adds support for finalizing aggregates with FINALFUNC_EXTRA. To do this, we need to pass NULLS correspond to all of the aggregate parameters to the ffunc as arguments following the partial state value. These arguments need to have the correct concrete types. For polymorphic aggregates, the types cannot be derived from the catalog but need to be somehow conveyed to the finalize_agg. Two designs were considered: 1) Encode the type names as part of the partial state (bytea) 2) Pass down the arguments as parameters to the finalize_agg In the end (2) was picked for the simple reason that (1) would have increased the size of each partial, sometimes considerably (esp. for small partial values). The types are passed down as names not OIDs because in the continuous agg case using OIDs is not safe for backup/restore and in the clustering case the datanodes may not have the same type OIDs either.
20 lines
1.0 KiB
SQL
20 lines
1.0 KiB
SQL
-- This file and its contents are licensed under the Apache License 2.0.
|
|
-- Please see the included NOTICE for copyright information and
|
|
-- LICENSE-APACHE for a copy of the license.
|
|
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.partialize_agg(arg ANYELEMENT)
|
|
RETURNS BYTEA AS '@MODULE_PATHNAME@', 'ts_partialize_agg' LANGUAGE C VOLATILE;
|
|
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.finalize_agg_sfunc(
|
|
tstate internal, aggfn TEXT, inner_agg_collation_schema NAME, inner_agg_collation_name NAME, inner_agg_input_types NAME[][], inner_agg_serialized_state BYTEA, return_type_dummy_val ANYELEMENT)
|
|
RETURNS internal
|
|
AS '@MODULE_PATHNAME@', 'ts_finalize_agg_sfunc'
|
|
LANGUAGE C IMMUTABLE ;
|
|
|
|
CREATE OR REPLACE FUNCTION _timescaledb_internal.finalize_agg_ffunc(
|
|
tstate internal, aggfn TEXT, inner_agg_collation_schema NAME, inner_agg_collation_name NAME, inner_agg_input_types NAME[][], inner_agg_serialized_state BYTEA, return_type_dummy_val ANYELEMENT)
|
|
RETURNS anyelement
|
|
AS '@MODULE_PATHNAME@', 'ts_finalize_agg_ffunc'
|
|
LANGUAGE C IMMUTABLE ;
|
|
|