-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
\set EXPLAIN 'EXPLAIN (VERBOSE, BUFFERS OFF, COSTS OFF)'
CREATE TABLE testtable (
time timestamptz NOT NULL,
segment_by_value integer,
int_value integer,
float_value double precision);
SELECT FROM create_hypertable(relation=>'testtable', time_column_name=> 'time');
--

ALTER TABLE testtable SET (timescaledb.compress, timescaledb.compress_segmentby='segment_by_value');
INSERT INTO testtable
SELECT time AS time,
value AS segment_by_value,
value AS int_value,
value AS float_value
FROM
generate_series('1980-01-01 00:00:00-00', '1980-03-01 00:00:00-00', INTERVAL '1 day') AS g1(time),
generate_series(-10, 100, 1) AS g2(value)
ORDER BY time;
-- Aggregation result without any vectorization
SELECT sum(segment_by_value), sum(int_value), sum(float_value) FROM testtable;
  sum   |  sum   |  sum   
--------+--------+--------
 304695 | 304695 | 304695

--
-- Enable this GUC to run this test with Hypercore TAM. The EXPLAINs
-- will differ, but the results should not.
--
--SET timescaledb.default_hypercore_use_access_method = true;
---
-- Tests with some chunks compressed
---
SELECT compress_chunk(ch) FROM show_chunks('testtable') ch LIMIT 3;
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk
 _timescaledb_internal._hyper_1_2_chunk
 _timescaledb_internal._hyper_1_3_chunk

VACUUM ANALYZE testtable;
-- Vectorized aggregation possible
SELECT sum(segment_by_value) FROM testtable;
  sum   
--------
 304695

:EXPLAIN
SELECT sum(segment_by_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_4_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.segment_by_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_5_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.segment_by_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_6_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.segment_by_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_7_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.segment_by_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_8_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.segment_by_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_9_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.segment_by_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_10_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.segment_by_value

-- Vectorization possible - filter on segment_by
:EXPLAIN
SELECT sum(segment_by_value) FROM testtable WHERE segment_by_value > 0;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
                           Filter: (compress_hyper_2_11_chunk.segment_by_value > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
                           Filter: (compress_hyper_2_12_chunk.segment_by_value > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
                           Filter: (compress_hyper_2_13_chunk.segment_by_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_4_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.segment_by_value
                     Filter: (_hyper_1_4_chunk.segment_by_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_5_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.segment_by_value
                     Filter: (_hyper_1_5_chunk.segment_by_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_6_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.segment_by_value
                     Filter: (_hyper_1_6_chunk.segment_by_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_7_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.segment_by_value
                     Filter: (_hyper_1_7_chunk.segment_by_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_8_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.segment_by_value
                     Filter: (_hyper_1_8_chunk.segment_by_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_9_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.segment_by_value
                     Filter: (_hyper_1_9_chunk.segment_by_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_10_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.segment_by_value
                     Filter: (_hyper_1_10_chunk.segment_by_value > 0)

-- Vectorization with filter on compressed columns
:EXPLAIN
SELECT sum(segment_by_value) FROM testtable WHERE segment_by_value > 0 AND int_value > 0;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
                     Vectorized Filter: (_hyper_1_1_chunk.int_value > 0)
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
                           Filter: (compress_hyper_2_11_chunk.segment_by_value > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.segment_by_value
                     Vectorized Filter: (_hyper_1_2_chunk.int_value > 0)
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
                           Filter: (compress_hyper_2_12_chunk.segment_by_value > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.segment_by_value
                     Vectorized Filter: (_hyper_1_3_chunk.int_value > 0)
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
                           Filter: (compress_hyper_2_13_chunk.segment_by_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_4_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.segment_by_value
                     Filter: ((_hyper_1_4_chunk.segment_by_value > 0) AND (_hyper_1_4_chunk.int_value > 0))
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_5_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.segment_by_value
                     Filter: ((_hyper_1_5_chunk.segment_by_value > 0) AND (_hyper_1_5_chunk.int_value > 0))
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_6_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.segment_by_value
                     Filter: ((_hyper_1_6_chunk.segment_by_value > 0) AND (_hyper_1_6_chunk.int_value > 0))
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_7_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.segment_by_value
                     Filter: ((_hyper_1_7_chunk.segment_by_value > 0) AND (_hyper_1_7_chunk.int_value > 0))
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_8_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.segment_by_value
                     Filter: ((_hyper_1_8_chunk.segment_by_value > 0) AND (_hyper_1_8_chunk.int_value > 0))
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_9_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.segment_by_value
                     Filter: ((_hyper_1_9_chunk.segment_by_value > 0) AND (_hyper_1_9_chunk.int_value > 0))
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_10_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.segment_by_value
                     Filter: ((_hyper_1_10_chunk.segment_by_value > 0) AND (_hyper_1_10_chunk.int_value > 0))

:EXPLAIN
SELECT sum(segment_by_value) FROM testtable WHERE int_value > 0;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
                     Vectorized Filter: (_hyper_1_1_chunk.int_value > 0)
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.segment_by_value
                     Vectorized Filter: (_hyper_1_2_chunk.int_value > 0)
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.segment_by_value
                     Vectorized Filter: (_hyper_1_3_chunk.int_value > 0)
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_4_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.segment_by_value
                     Filter: (_hyper_1_4_chunk.int_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_5_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.segment_by_value
                     Filter: (_hyper_1_5_chunk.int_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_6_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.segment_by_value
                     Filter: (_hyper_1_6_chunk.int_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_7_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.segment_by_value
                     Filter: (_hyper_1_7_chunk.int_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_8_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.segment_by_value
                     Filter: (_hyper_1_8_chunk.int_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_9_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.segment_by_value
                     Filter: (_hyper_1_9_chunk.int_value > 0)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_10_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.segment_by_value
                     Filter: (_hyper_1_10_chunk.int_value > 0)

:EXPLAIN
SELECT sum(segment_by_value) FROM testtable WHERE float_value > 0;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
                     Vectorized Filter: (_hyper_1_1_chunk.float_value > '0'::double precision)
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.segment_by_value
                     Vectorized Filter: (_hyper_1_2_chunk.float_value > '0'::double precision)
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.segment_by_value
                     Vectorized Filter: (_hyper_1_3_chunk.float_value > '0'::double precision)
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_4_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.segment_by_value
                     Filter: (_hyper_1_4_chunk.float_value > '0'::double precision)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_5_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.segment_by_value
                     Filter: (_hyper_1_5_chunk.float_value > '0'::double precision)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_6_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.segment_by_value
                     Filter: (_hyper_1_6_chunk.float_value > '0'::double precision)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_7_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.segment_by_value
                     Filter: (_hyper_1_7_chunk.float_value > '0'::double precision)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_8_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.segment_by_value
                     Filter: (_hyper_1_8_chunk.float_value > '0'::double precision)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_9_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.segment_by_value
                     Filter: (_hyper_1_9_chunk.float_value > '0'::double precision)
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_10_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.segment_by_value
                     Filter: (_hyper_1_10_chunk.float_value > '0'::double precision)

-- Vectorization possible with grouping by one fixed-size column
:EXPLAIN
SELECT sum(segment_by_value) FROM testtable GROUP BY float_value;
--- QUERY PLAN ---
 Finalize HashAggregate
   Output: sum(testtable.segment_by_value), testtable.float_value
   Group Key: testtable.float_value
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_1_chunk.float_value, (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: hashed with single 8-byte key
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.float_value, _hyper_1_1_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_2_chunk.float_value, (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: hashed with single 8-byte key
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.float_value, _hyper_1_2_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_3_chunk.float_value, (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: hashed with single 8-byte key
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.float_value, _hyper_1_3_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial HashAggregate
               Output: _hyper_1_4_chunk.float_value, PARTIAL sum(_hyper_1_4_chunk.segment_by_value)
               Group Key: _hyper_1_4_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.float_value, _hyper_1_4_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_5_chunk.float_value, PARTIAL sum(_hyper_1_5_chunk.segment_by_value)
               Group Key: _hyper_1_5_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.float_value, _hyper_1_5_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_6_chunk.float_value, PARTIAL sum(_hyper_1_6_chunk.segment_by_value)
               Group Key: _hyper_1_6_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.float_value, _hyper_1_6_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_7_chunk.float_value, PARTIAL sum(_hyper_1_7_chunk.segment_by_value)
               Group Key: _hyper_1_7_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.float_value, _hyper_1_7_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_8_chunk.float_value, PARTIAL sum(_hyper_1_8_chunk.segment_by_value)
               Group Key: _hyper_1_8_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.float_value, _hyper_1_8_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_9_chunk.float_value, PARTIAL sum(_hyper_1_9_chunk.segment_by_value)
               Group Key: _hyper_1_9_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.float_value, _hyper_1_9_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_10_chunk.float_value, PARTIAL sum(_hyper_1_10_chunk.segment_by_value)
               Group Key: _hyper_1_10_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.float_value, _hyper_1_10_chunk.segment_by_value

:EXPLAIN
SELECT sum(segment_by_value) FROM testtable GROUP BY int_value;
--- QUERY PLAN ---
 Finalize HashAggregate
   Output: sum(testtable.segment_by_value), testtable.int_value
   Group Key: testtable.int_value
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_1_chunk.int_value, (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: hashed with single 4-byte key
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value, _hyper_1_1_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_2_chunk.int_value, (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: hashed with single 4-byte key
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.int_value, _hyper_1_2_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_3_chunk.int_value, (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: hashed with single 4-byte key
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.int_value, _hyper_1_3_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial HashAggregate
               Output: _hyper_1_4_chunk.int_value, PARTIAL sum(_hyper_1_4_chunk.segment_by_value)
               Group Key: _hyper_1_4_chunk.int_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.int_value, _hyper_1_4_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_5_chunk.int_value, PARTIAL sum(_hyper_1_5_chunk.segment_by_value)
               Group Key: _hyper_1_5_chunk.int_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.int_value, _hyper_1_5_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_6_chunk.int_value, PARTIAL sum(_hyper_1_6_chunk.segment_by_value)
               Group Key: _hyper_1_6_chunk.int_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.int_value, _hyper_1_6_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_7_chunk.int_value, PARTIAL sum(_hyper_1_7_chunk.segment_by_value)
               Group Key: _hyper_1_7_chunk.int_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.int_value, _hyper_1_7_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_8_chunk.int_value, PARTIAL sum(_hyper_1_8_chunk.segment_by_value)
               Group Key: _hyper_1_8_chunk.int_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.int_value, _hyper_1_8_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_9_chunk.int_value, PARTIAL sum(_hyper_1_9_chunk.segment_by_value)
               Group Key: _hyper_1_9_chunk.int_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.int_value, _hyper_1_9_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_10_chunk.int_value, PARTIAL sum(_hyper_1_10_chunk.segment_by_value)
               Group Key: _hyper_1_10_chunk.int_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.int_value, _hyper_1_10_chunk.segment_by_value

-- Vectorization possible with grouping by multiple columns
:EXPLAIN
SELECT sum(segment_by_value) FROM testtable GROUP BY int_value, float_value;
--- QUERY PLAN ---
 Finalize HashAggregate
   Output: sum(testtable.segment_by_value), testtable.int_value, testtable.float_value
   Group Key: testtable.int_value, testtable.float_value
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_1_chunk.int_value, _hyper_1_1_chunk.float_value, (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: hashed with serialized key
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value, _hyper_1_1_chunk.float_value, _hyper_1_1_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_2_chunk.int_value, _hyper_1_2_chunk.float_value, (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: hashed with serialized key
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.int_value, _hyper_1_2_chunk.float_value, _hyper_1_2_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_3_chunk.int_value, _hyper_1_3_chunk.float_value, (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: hashed with serialized key
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.int_value, _hyper_1_3_chunk.float_value, _hyper_1_3_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial HashAggregate
               Output: _hyper_1_4_chunk.int_value, _hyper_1_4_chunk.float_value, PARTIAL sum(_hyper_1_4_chunk.segment_by_value)
               Group Key: _hyper_1_4_chunk.int_value, _hyper_1_4_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.int_value, _hyper_1_4_chunk.float_value, _hyper_1_4_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_5_chunk.int_value, _hyper_1_5_chunk.float_value, PARTIAL sum(_hyper_1_5_chunk.segment_by_value)
               Group Key: _hyper_1_5_chunk.int_value, _hyper_1_5_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.int_value, _hyper_1_5_chunk.float_value, _hyper_1_5_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_6_chunk.int_value, _hyper_1_6_chunk.float_value, PARTIAL sum(_hyper_1_6_chunk.segment_by_value)
               Group Key: _hyper_1_6_chunk.int_value, _hyper_1_6_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.int_value, _hyper_1_6_chunk.float_value, _hyper_1_6_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_7_chunk.int_value, _hyper_1_7_chunk.float_value, PARTIAL sum(_hyper_1_7_chunk.segment_by_value)
               Group Key: _hyper_1_7_chunk.int_value, _hyper_1_7_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.int_value, _hyper_1_7_chunk.float_value, _hyper_1_7_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_8_chunk.int_value, _hyper_1_8_chunk.float_value, PARTIAL sum(_hyper_1_8_chunk.segment_by_value)
               Group Key: _hyper_1_8_chunk.int_value, _hyper_1_8_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.int_value, _hyper_1_8_chunk.float_value, _hyper_1_8_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_9_chunk.int_value, _hyper_1_9_chunk.float_value, PARTIAL sum(_hyper_1_9_chunk.segment_by_value)
               Group Key: _hyper_1_9_chunk.int_value, _hyper_1_9_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.int_value, _hyper_1_9_chunk.float_value, _hyper_1_9_chunk.segment_by_value
         ->  Partial HashAggregate
               Output: _hyper_1_10_chunk.int_value, _hyper_1_10_chunk.float_value, PARTIAL sum(_hyper_1_10_chunk.segment_by_value)
               Group Key: _hyper_1_10_chunk.int_value, _hyper_1_10_chunk.float_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.int_value, _hyper_1_10_chunk.float_value, _hyper_1_10_chunk.segment_by_value

-- Vectorization possible with grouping by a segmentby column.
:EXPLAIN
SELECT sum(int_value) FROM testtable GROUP BY segment_by_value;
--- QUERY PLAN ---
 Finalize HashAggregate
   Output: sum(testtable.int_value), testtable.segment_by_value
   Group Key: testtable.segment_by_value
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_1_chunk.segment_by_value, (PARTIAL sum(_hyper_1_1_chunk.int_value))
               Grouping Policy: per compressed batch
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value, _hyper_1_1_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_2_chunk.segment_by_value, (PARTIAL sum(_hyper_1_2_chunk.int_value))
               Grouping Policy: per compressed batch
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.segment_by_value, _hyper_1_2_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: _hyper_1_3_chunk.segment_by_value, (PARTIAL sum(_hyper_1_3_chunk.int_value))
               Grouping Policy: per compressed batch
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.segment_by_value, _hyper_1_3_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial HashAggregate
               Output: _hyper_1_4_chunk.segment_by_value, PARTIAL sum(_hyper_1_4_chunk.int_value)
               Group Key: _hyper_1_4_chunk.segment_by_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.segment_by_value, _hyper_1_4_chunk.int_value
         ->  Partial HashAggregate
               Output: _hyper_1_5_chunk.segment_by_value, PARTIAL sum(_hyper_1_5_chunk.int_value)
               Group Key: _hyper_1_5_chunk.segment_by_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.segment_by_value, _hyper_1_5_chunk.int_value
         ->  Partial HashAggregate
               Output: _hyper_1_6_chunk.segment_by_value, PARTIAL sum(_hyper_1_6_chunk.int_value)
               Group Key: _hyper_1_6_chunk.segment_by_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.segment_by_value, _hyper_1_6_chunk.int_value
         ->  Partial HashAggregate
               Output: _hyper_1_7_chunk.segment_by_value, PARTIAL sum(_hyper_1_7_chunk.int_value)
               Group Key: _hyper_1_7_chunk.segment_by_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.segment_by_value, _hyper_1_7_chunk.int_value
         ->  Partial HashAggregate
               Output: _hyper_1_8_chunk.segment_by_value, PARTIAL sum(_hyper_1_8_chunk.int_value)
               Group Key: _hyper_1_8_chunk.segment_by_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.segment_by_value, _hyper_1_8_chunk.int_value
         ->  Partial HashAggregate
               Output: _hyper_1_9_chunk.segment_by_value, PARTIAL sum(_hyper_1_9_chunk.int_value)
               Group Key: _hyper_1_9_chunk.segment_by_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.segment_by_value, _hyper_1_9_chunk.int_value
         ->  Partial HashAggregate
               Output: _hyper_1_10_chunk.segment_by_value, PARTIAL sum(_hyper_1_10_chunk.int_value)
               Group Key: _hyper_1_10_chunk.segment_by_value
               ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.segment_by_value, _hyper_1_10_chunk.int_value

:EXPLAIN
SELECT sum(segment_by_value), segment_by_value FROM testtable GROUP BY segment_by_value ORDER BY 1, 2;
--- QUERY PLAN ---
 Sort
   Output: (sum(testtable.segment_by_value)), testtable.segment_by_value
   Sort Key: (sum(testtable.segment_by_value)), testtable.segment_by_value
   ->  Finalize HashAggregate
         Output: sum(testtable.segment_by_value), testtable.segment_by_value
         Group Key: testtable.segment_by_value
         ->  Append
               ->  Custom Scan (VectorAgg)
                     Output: _hyper_1_1_chunk.segment_by_value, (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
                     Grouping Policy: per compressed batch
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                           Output: _hyper_1_1_chunk.segment_by_value
                           ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                                 Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: _hyper_1_2_chunk.segment_by_value, (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
                     Grouping Policy: per compressed batch
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                           Output: _hyper_1_2_chunk.segment_by_value
                           ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                                 Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: _hyper_1_3_chunk.segment_by_value, (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
                     Grouping Policy: per compressed batch
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                           Output: _hyper_1_3_chunk.segment_by_value
                           ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                                 Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
               ->  Partial HashAggregate
                     Output: _hyper_1_4_chunk.segment_by_value, PARTIAL sum(_hyper_1_4_chunk.segment_by_value)
                     Group Key: _hyper_1_4_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                           Output: _hyper_1_4_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_5_chunk.segment_by_value, PARTIAL sum(_hyper_1_5_chunk.segment_by_value)
                     Group Key: _hyper_1_5_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                           Output: _hyper_1_5_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_6_chunk.segment_by_value, PARTIAL sum(_hyper_1_6_chunk.segment_by_value)
                     Group Key: _hyper_1_6_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                           Output: _hyper_1_6_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_7_chunk.segment_by_value, PARTIAL sum(_hyper_1_7_chunk.segment_by_value)
                     Group Key: _hyper_1_7_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                           Output: _hyper_1_7_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_8_chunk.segment_by_value, PARTIAL sum(_hyper_1_8_chunk.segment_by_value)
                     Group Key: _hyper_1_8_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                           Output: _hyper_1_8_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_9_chunk.segment_by_value, PARTIAL sum(_hyper_1_9_chunk.segment_by_value)
                     Group Key: _hyper_1_9_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                           Output: _hyper_1_9_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_10_chunk.segment_by_value, PARTIAL sum(_hyper_1_10_chunk.segment_by_value)
                     Group Key: _hyper_1_10_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                           Output: _hyper_1_10_chunk.segment_by_value

SELECT sum(segment_by_value), segment_by_value FROM testtable GROUP BY segment_by_value ORDER BY 1, 2;
 sum  | segment_by_value 
------+------------------
 -610 |              -10
 -549 |               -9
 -488 |               -8
 -427 |               -7
 -366 |               -6
 -305 |               -5
 -244 |               -4
 -183 |               -3
 -122 |               -2
  -61 |               -1
    0 |                0
   61 |                1
  122 |                2
  183 |                3
  244 |                4
  305 |                5
  366 |                6
  427 |                7
  488 |                8
  549 |                9
  610 |               10
  671 |               11
  732 |               12
  793 |               13
  854 |               14
  915 |               15
  976 |               16
 1037 |               17
 1098 |               18
 1159 |               19
 1220 |               20
 1281 |               21
 1342 |               22
 1403 |               23
 1464 |               24
 1525 |               25
 1586 |               26
 1647 |               27
 1708 |               28
 1769 |               29
 1830 |               30
 1891 |               31
 1952 |               32
 2013 |               33
 2074 |               34
 2135 |               35
 2196 |               36
 2257 |               37
 2318 |               38
 2379 |               39
 2440 |               40
 2501 |               41
 2562 |               42
 2623 |               43
 2684 |               44
 2745 |               45
 2806 |               46
 2867 |               47
 2928 |               48
 2989 |               49
 3050 |               50
 3111 |               51
 3172 |               52
 3233 |               53
 3294 |               54
 3355 |               55
 3416 |               56
 3477 |               57
 3538 |               58
 3599 |               59
 3660 |               60
 3721 |               61
 3782 |               62
 3843 |               63
 3904 |               64
 3965 |               65
 4026 |               66
 4087 |               67
 4148 |               68
 4209 |               69
 4270 |               70
 4331 |               71
 4392 |               72
 4453 |               73
 4514 |               74
 4575 |               75
 4636 |               76
 4697 |               77
 4758 |               78
 4819 |               79
 4880 |               80
 4941 |               81
 5002 |               82
 5063 |               83
 5124 |               84
 5185 |               85
 5246 |               86
 5307 |               87
 5368 |               88
 5429 |               89
 5490 |               90
 5551 |               91
 5612 |               92
 5673 |               93
 5734 |               94
 5795 |               95
 5856 |               96
 5917 |               97
 5978 |               98
 6039 |               99
 6100 |              100

:EXPLAIN
SELECT segment_by_value, sum(segment_by_value) FROM testtable GROUP BY segment_by_value ORDER BY 1, 2;
--- QUERY PLAN ---
 Sort
   Output: testtable.segment_by_value, (sum(testtable.segment_by_value))
   Sort Key: testtable.segment_by_value, (sum(testtable.segment_by_value))
   ->  Finalize HashAggregate
         Output: testtable.segment_by_value, sum(testtable.segment_by_value)
         Group Key: testtable.segment_by_value
         ->  Append
               ->  Custom Scan (VectorAgg)
                     Output: _hyper_1_1_chunk.segment_by_value, (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
                     Grouping Policy: per compressed batch
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                           Output: _hyper_1_1_chunk.segment_by_value
                           ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                                 Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: _hyper_1_2_chunk.segment_by_value, (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
                     Grouping Policy: per compressed batch
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                           Output: _hyper_1_2_chunk.segment_by_value
                           ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                                 Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: _hyper_1_3_chunk.segment_by_value, (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
                     Grouping Policy: per compressed batch
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                           Output: _hyper_1_3_chunk.segment_by_value
                           ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                                 Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
               ->  Partial HashAggregate
                     Output: _hyper_1_4_chunk.segment_by_value, PARTIAL sum(_hyper_1_4_chunk.segment_by_value)
                     Group Key: _hyper_1_4_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                           Output: _hyper_1_4_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_5_chunk.segment_by_value, PARTIAL sum(_hyper_1_5_chunk.segment_by_value)
                     Group Key: _hyper_1_5_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                           Output: _hyper_1_5_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_6_chunk.segment_by_value, PARTIAL sum(_hyper_1_6_chunk.segment_by_value)
                     Group Key: _hyper_1_6_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                           Output: _hyper_1_6_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_7_chunk.segment_by_value, PARTIAL sum(_hyper_1_7_chunk.segment_by_value)
                     Group Key: _hyper_1_7_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                           Output: _hyper_1_7_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_8_chunk.segment_by_value, PARTIAL sum(_hyper_1_8_chunk.segment_by_value)
                     Group Key: _hyper_1_8_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                           Output: _hyper_1_8_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_9_chunk.segment_by_value, PARTIAL sum(_hyper_1_9_chunk.segment_by_value)
                     Group Key: _hyper_1_9_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                           Output: _hyper_1_9_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_10_chunk.segment_by_value, PARTIAL sum(_hyper_1_10_chunk.segment_by_value)
                     Group Key: _hyper_1_10_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                           Output: _hyper_1_10_chunk.segment_by_value

SELECT segment_by_value, sum(segment_by_value) FROM testtable GROUP BY segment_by_value ORDER BY 1, 2;
 segment_by_value | sum  
------------------+------
              -10 | -610
               -9 | -549
               -8 | -488
               -7 | -427
               -6 | -366
               -5 | -305
               -4 | -244
               -3 | -183
               -2 | -122
               -1 |  -61
                0 |    0
                1 |   61
                2 |  122
                3 |  183
                4 |  244
                5 |  305
                6 |  366
                7 |  427
                8 |  488
                9 |  549
               10 |  610
               11 |  671
               12 |  732
               13 |  793
               14 |  854
               15 |  915
               16 |  976
               17 | 1037
               18 | 1098
               19 | 1159
               20 | 1220
               21 | 1281
               22 | 1342
               23 | 1403
               24 | 1464
               25 | 1525
               26 | 1586
               27 | 1647
               28 | 1708
               29 | 1769
               30 | 1830
               31 | 1891
               32 | 1952
               33 | 2013
               34 | 2074
               35 | 2135
               36 | 2196
               37 | 2257
               38 | 2318
               39 | 2379
               40 | 2440
               41 | 2501
               42 | 2562
               43 | 2623
               44 | 2684
               45 | 2745
               46 | 2806
               47 | 2867
               48 | 2928
               49 | 2989
               50 | 3050
               51 | 3111
               52 | 3172
               53 | 3233
               54 | 3294
               55 | 3355
               56 | 3416
               57 | 3477
               58 | 3538
               59 | 3599
               60 | 3660
               61 | 3721
               62 | 3782
               63 | 3843
               64 | 3904
               65 | 3965
               66 | 4026
               67 | 4087
               68 | 4148
               69 | 4209
               70 | 4270
               71 | 4331
               72 | 4392
               73 | 4453
               74 | 4514
               75 | 4575
               76 | 4636
               77 | 4697
               78 | 4758
               79 | 4819
               80 | 4880
               81 | 4941
               82 | 5002
               83 | 5063
               84 | 5124
               85 | 5185
               86 | 5246
               87 | 5307
               88 | 5368
               89 | 5429
               90 | 5490
               91 | 5551
               92 | 5612
               93 | 5673
               94 | 5734
               95 | 5795
               96 | 5856
               97 | 5917
               98 | 5978
               99 | 6039
              100 | 6100

:EXPLAIN
SELECT segment_by_value FROM testtable GROUP BY segment_by_value ORDER BY 1;
--- QUERY PLAN ---
 Sort
   Output: testtable.segment_by_value
   Sort Key: testtable.segment_by_value
   ->  Finalize HashAggregate
         Output: testtable.segment_by_value
         Group Key: testtable.segment_by_value
         ->  Append
               ->  Custom Scan (VectorAgg)
                     Output: _hyper_1_1_chunk.segment_by_value
                     Grouping Policy: per compressed batch
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                           Output: _hyper_1_1_chunk.segment_by_value
                           ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                                 Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: _hyper_1_2_chunk.segment_by_value
                     Grouping Policy: per compressed batch
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                           Output: _hyper_1_2_chunk.segment_by_value
                           ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                                 Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: _hyper_1_3_chunk.segment_by_value
                     Grouping Policy: per compressed batch
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                           Output: _hyper_1_3_chunk.segment_by_value
                           ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                                 Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
               ->  Partial HashAggregate
                     Output: _hyper_1_4_chunk.segment_by_value
                     Group Key: _hyper_1_4_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                           Output: _hyper_1_4_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_5_chunk.segment_by_value
                     Group Key: _hyper_1_5_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                           Output: _hyper_1_5_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_6_chunk.segment_by_value
                     Group Key: _hyper_1_6_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                           Output: _hyper_1_6_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_7_chunk.segment_by_value
                     Group Key: _hyper_1_7_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                           Output: _hyper_1_7_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_8_chunk.segment_by_value
                     Group Key: _hyper_1_8_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                           Output: _hyper_1_8_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_9_chunk.segment_by_value
                     Group Key: _hyper_1_9_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                           Output: _hyper_1_9_chunk.segment_by_value
               ->  Partial HashAggregate
                     Output: _hyper_1_10_chunk.segment_by_value
                     Group Key: _hyper_1_10_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                           Output: _hyper_1_10_chunk.segment_by_value

SELECT segment_by_value FROM testtable GROUP BY segment_by_value ORDER BY 1;
 segment_by_value 
------------------
              -10
               -9
               -8
               -7
               -6
               -5
               -4
               -3
               -2
               -1
                0
                1
                2
                3
                4
                5
                6
                7
                8
                9
               10
               11
               12
               13
               14
               15
               16
               17
               18
               19
               20
               21
               22
               23
               24
               25
               26
               27
               28
               29
               30
               31
               32
               33
               34
               35
               36
               37
               38
               39
               40
               41
               42
               43
               44
               45
               46
               47
               48
               49
               50
               51
               52
               53
               54
               55
               56
               57
               58
               59
               60
               61
               62
               63
               64
               65
               66
               67
               68
               69
               70
               71
               72
               73
               74
               75
               76
               77
               78
               79
               80
               81
               82
               83
               84
               85
               86
               87
               88
               89
               90
               91
               92
               93
               94
               95
               96
               97
               98
               99
              100

-- Vectorized aggregation possible
SELECT sum(int_value) FROM testtable;
  sum   
--------
 304695

:EXPLAIN
SELECT sum(int_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.int_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_4_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.int_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_5_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.int_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_6_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.int_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_7_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.int_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_8_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.int_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_9_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.int_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_10_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.int_value

-- Vectorized aggregation possible
SELECT sum(float_value) FROM testtable;
  sum   
--------
 304695

:EXPLAIN
SELECT sum(float_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.float_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.float_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.float_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.float_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.float_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.float_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.float_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_4_chunk.float_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_5_chunk.float_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_6_chunk.float_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_7_chunk.float_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_8_chunk.float_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_9_chunk.float_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_10_chunk.float_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.float_value

---
-- Tests with all chunks compressed
---
SELECT compress_chunk(ch, if_not_compressed => true) FROM show_chunks('testtable') ch;
NOTICE:  chunk "_hyper_1_1_chunk" is already converted to columnstore
NOTICE:  chunk "_hyper_1_2_chunk" is already converted to columnstore
NOTICE:  chunk "_hyper_1_3_chunk" is already converted to columnstore
             compress_chunk              
-----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk
 _timescaledb_internal._hyper_1_2_chunk
 _timescaledb_internal._hyper_1_3_chunk
 _timescaledb_internal._hyper_1_4_chunk
 _timescaledb_internal._hyper_1_5_chunk
 _timescaledb_internal._hyper_1_6_chunk
 _timescaledb_internal._hyper_1_7_chunk
 _timescaledb_internal._hyper_1_8_chunk
 _timescaledb_internal._hyper_1_9_chunk
 _timescaledb_internal._hyper_1_10_chunk

VACUUM ANALYZE testtable;
-- Vectorized aggregation possible
SELECT sum(segment_by_value) FROM testtable;
  sum   
--------
 304695

:EXPLAIN
SELECT sum(segment_by_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_4_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_5_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_6_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_7_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_8_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_9_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_10_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

-- Vectorized aggregation possible
SELECT sum(int_value) FROM testtable;
  sum   
--------
 304695

:EXPLAIN
SELECT sum(int_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.int_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_4_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_5_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_6_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_7_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_8_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_9_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_10_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

---
-- Tests with some chunks are partially compressed
---
INSERT INTO testtable (time, segment_by_value, int_value, float_value)
   VALUES ('1980-01-02 01:00:00-00', 0, 0, 0);
-- Vectorized aggregation possible
SELECT sum(segment_by_value) FROM testtable;
  sum   
--------
 304695

:EXPLAIN
SELECT sum(segment_by_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
                     Chunk Status: PARTIAL
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_4_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_5_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_6_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_7_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_8_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_9_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_10_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

-- Vectorized aggregation possible
SELECT sum(int_value) FROM testtable;
  sum   
--------
 304695

:EXPLAIN
SELECT sum(int_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.int_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
                     Chunk Status: PARTIAL
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_4_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_5_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_6_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_7_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_8_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_9_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_10_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

--Vectorized aggregation not possible for expression
SELECT sum(abs(int_value)) FROM testtable;
  sum   
--------
 311405

:EXPLAIN
SELECT sum(abs(int_value)) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(abs(testtable.int_value))
   ->  Append
         ->  Partial Aggregate
               Output: PARTIAL sum(abs(_hyper_1_1_chunk.int_value))
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
                     Chunk Status: PARTIAL
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(abs(_hyper_1_1_chunk.int_value))
               ->  Seq Scan on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
         ->  Partial Aggregate
               Output: PARTIAL sum(abs(_hyper_1_2_chunk.int_value))
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(abs(_hyper_1_3_chunk.int_value))
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(abs(_hyper_1_4_chunk.int_value))
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(abs(_hyper_1_5_chunk.int_value))
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(abs(_hyper_1_6_chunk.int_value))
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(abs(_hyper_1_7_chunk.int_value))
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(abs(_hyper_1_8_chunk.int_value))
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(abs(_hyper_1_9_chunk.int_value))
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(abs(_hyper_1_10_chunk.int_value))
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

-- Vectorized aggregation NOT possible
SET timescaledb.enable_vectorized_aggregation = OFF;
:EXPLAIN
SELECT sum(int_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.int_value)
   ->  Append
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
                     Chunk Status: PARTIAL
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_2_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_3_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_4_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_5_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_6_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_7_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_8_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_9_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_10_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

RESET timescaledb.enable_vectorized_aggregation;
-- Vectorized aggregation without bulk decompression only possible for
-- segmentby columns.
SET timescaledb.enable_bulk_decompression = OFF;
:EXPLAIN
SELECT sum(int_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.int_value)
   ->  Append
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
                     Chunk Status: PARTIAL
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_2_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_3_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_4_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_5_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_6_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_7_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_8_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_9_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_10_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

:EXPLAIN
SELECT sum(segment_by_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
                     Chunk Status: PARTIAL
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_4_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_5_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_6_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_7_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_8_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_9_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_10_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

SELECT sum(segment_by_value) FROM testtable;
  sum   
--------
 304695

RESET timescaledb.enable_bulk_decompression;
-- Using the same sum function multiple times is supported by vectorization
:EXPLAIN
SELECT sum(int_value), sum(int_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.int_value), sum(testtable.int_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
                     Chunk Status: PARTIAL
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_4_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_5_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_6_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_7_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_8_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_9_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_10_chunk.int_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

-- Using the same sum function multiple times is supported by vectorization
:EXPLAIN
SELECT sum(segment_by_value), sum(segment_by_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value), sum(testtable.segment_by_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
                     Chunk Status: PARTIAL
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_4_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_5_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_6_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_7_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_8_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_9_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_10_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

-- Performing a sum on multiple columns is supported.
:EXPLAIN
SELECT sum(int_value), sum(segment_by_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.int_value), sum(testtable.segment_by_value)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_1_chunk.int_value)), (PARTIAL sum(_hyper_1_1_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value, _hyper_1_1_chunk.segment_by_value
                     Chunk Status: PARTIAL
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.int_value), PARTIAL sum(_hyper_1_1_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value, _hyper_1_1_chunk.segment_by_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_2_chunk.int_value)), (PARTIAL sum(_hyper_1_2_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.int_value, _hyper_1_2_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_3_chunk.int_value)), (PARTIAL sum(_hyper_1_3_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.int_value, _hyper_1_3_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_4_chunk.int_value)), (PARTIAL sum(_hyper_1_4_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.int_value, _hyper_1_4_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_5_chunk.int_value)), (PARTIAL sum(_hyper_1_5_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.int_value, _hyper_1_5_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_6_chunk.int_value)), (PARTIAL sum(_hyper_1_6_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.int_value, _hyper_1_6_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_7_chunk.int_value)), (PARTIAL sum(_hyper_1_7_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.int_value, _hyper_1_7_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_8_chunk.int_value)), (PARTIAL sum(_hyper_1_8_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.int_value, _hyper_1_8_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_9_chunk.int_value)), (PARTIAL sum(_hyper_1_9_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.int_value, _hyper_1_9_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_1_10_chunk.int_value)), (PARTIAL sum(_hyper_1_10_chunk.segment_by_value))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.int_value, _hyper_1_10_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

SELECT sum(int_value), sum(segment_by_value) FROM testtable;
  sum   |  sum   
--------+--------
 304695 | 304695

-- Using the sum function together with another non-vector capable aggregate is not supported
:EXPLAIN
SELECT sum(int_value), bit_or(int_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.int_value), bit_or(testtable.int_value)
   ->  Append
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.int_value), PARTIAL bit_or(_hyper_1_1_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
                     Chunk Status: PARTIAL
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.int_value), PARTIAL bit_or(_hyper_1_1_chunk.int_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.int_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_2_chunk.int_value), PARTIAL bit_or(_hyper_1_2_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_3_chunk.int_value), PARTIAL bit_or(_hyper_1_3_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_4_chunk.int_value), PARTIAL bit_or(_hyper_1_4_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_5_chunk.int_value), PARTIAL bit_or(_hyper_1_5_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_6_chunk.int_value), PARTIAL bit_or(_hyper_1_6_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_7_chunk.int_value), PARTIAL bit_or(_hyper_1_7_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_8_chunk.int_value), PARTIAL bit_or(_hyper_1_8_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_9_chunk.int_value), PARTIAL bit_or(_hyper_1_9_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_10_chunk.int_value), PARTIAL bit_or(_hyper_1_10_chunk.int_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.int_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

-- Using the sum function together with another non-vector capable aggregate is not supported
:EXPLAIN
SELECT sum(segment_by_value), bit_or(segment_by_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value), bit_or(testtable.segment_by_value)
   ->  Append
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.segment_by_value), PARTIAL bit_or(_hyper_1_1_chunk.segment_by_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
                     Chunk Status: PARTIAL
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_11_chunk
                           Output: compress_hyper_2_11_chunk._ts_meta_count, compress_hyper_2_11_chunk.segment_by_value, compress_hyper_2_11_chunk._ts_meta_min_1, compress_hyper_2_11_chunk._ts_meta_max_1, compress_hyper_2_11_chunk."time", compress_hyper_2_11_chunk.int_value, compress_hyper_2_11_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_1_chunk.segment_by_value), PARTIAL bit_or(_hyper_1_1_chunk.segment_by_value)
               ->  Seq Scan on _timescaledb_internal._hyper_1_1_chunk
                     Output: _hyper_1_1_chunk.segment_by_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_2_chunk.segment_by_value), PARTIAL bit_or(_hyper_1_2_chunk.segment_by_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_2_chunk
                     Output: _hyper_1_2_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_12_chunk
                           Output: compress_hyper_2_12_chunk._ts_meta_count, compress_hyper_2_12_chunk.segment_by_value, compress_hyper_2_12_chunk._ts_meta_min_1, compress_hyper_2_12_chunk._ts_meta_max_1, compress_hyper_2_12_chunk."time", compress_hyper_2_12_chunk.int_value, compress_hyper_2_12_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_3_chunk.segment_by_value), PARTIAL bit_or(_hyper_1_3_chunk.segment_by_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
                     Output: _hyper_1_3_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_13_chunk
                           Output: compress_hyper_2_13_chunk._ts_meta_count, compress_hyper_2_13_chunk.segment_by_value, compress_hyper_2_13_chunk._ts_meta_min_1, compress_hyper_2_13_chunk._ts_meta_max_1, compress_hyper_2_13_chunk."time", compress_hyper_2_13_chunk.int_value, compress_hyper_2_13_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_4_chunk.segment_by_value), PARTIAL bit_or(_hyper_1_4_chunk.segment_by_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_4_chunk
                     Output: _hyper_1_4_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_14_chunk
                           Output: compress_hyper_2_14_chunk._ts_meta_count, compress_hyper_2_14_chunk.segment_by_value, compress_hyper_2_14_chunk._ts_meta_min_1, compress_hyper_2_14_chunk._ts_meta_max_1, compress_hyper_2_14_chunk."time", compress_hyper_2_14_chunk.int_value, compress_hyper_2_14_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_5_chunk.segment_by_value), PARTIAL bit_or(_hyper_1_5_chunk.segment_by_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_5_chunk
                     Output: _hyper_1_5_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_15_chunk
                           Output: compress_hyper_2_15_chunk._ts_meta_count, compress_hyper_2_15_chunk.segment_by_value, compress_hyper_2_15_chunk._ts_meta_min_1, compress_hyper_2_15_chunk._ts_meta_max_1, compress_hyper_2_15_chunk."time", compress_hyper_2_15_chunk.int_value, compress_hyper_2_15_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_6_chunk.segment_by_value), PARTIAL bit_or(_hyper_1_6_chunk.segment_by_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_6_chunk
                     Output: _hyper_1_6_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_16_chunk
                           Output: compress_hyper_2_16_chunk._ts_meta_count, compress_hyper_2_16_chunk.segment_by_value, compress_hyper_2_16_chunk._ts_meta_min_1, compress_hyper_2_16_chunk._ts_meta_max_1, compress_hyper_2_16_chunk."time", compress_hyper_2_16_chunk.int_value, compress_hyper_2_16_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_7_chunk.segment_by_value), PARTIAL bit_or(_hyper_1_7_chunk.segment_by_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_7_chunk
                     Output: _hyper_1_7_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_17_chunk
                           Output: compress_hyper_2_17_chunk._ts_meta_count, compress_hyper_2_17_chunk.segment_by_value, compress_hyper_2_17_chunk._ts_meta_min_1, compress_hyper_2_17_chunk._ts_meta_max_1, compress_hyper_2_17_chunk."time", compress_hyper_2_17_chunk.int_value, compress_hyper_2_17_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_8_chunk.segment_by_value), PARTIAL bit_or(_hyper_1_8_chunk.segment_by_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_8_chunk
                     Output: _hyper_1_8_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_18_chunk
                           Output: compress_hyper_2_18_chunk._ts_meta_count, compress_hyper_2_18_chunk.segment_by_value, compress_hyper_2_18_chunk._ts_meta_min_1, compress_hyper_2_18_chunk._ts_meta_max_1, compress_hyper_2_18_chunk."time", compress_hyper_2_18_chunk.int_value, compress_hyper_2_18_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_9_chunk.segment_by_value), PARTIAL bit_or(_hyper_1_9_chunk.segment_by_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_9_chunk
                     Output: _hyper_1_9_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_19_chunk
                           Output: compress_hyper_2_19_chunk._ts_meta_count, compress_hyper_2_19_chunk.segment_by_value, compress_hyper_2_19_chunk._ts_meta_min_1, compress_hyper_2_19_chunk._ts_meta_max_1, compress_hyper_2_19_chunk."time", compress_hyper_2_19_chunk.int_value, compress_hyper_2_19_chunk.float_value
         ->  Partial Aggregate
               Output: PARTIAL sum(_hyper_1_10_chunk.segment_by_value), PARTIAL bit_or(_hyper_1_10_chunk.segment_by_value)
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_10_chunk
                     Output: _hyper_1_10_chunk.segment_by_value
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_2_20_chunk
                           Output: compress_hyper_2_20_chunk._ts_meta_count, compress_hyper_2_20_chunk.segment_by_value, compress_hyper_2_20_chunk._ts_meta_min_1, compress_hyper_2_20_chunk._ts_meta_max_1, compress_hyper_2_20_chunk."time", compress_hyper_2_20_chunk.int_value, compress_hyper_2_20_chunk.float_value

---
-- Tests with only negative values
---
TRUNCATE testtable;
INSERT INTO testtable
SELECT time AS time,
value AS segment_by_value,
value AS int_value,
value AS float_value
FROM
generate_series('1980-01-01 00:00:00-00', '1980-03-01 00:00:00-00', INTERVAL '1 day') AS g1(time),
generate_series(-10, 0, 1) AS g2(value)
ORDER BY time;
-- Aggregation result without any vectorization
SELECT sum(segment_by_value), sum(int_value), sum(float_value) FROM testtable;
  sum  |  sum  |  sum  
-------+-------+-------
 -3355 | -3355 | -3355

SELECT compress_chunk(ch) FROM show_chunks('testtable') ch;
             compress_chunk              
-----------------------------------------
 _timescaledb_internal._hyper_1_21_chunk
 _timescaledb_internal._hyper_1_22_chunk
 _timescaledb_internal._hyper_1_23_chunk
 _timescaledb_internal._hyper_1_24_chunk
 _timescaledb_internal._hyper_1_25_chunk
 _timescaledb_internal._hyper_1_26_chunk
 _timescaledb_internal._hyper_1_27_chunk
 _timescaledb_internal._hyper_1_28_chunk
 _timescaledb_internal._hyper_1_29_chunk
 _timescaledb_internal._hyper_1_30_chunk

-- Aggregation with vectorization
SELECT sum(segment_by_value) FROM testtable;
  sum  
-------
 -3355

SELECT sum(int_value) FROM testtable;
  sum  
-------
 -3355

---
-- Tests with only positive values
---
TRUNCATE testtable;
INSERT INTO testtable
SELECT time AS time,
value AS segment_by_value,
value AS int_value,
value AS float_value
FROM
generate_series('1980-01-01 00:00:00-00', '1980-03-01 00:00:00-00', INTERVAL '1 day') AS g1(time),
generate_series(0, 10, 1) AS g2(value)
ORDER BY time;
-- Aggregation result without any vectorization
SELECT sum(segment_by_value), sum(int_value), sum(float_value) FROM testtable;
 sum  | sum  | sum  
------+------+------
 3355 | 3355 | 3355

SELECT compress_chunk(ch) FROM show_chunks('testtable') ch;
             compress_chunk              
-----------------------------------------
 _timescaledb_internal._hyper_1_41_chunk
 _timescaledb_internal._hyper_1_42_chunk
 _timescaledb_internal._hyper_1_43_chunk
 _timescaledb_internal._hyper_1_44_chunk
 _timescaledb_internal._hyper_1_45_chunk
 _timescaledb_internal._hyper_1_46_chunk
 _timescaledb_internal._hyper_1_47_chunk
 _timescaledb_internal._hyper_1_48_chunk
 _timescaledb_internal._hyper_1_49_chunk
 _timescaledb_internal._hyper_1_50_chunk

-- Aggregation with vectorization
SELECT sum(segment_by_value) FROM testtable;
 sum  
------
 3355

SELECT sum(int_value) FROM testtable;
 sum  
------
 3355

-- Vectorization possible - filter on segment_by
:EXPLAIN
SELECT sum(int_value) FROM testtable WHERE segment_by_value > 5;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.int_value)
   ->  Gather
         Output: (PARTIAL sum(testtable.int_value))
         Workers Planned: 2
         ->  Parallel Append
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_41_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_41_chunk
                           Output: _hyper_1_41_chunk.int_value
                           ->  Parallel Index Scan using compress_hyper_2_51_chunk_segment_by_value__ts_meta_min_1___idx on _timescaledb_internal.compress_hyper_2_51_chunk
                                 Output: compress_hyper_2_51_chunk._ts_meta_count, compress_hyper_2_51_chunk.segment_by_value, compress_hyper_2_51_chunk._ts_meta_min_1, compress_hyper_2_51_chunk._ts_meta_max_1, compress_hyper_2_51_chunk."time", compress_hyper_2_51_chunk.int_value, compress_hyper_2_51_chunk.float_value
                                 Index Cond: (compress_hyper_2_51_chunk.segment_by_value > 5)
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_42_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_42_chunk
                           Output: _hyper_1_42_chunk.int_value
                           ->  Parallel Index Scan using compress_hyper_2_52_chunk_segment_by_value__ts_meta_min_1___idx on _timescaledb_internal.compress_hyper_2_52_chunk
                                 Output: compress_hyper_2_52_chunk._ts_meta_count, compress_hyper_2_52_chunk.segment_by_value, compress_hyper_2_52_chunk._ts_meta_min_1, compress_hyper_2_52_chunk._ts_meta_max_1, compress_hyper_2_52_chunk."time", compress_hyper_2_52_chunk.int_value, compress_hyper_2_52_chunk.float_value
                                 Index Cond: (compress_hyper_2_52_chunk.segment_by_value > 5)
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_43_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_43_chunk
                           Output: _hyper_1_43_chunk.int_value
                           ->  Parallel Index Scan using compress_hyper_2_53_chunk_segment_by_value__ts_meta_min_1___idx on _timescaledb_internal.compress_hyper_2_53_chunk
                                 Output: compress_hyper_2_53_chunk._ts_meta_count, compress_hyper_2_53_chunk.segment_by_value, compress_hyper_2_53_chunk._ts_meta_min_1, compress_hyper_2_53_chunk._ts_meta_max_1, compress_hyper_2_53_chunk."time", compress_hyper_2_53_chunk.int_value, compress_hyper_2_53_chunk.float_value
                                 Index Cond: (compress_hyper_2_53_chunk.segment_by_value > 5)
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_44_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_44_chunk
                           Output: _hyper_1_44_chunk.int_value
                           ->  Parallel Index Scan using compress_hyper_2_54_chunk_segment_by_value__ts_meta_min_1___idx on _timescaledb_internal.compress_hyper_2_54_chunk
                                 Output: compress_hyper_2_54_chunk._ts_meta_count, compress_hyper_2_54_chunk.segment_by_value, compress_hyper_2_54_chunk._ts_meta_min_1, compress_hyper_2_54_chunk._ts_meta_max_1, compress_hyper_2_54_chunk."time", compress_hyper_2_54_chunk.int_value, compress_hyper_2_54_chunk.float_value
                                 Index Cond: (compress_hyper_2_54_chunk.segment_by_value > 5)
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_45_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_45_chunk
                           Output: _hyper_1_45_chunk.int_value
                           ->  Parallel Index Scan using compress_hyper_2_55_chunk_segment_by_value__ts_meta_min_1___idx on _timescaledb_internal.compress_hyper_2_55_chunk
                                 Output: compress_hyper_2_55_chunk._ts_meta_count, compress_hyper_2_55_chunk.segment_by_value, compress_hyper_2_55_chunk._ts_meta_min_1, compress_hyper_2_55_chunk._ts_meta_max_1, compress_hyper_2_55_chunk."time", compress_hyper_2_55_chunk.int_value, compress_hyper_2_55_chunk.float_value
                                 Index Cond: (compress_hyper_2_55_chunk.segment_by_value > 5)
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_46_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_46_chunk
                           Output: _hyper_1_46_chunk.int_value
                           ->  Parallel Index Scan using compress_hyper_2_56_chunk_segment_by_value__ts_meta_min_1___idx on _timescaledb_internal.compress_hyper_2_56_chunk
                                 Output: compress_hyper_2_56_chunk._ts_meta_count, compress_hyper_2_56_chunk.segment_by_value, compress_hyper_2_56_chunk._ts_meta_min_1, compress_hyper_2_56_chunk._ts_meta_max_1, compress_hyper_2_56_chunk."time", compress_hyper_2_56_chunk.int_value, compress_hyper_2_56_chunk.float_value
                                 Index Cond: (compress_hyper_2_56_chunk.segment_by_value > 5)
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_47_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_47_chunk
                           Output: _hyper_1_47_chunk.int_value
                           ->  Parallel Index Scan using compress_hyper_2_57_chunk_segment_by_value__ts_meta_min_1___idx on _timescaledb_internal.compress_hyper_2_57_chunk
                                 Output: compress_hyper_2_57_chunk._ts_meta_count, compress_hyper_2_57_chunk.segment_by_value, compress_hyper_2_57_chunk._ts_meta_min_1, compress_hyper_2_57_chunk._ts_meta_max_1, compress_hyper_2_57_chunk."time", compress_hyper_2_57_chunk.int_value, compress_hyper_2_57_chunk.float_value
                                 Index Cond: (compress_hyper_2_57_chunk.segment_by_value > 5)
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_48_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_48_chunk
                           Output: _hyper_1_48_chunk.int_value
                           ->  Parallel Index Scan using compress_hyper_2_58_chunk_segment_by_value__ts_meta_min_1___idx on _timescaledb_internal.compress_hyper_2_58_chunk
                                 Output: compress_hyper_2_58_chunk._ts_meta_count, compress_hyper_2_58_chunk.segment_by_value, compress_hyper_2_58_chunk._ts_meta_min_1, compress_hyper_2_58_chunk._ts_meta_max_1, compress_hyper_2_58_chunk."time", compress_hyper_2_58_chunk.int_value, compress_hyper_2_58_chunk.float_value
                                 Index Cond: (compress_hyper_2_58_chunk.segment_by_value > 5)
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_49_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_49_chunk
                           Output: _hyper_1_49_chunk.int_value
                           ->  Parallel Index Scan using compress_hyper_2_59_chunk_segment_by_value__ts_meta_min_1___idx on _timescaledb_internal.compress_hyper_2_59_chunk
                                 Output: compress_hyper_2_59_chunk._ts_meta_count, compress_hyper_2_59_chunk.segment_by_value, compress_hyper_2_59_chunk._ts_meta_min_1, compress_hyper_2_59_chunk._ts_meta_max_1, compress_hyper_2_59_chunk."time", compress_hyper_2_59_chunk.int_value, compress_hyper_2_59_chunk.float_value
                                 Index Cond: (compress_hyper_2_59_chunk.segment_by_value > 5)
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_50_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_50_chunk
                           Output: _hyper_1_50_chunk.int_value
                           ->  Parallel Index Scan using compress_hyper_2_60_chunk_segment_by_value__ts_meta_min_1___idx on _timescaledb_internal.compress_hyper_2_60_chunk
                                 Output: compress_hyper_2_60_chunk._ts_meta_count, compress_hyper_2_60_chunk.segment_by_value, compress_hyper_2_60_chunk._ts_meta_min_1, compress_hyper_2_60_chunk._ts_meta_max_1, compress_hyper_2_60_chunk."time", compress_hyper_2_60_chunk.int_value, compress_hyper_2_60_chunk.float_value
                                 Index Cond: (compress_hyper_2_60_chunk.segment_by_value > 5)

SELECT sum(int_value) FROM testtable WHERE segment_by_value > 5;
 sum  
------
 2440

SET timescaledb.enable_vectorized_aggregation = OFF;
SELECT sum(int_value) FROM testtable WHERE segment_by_value > 5;
 sum  
------
 2440

RESET timescaledb.enable_vectorized_aggregation;
SELECT sum(int_value) FROM testtable WHERE segment_by_value > 10;
 sum 
-----
    

SET timescaledb.enable_vectorized_aggregation = OFF;
SELECT sum(int_value) FROM testtable WHERE segment_by_value > 10;
 sum 
-----
    

RESET timescaledb.enable_vectorized_aggregation;
---
-- Tests with parallel plans
---
SET parallel_leader_participation = off;
SET min_parallel_table_scan_size = 0;
SET parallel_setup_cost = 0;
SET parallel_tuple_cost = 0;
:EXPLAIN
SELECT sum(segment_by_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value)
   ->  Gather
         Output: (PARTIAL sum(testtable.segment_by_value))
         Workers Planned: 2
         ->  Parallel Append
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_41_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_41_chunk
                           Output: _hyper_1_41_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_51_chunk
                                 Output: compress_hyper_2_51_chunk._ts_meta_count, compress_hyper_2_51_chunk.segment_by_value, compress_hyper_2_51_chunk._ts_meta_min_1, compress_hyper_2_51_chunk._ts_meta_max_1, compress_hyper_2_51_chunk."time", compress_hyper_2_51_chunk.int_value, compress_hyper_2_51_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_42_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_42_chunk
                           Output: _hyper_1_42_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_52_chunk
                                 Output: compress_hyper_2_52_chunk._ts_meta_count, compress_hyper_2_52_chunk.segment_by_value, compress_hyper_2_52_chunk._ts_meta_min_1, compress_hyper_2_52_chunk._ts_meta_max_1, compress_hyper_2_52_chunk."time", compress_hyper_2_52_chunk.int_value, compress_hyper_2_52_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_43_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_43_chunk
                           Output: _hyper_1_43_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_53_chunk
                                 Output: compress_hyper_2_53_chunk._ts_meta_count, compress_hyper_2_53_chunk.segment_by_value, compress_hyper_2_53_chunk._ts_meta_min_1, compress_hyper_2_53_chunk._ts_meta_max_1, compress_hyper_2_53_chunk."time", compress_hyper_2_53_chunk.int_value, compress_hyper_2_53_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_44_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_44_chunk
                           Output: _hyper_1_44_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_54_chunk
                                 Output: compress_hyper_2_54_chunk._ts_meta_count, compress_hyper_2_54_chunk.segment_by_value, compress_hyper_2_54_chunk._ts_meta_min_1, compress_hyper_2_54_chunk._ts_meta_max_1, compress_hyper_2_54_chunk."time", compress_hyper_2_54_chunk.int_value, compress_hyper_2_54_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_45_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_45_chunk
                           Output: _hyper_1_45_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_55_chunk
                                 Output: compress_hyper_2_55_chunk._ts_meta_count, compress_hyper_2_55_chunk.segment_by_value, compress_hyper_2_55_chunk._ts_meta_min_1, compress_hyper_2_55_chunk._ts_meta_max_1, compress_hyper_2_55_chunk."time", compress_hyper_2_55_chunk.int_value, compress_hyper_2_55_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_46_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_46_chunk
                           Output: _hyper_1_46_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_56_chunk
                                 Output: compress_hyper_2_56_chunk._ts_meta_count, compress_hyper_2_56_chunk.segment_by_value, compress_hyper_2_56_chunk._ts_meta_min_1, compress_hyper_2_56_chunk._ts_meta_max_1, compress_hyper_2_56_chunk."time", compress_hyper_2_56_chunk.int_value, compress_hyper_2_56_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_47_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_47_chunk
                           Output: _hyper_1_47_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_57_chunk
                                 Output: compress_hyper_2_57_chunk._ts_meta_count, compress_hyper_2_57_chunk.segment_by_value, compress_hyper_2_57_chunk._ts_meta_min_1, compress_hyper_2_57_chunk._ts_meta_max_1, compress_hyper_2_57_chunk."time", compress_hyper_2_57_chunk.int_value, compress_hyper_2_57_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_48_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_48_chunk
                           Output: _hyper_1_48_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_58_chunk
                                 Output: compress_hyper_2_58_chunk._ts_meta_count, compress_hyper_2_58_chunk.segment_by_value, compress_hyper_2_58_chunk._ts_meta_min_1, compress_hyper_2_58_chunk._ts_meta_max_1, compress_hyper_2_58_chunk."time", compress_hyper_2_58_chunk.int_value, compress_hyper_2_58_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_49_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_49_chunk
                           Output: _hyper_1_49_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_59_chunk
                                 Output: compress_hyper_2_59_chunk._ts_meta_count, compress_hyper_2_59_chunk.segment_by_value, compress_hyper_2_59_chunk._ts_meta_min_1, compress_hyper_2_59_chunk._ts_meta_max_1, compress_hyper_2_59_chunk."time", compress_hyper_2_59_chunk.int_value, compress_hyper_2_59_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_50_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_50_chunk
                           Output: _hyper_1_50_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_60_chunk
                                 Output: compress_hyper_2_60_chunk._ts_meta_count, compress_hyper_2_60_chunk.segment_by_value, compress_hyper_2_60_chunk._ts_meta_min_1, compress_hyper_2_60_chunk._ts_meta_max_1, compress_hyper_2_60_chunk."time", compress_hyper_2_60_chunk.int_value, compress_hyper_2_60_chunk.float_value

SELECT sum(segment_by_value) FROM testtable;
 sum  
------
 3355

RESET parallel_leader_participation;
RESET min_parallel_table_scan_size;
RESET parallel_setup_cost;
RESET parallel_tuple_cost;
---
-- Tests with only zero values
---
TRUNCATE testtable;
INSERT INTO testtable
SELECT time AS time,
0 AS segment_by_value,
0 AS int_value,
0 AS float_value
FROM
generate_series('1980-01-01 00:00:00-00', '1980-03-01 00:00:00-00', INTERVAL '1 day') AS g1(time)
ORDER BY time;
-- Aggregation result without any vectorization
SELECT sum(segment_by_value), sum(int_value), sum(float_value) FROM testtable;
 sum | sum | sum 
-----+-----+-----
   0 |   0 |   0

SELECT compress_chunk(ch) FROM show_chunks('testtable') ch;
             compress_chunk              
-----------------------------------------
 _timescaledb_internal._hyper_1_61_chunk
 _timescaledb_internal._hyper_1_62_chunk
 _timescaledb_internal._hyper_1_63_chunk
 _timescaledb_internal._hyper_1_64_chunk
 _timescaledb_internal._hyper_1_65_chunk
 _timescaledb_internal._hyper_1_66_chunk
 _timescaledb_internal._hyper_1_67_chunk
 _timescaledb_internal._hyper_1_68_chunk
 _timescaledb_internal._hyper_1_69_chunk
 _timescaledb_internal._hyper_1_70_chunk

-- Aggregation with vectorization
SELECT sum(segment_by_value) FROM testtable;
 sum 
-----
   0

SELECT sum(int_value) FROM testtable;
 sum 
-----
   0

---
-- Tests with null values
---
TRUNCATE testtable;
INSERT INTO testtable
SELECT time AS time,
value AS segment_by_value,
value AS int_value,
value AS float_value
FROM
generate_series('1980-01-01 00:00:00-00', '1980-03-01 00:00:00-00', INTERVAL '1 day') AS g1(time),
generate_series(0, 10, 1) AS g2(value)
ORDER BY time;
-- NULL values for compressed data
INSERT INTO testtable
SELECT time AS time,
value AS segment_by_value,
NULL AS int_value,
NULL AS float_value
FROM
generate_series('1980-01-01 00:00:00-00', '1980-03-01 00:00:00-00', INTERVAL '1 day') AS g1(time),
generate_series(0, 5, 1) AS g2(value)
ORDER BY time;
-- NULL values for segment_by
INSERT INTO testtable
SELECT time AS time,
NULL AS segment_by_value,
value AS int_value,
value AS float_value
FROM
generate_series('1980-01-01 00:00:00-00', '1980-03-01 00:00:00-00', INTERVAL '1 day') AS g1(time),
generate_series(0, 2, 1) AS g2(value)
ORDER BY time;
-- Aggregation result without any vectorization
SELECT sum(segment_by_value), sum(int_value), sum(float_value) FROM testtable;
 sum  | sum  | sum  
------+------+------
 4270 | 3538 | 3538

SELECT compress_chunk(ch) FROM show_chunks('testtable') ch;
             compress_chunk              
-----------------------------------------
 _timescaledb_internal._hyper_1_81_chunk
 _timescaledb_internal._hyper_1_82_chunk
 _timescaledb_internal._hyper_1_83_chunk
 _timescaledb_internal._hyper_1_84_chunk
 _timescaledb_internal._hyper_1_85_chunk
 _timescaledb_internal._hyper_1_86_chunk
 _timescaledb_internal._hyper_1_87_chunk
 _timescaledb_internal._hyper_1_88_chunk
 _timescaledb_internal._hyper_1_89_chunk
 _timescaledb_internal._hyper_1_90_chunk

-- Aggregation with vectorization
:EXPLAIN
SELECT sum(segment_by_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value)
   ->  Gather
         Output: (PARTIAL sum(testtable.segment_by_value))
         Workers Planned: 2
         ->  Parallel Append
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_81_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_81_chunk
                           Output: _hyper_1_81_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_91_chunk
                                 Output: compress_hyper_2_91_chunk._ts_meta_count, compress_hyper_2_91_chunk.segment_by_value, compress_hyper_2_91_chunk._ts_meta_min_1, compress_hyper_2_91_chunk._ts_meta_max_1, compress_hyper_2_91_chunk."time", compress_hyper_2_91_chunk.int_value, compress_hyper_2_91_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_82_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_82_chunk
                           Output: _hyper_1_82_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_92_chunk
                                 Output: compress_hyper_2_92_chunk._ts_meta_count, compress_hyper_2_92_chunk.segment_by_value, compress_hyper_2_92_chunk._ts_meta_min_1, compress_hyper_2_92_chunk._ts_meta_max_1, compress_hyper_2_92_chunk."time", compress_hyper_2_92_chunk.int_value, compress_hyper_2_92_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_83_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_83_chunk
                           Output: _hyper_1_83_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_93_chunk
                                 Output: compress_hyper_2_93_chunk._ts_meta_count, compress_hyper_2_93_chunk.segment_by_value, compress_hyper_2_93_chunk._ts_meta_min_1, compress_hyper_2_93_chunk._ts_meta_max_1, compress_hyper_2_93_chunk."time", compress_hyper_2_93_chunk.int_value, compress_hyper_2_93_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_84_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_84_chunk
                           Output: _hyper_1_84_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_94_chunk
                                 Output: compress_hyper_2_94_chunk._ts_meta_count, compress_hyper_2_94_chunk.segment_by_value, compress_hyper_2_94_chunk._ts_meta_min_1, compress_hyper_2_94_chunk._ts_meta_max_1, compress_hyper_2_94_chunk."time", compress_hyper_2_94_chunk.int_value, compress_hyper_2_94_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_85_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_85_chunk
                           Output: _hyper_1_85_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_95_chunk
                                 Output: compress_hyper_2_95_chunk._ts_meta_count, compress_hyper_2_95_chunk.segment_by_value, compress_hyper_2_95_chunk._ts_meta_min_1, compress_hyper_2_95_chunk._ts_meta_max_1, compress_hyper_2_95_chunk."time", compress_hyper_2_95_chunk.int_value, compress_hyper_2_95_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_86_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_86_chunk
                           Output: _hyper_1_86_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_96_chunk
                                 Output: compress_hyper_2_96_chunk._ts_meta_count, compress_hyper_2_96_chunk.segment_by_value, compress_hyper_2_96_chunk._ts_meta_min_1, compress_hyper_2_96_chunk._ts_meta_max_1, compress_hyper_2_96_chunk."time", compress_hyper_2_96_chunk.int_value, compress_hyper_2_96_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_87_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_87_chunk
                           Output: _hyper_1_87_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_97_chunk
                                 Output: compress_hyper_2_97_chunk._ts_meta_count, compress_hyper_2_97_chunk.segment_by_value, compress_hyper_2_97_chunk._ts_meta_min_1, compress_hyper_2_97_chunk._ts_meta_max_1, compress_hyper_2_97_chunk."time", compress_hyper_2_97_chunk.int_value, compress_hyper_2_97_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_88_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_88_chunk
                           Output: _hyper_1_88_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_98_chunk
                                 Output: compress_hyper_2_98_chunk._ts_meta_count, compress_hyper_2_98_chunk.segment_by_value, compress_hyper_2_98_chunk._ts_meta_min_1, compress_hyper_2_98_chunk._ts_meta_max_1, compress_hyper_2_98_chunk."time", compress_hyper_2_98_chunk.int_value, compress_hyper_2_98_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_89_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_89_chunk
                           Output: _hyper_1_89_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_99_chunk
                                 Output: compress_hyper_2_99_chunk._ts_meta_count, compress_hyper_2_99_chunk.segment_by_value, compress_hyper_2_99_chunk._ts_meta_min_1, compress_hyper_2_99_chunk._ts_meta_max_1, compress_hyper_2_99_chunk."time", compress_hyper_2_99_chunk.int_value, compress_hyper_2_99_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_90_chunk.segment_by_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_90_chunk
                           Output: _hyper_1_90_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_100_chunk
                                 Output: compress_hyper_2_100_chunk._ts_meta_count, compress_hyper_2_100_chunk.segment_by_value, compress_hyper_2_100_chunk._ts_meta_min_1, compress_hyper_2_100_chunk._ts_meta_max_1, compress_hyper_2_100_chunk."time", compress_hyper_2_100_chunk.int_value, compress_hyper_2_100_chunk.float_value

:EXPLAIN
SELECT sum(int_value) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.int_value)
   ->  Gather
         Output: (PARTIAL sum(testtable.int_value))
         Workers Planned: 2
         ->  Parallel Append
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_81_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_81_chunk
                           Output: _hyper_1_81_chunk.int_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_91_chunk
                                 Output: compress_hyper_2_91_chunk._ts_meta_count, compress_hyper_2_91_chunk.segment_by_value, compress_hyper_2_91_chunk._ts_meta_min_1, compress_hyper_2_91_chunk._ts_meta_max_1, compress_hyper_2_91_chunk."time", compress_hyper_2_91_chunk.int_value, compress_hyper_2_91_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_82_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_82_chunk
                           Output: _hyper_1_82_chunk.int_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_92_chunk
                                 Output: compress_hyper_2_92_chunk._ts_meta_count, compress_hyper_2_92_chunk.segment_by_value, compress_hyper_2_92_chunk._ts_meta_min_1, compress_hyper_2_92_chunk._ts_meta_max_1, compress_hyper_2_92_chunk."time", compress_hyper_2_92_chunk.int_value, compress_hyper_2_92_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_83_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_83_chunk
                           Output: _hyper_1_83_chunk.int_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_93_chunk
                                 Output: compress_hyper_2_93_chunk._ts_meta_count, compress_hyper_2_93_chunk.segment_by_value, compress_hyper_2_93_chunk._ts_meta_min_1, compress_hyper_2_93_chunk._ts_meta_max_1, compress_hyper_2_93_chunk."time", compress_hyper_2_93_chunk.int_value, compress_hyper_2_93_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_84_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_84_chunk
                           Output: _hyper_1_84_chunk.int_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_94_chunk
                                 Output: compress_hyper_2_94_chunk._ts_meta_count, compress_hyper_2_94_chunk.segment_by_value, compress_hyper_2_94_chunk._ts_meta_min_1, compress_hyper_2_94_chunk._ts_meta_max_1, compress_hyper_2_94_chunk."time", compress_hyper_2_94_chunk.int_value, compress_hyper_2_94_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_85_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_85_chunk
                           Output: _hyper_1_85_chunk.int_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_95_chunk
                                 Output: compress_hyper_2_95_chunk._ts_meta_count, compress_hyper_2_95_chunk.segment_by_value, compress_hyper_2_95_chunk._ts_meta_min_1, compress_hyper_2_95_chunk._ts_meta_max_1, compress_hyper_2_95_chunk."time", compress_hyper_2_95_chunk.int_value, compress_hyper_2_95_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_86_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_86_chunk
                           Output: _hyper_1_86_chunk.int_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_96_chunk
                                 Output: compress_hyper_2_96_chunk._ts_meta_count, compress_hyper_2_96_chunk.segment_by_value, compress_hyper_2_96_chunk._ts_meta_min_1, compress_hyper_2_96_chunk._ts_meta_max_1, compress_hyper_2_96_chunk."time", compress_hyper_2_96_chunk.int_value, compress_hyper_2_96_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_87_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_87_chunk
                           Output: _hyper_1_87_chunk.int_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_97_chunk
                                 Output: compress_hyper_2_97_chunk._ts_meta_count, compress_hyper_2_97_chunk.segment_by_value, compress_hyper_2_97_chunk._ts_meta_min_1, compress_hyper_2_97_chunk._ts_meta_max_1, compress_hyper_2_97_chunk."time", compress_hyper_2_97_chunk.int_value, compress_hyper_2_97_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_88_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_88_chunk
                           Output: _hyper_1_88_chunk.int_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_98_chunk
                                 Output: compress_hyper_2_98_chunk._ts_meta_count, compress_hyper_2_98_chunk.segment_by_value, compress_hyper_2_98_chunk._ts_meta_min_1, compress_hyper_2_98_chunk._ts_meta_max_1, compress_hyper_2_98_chunk."time", compress_hyper_2_98_chunk.int_value, compress_hyper_2_98_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_89_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_89_chunk
                           Output: _hyper_1_89_chunk.int_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_99_chunk
                                 Output: compress_hyper_2_99_chunk._ts_meta_count, compress_hyper_2_99_chunk.segment_by_value, compress_hyper_2_99_chunk._ts_meta_min_1, compress_hyper_2_99_chunk._ts_meta_max_1, compress_hyper_2_99_chunk."time", compress_hyper_2_99_chunk.int_value, compress_hyper_2_99_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_90_chunk.int_value))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_90_chunk
                           Output: _hyper_1_90_chunk.int_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_100_chunk
                                 Output: compress_hyper_2_100_chunk._ts_meta_count, compress_hyper_2_100_chunk.segment_by_value, compress_hyper_2_100_chunk._ts_meta_min_1, compress_hyper_2_100_chunk._ts_meta_max_1, compress_hyper_2_100_chunk."time", compress_hyper_2_100_chunk.int_value, compress_hyper_2_100_chunk.float_value

SELECT sum(segment_by_value) FROM testtable;
 sum  
------
 4270

SELECT sum(int_value) FROM testtable;
 sum  
------
 3538

-- Vectorizable aggregation filters are supported
:EXPLAIN
SELECT sum(segment_by_value) FILTER (WHERE segment_by_value > 99999) FROM testtable;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable.segment_by_value) FILTER (WHERE (testtable.segment_by_value > 99999))
   ->  Gather
         Output: (PARTIAL sum(testtable.segment_by_value) FILTER (WHERE (testtable.segment_by_value > 99999)))
         Workers Planned: 2
         ->  Parallel Append
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_81_chunk.segment_by_value) FILTER (WHERE (_hyper_1_81_chunk.segment_by_value > 99999)))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_81_chunk
                           Output: _hyper_1_81_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_91_chunk
                                 Output: compress_hyper_2_91_chunk._ts_meta_count, compress_hyper_2_91_chunk.segment_by_value, compress_hyper_2_91_chunk._ts_meta_min_1, compress_hyper_2_91_chunk._ts_meta_max_1, compress_hyper_2_91_chunk."time", compress_hyper_2_91_chunk.int_value, compress_hyper_2_91_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_82_chunk.segment_by_value) FILTER (WHERE (_hyper_1_82_chunk.segment_by_value > 99999)))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_82_chunk
                           Output: _hyper_1_82_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_92_chunk
                                 Output: compress_hyper_2_92_chunk._ts_meta_count, compress_hyper_2_92_chunk.segment_by_value, compress_hyper_2_92_chunk._ts_meta_min_1, compress_hyper_2_92_chunk._ts_meta_max_1, compress_hyper_2_92_chunk."time", compress_hyper_2_92_chunk.int_value, compress_hyper_2_92_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_83_chunk.segment_by_value) FILTER (WHERE (_hyper_1_83_chunk.segment_by_value > 99999)))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_83_chunk
                           Output: _hyper_1_83_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_93_chunk
                                 Output: compress_hyper_2_93_chunk._ts_meta_count, compress_hyper_2_93_chunk.segment_by_value, compress_hyper_2_93_chunk._ts_meta_min_1, compress_hyper_2_93_chunk._ts_meta_max_1, compress_hyper_2_93_chunk."time", compress_hyper_2_93_chunk.int_value, compress_hyper_2_93_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_84_chunk.segment_by_value) FILTER (WHERE (_hyper_1_84_chunk.segment_by_value > 99999)))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_84_chunk
                           Output: _hyper_1_84_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_94_chunk
                                 Output: compress_hyper_2_94_chunk._ts_meta_count, compress_hyper_2_94_chunk.segment_by_value, compress_hyper_2_94_chunk._ts_meta_min_1, compress_hyper_2_94_chunk._ts_meta_max_1, compress_hyper_2_94_chunk."time", compress_hyper_2_94_chunk.int_value, compress_hyper_2_94_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_85_chunk.segment_by_value) FILTER (WHERE (_hyper_1_85_chunk.segment_by_value > 99999)))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_85_chunk
                           Output: _hyper_1_85_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_95_chunk
                                 Output: compress_hyper_2_95_chunk._ts_meta_count, compress_hyper_2_95_chunk.segment_by_value, compress_hyper_2_95_chunk._ts_meta_min_1, compress_hyper_2_95_chunk._ts_meta_max_1, compress_hyper_2_95_chunk."time", compress_hyper_2_95_chunk.int_value, compress_hyper_2_95_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_86_chunk.segment_by_value) FILTER (WHERE (_hyper_1_86_chunk.segment_by_value > 99999)))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_86_chunk
                           Output: _hyper_1_86_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_96_chunk
                                 Output: compress_hyper_2_96_chunk._ts_meta_count, compress_hyper_2_96_chunk.segment_by_value, compress_hyper_2_96_chunk._ts_meta_min_1, compress_hyper_2_96_chunk._ts_meta_max_1, compress_hyper_2_96_chunk."time", compress_hyper_2_96_chunk.int_value, compress_hyper_2_96_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_87_chunk.segment_by_value) FILTER (WHERE (_hyper_1_87_chunk.segment_by_value > 99999)))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_87_chunk
                           Output: _hyper_1_87_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_97_chunk
                                 Output: compress_hyper_2_97_chunk._ts_meta_count, compress_hyper_2_97_chunk.segment_by_value, compress_hyper_2_97_chunk._ts_meta_min_1, compress_hyper_2_97_chunk._ts_meta_max_1, compress_hyper_2_97_chunk."time", compress_hyper_2_97_chunk.int_value, compress_hyper_2_97_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_88_chunk.segment_by_value) FILTER (WHERE (_hyper_1_88_chunk.segment_by_value > 99999)))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_88_chunk
                           Output: _hyper_1_88_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_98_chunk
                                 Output: compress_hyper_2_98_chunk._ts_meta_count, compress_hyper_2_98_chunk.segment_by_value, compress_hyper_2_98_chunk._ts_meta_min_1, compress_hyper_2_98_chunk._ts_meta_max_1, compress_hyper_2_98_chunk."time", compress_hyper_2_98_chunk.int_value, compress_hyper_2_98_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_89_chunk.segment_by_value) FILTER (WHERE (_hyper_1_89_chunk.segment_by_value > 99999)))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_89_chunk
                           Output: _hyper_1_89_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_99_chunk
                                 Output: compress_hyper_2_99_chunk._ts_meta_count, compress_hyper_2_99_chunk.segment_by_value, compress_hyper_2_99_chunk._ts_meta_min_1, compress_hyper_2_99_chunk._ts_meta_max_1, compress_hyper_2_99_chunk."time", compress_hyper_2_99_chunk.int_value, compress_hyper_2_99_chunk.float_value
               ->  Custom Scan (VectorAgg)
                     Output: (PARTIAL sum(_hyper_1_90_chunk.segment_by_value) FILTER (WHERE (_hyper_1_90_chunk.segment_by_value > 99999)))
                     Grouping Policy: all compressed batches
                     ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_90_chunk
                           Output: _hyper_1_90_chunk.segment_by_value
                           ->  Parallel Seq Scan on _timescaledb_internal.compress_hyper_2_100_chunk
                                 Output: compress_hyper_2_100_chunk._ts_meta_count, compress_hyper_2_100_chunk.segment_by_value, compress_hyper_2_100_chunk._ts_meta_min_1, compress_hyper_2_100_chunk._ts_meta_max_1, compress_hyper_2_100_chunk."time", compress_hyper_2_100_chunk.int_value, compress_hyper_2_100_chunk.float_value

SET timescaledb.enable_vectorized_aggregation = OFF;
SELECT sum(segment_by_value) FILTER (WHERE segment_by_value > 99999) FROM testtable;
 sum 
-----
    

RESET timescaledb.enable_vectorized_aggregation;
SELECT sum(segment_by_value) FILTER (WHERE segment_by_value > 99999) FROM testtable;
 sum 
-----
    

---
-- Tests with multiple segment by values
---
CREATE TABLE testtable2 (
time timestamptz NOT NULL,
segment_by_value1 integer NOT NULL,
segment_by_value2 integer NOT NULL,
int_value integer NOT NULL,
float_value double precision NOT NULL);
SELECT FROM create_hypertable(relation=>'testtable2', time_column_name=> 'time');
--

ALTER TABLE testtable2 SET (timescaledb.compress, timescaledb.compress_segmentby='segment_by_value1, segment_by_value2');
INSERT INTO testtable2
SELECT time AS time,
value1 AS segment_by_value1,
value2 AS segment_by_value2,
value1 AS int_value,
value1 AS float_value
FROM
generate_series('1980-01-03 00:00:00-00', '1980-03-04 00:00:00-00', INTERVAL '1 day') AS g1(time),
generate_series(-10, 25, 1) AS g2(value1),
generate_series(-30, 20, 1) AS g3(value2)
ORDER BY time;
-- Aggregation result without any vectorization
SELECT sum(segment_by_value1), sum(segment_by_value2) FROM testtable2;
  sum   |   sum   
--------+---------
 853740 | -569160

SELECT compress_chunk(ch) FROM show_chunks('testtable2') ch;
              compress_chunk              
------------------------------------------
 _timescaledb_internal._hyper_3_101_chunk
 _timescaledb_internal._hyper_3_102_chunk
 _timescaledb_internal._hyper_3_103_chunk
 _timescaledb_internal._hyper_3_104_chunk
 _timescaledb_internal._hyper_3_105_chunk
 _timescaledb_internal._hyper_3_106_chunk
 _timescaledb_internal._hyper_3_107_chunk
 _timescaledb_internal._hyper_3_108_chunk
 _timescaledb_internal._hyper_3_109_chunk

ANALYZE testtable2;
:EXPLAIN
SELECT sum(segment_by_value1) FROM testtable2;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable2.segment_by_value1)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_101_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_101_chunk
                     Output: _hyper_3_101_chunk.segment_by_value1
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_110_chunk
                           Output: compress_hyper_4_110_chunk._ts_meta_count, compress_hyper_4_110_chunk.segment_by_value1, compress_hyper_4_110_chunk.segment_by_value2, compress_hyper_4_110_chunk._ts_meta_min_1, compress_hyper_4_110_chunk._ts_meta_max_1, compress_hyper_4_110_chunk."time", compress_hyper_4_110_chunk.int_value, compress_hyper_4_110_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_102_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_102_chunk
                     Output: _hyper_3_102_chunk.segment_by_value1
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_111_chunk
                           Output: compress_hyper_4_111_chunk._ts_meta_count, compress_hyper_4_111_chunk.segment_by_value1, compress_hyper_4_111_chunk.segment_by_value2, compress_hyper_4_111_chunk._ts_meta_min_1, compress_hyper_4_111_chunk._ts_meta_max_1, compress_hyper_4_111_chunk."time", compress_hyper_4_111_chunk.int_value, compress_hyper_4_111_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_103_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_103_chunk
                     Output: _hyper_3_103_chunk.segment_by_value1
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_112_chunk
                           Output: compress_hyper_4_112_chunk._ts_meta_count, compress_hyper_4_112_chunk.segment_by_value1, compress_hyper_4_112_chunk.segment_by_value2, compress_hyper_4_112_chunk._ts_meta_min_1, compress_hyper_4_112_chunk._ts_meta_max_1, compress_hyper_4_112_chunk."time", compress_hyper_4_112_chunk.int_value, compress_hyper_4_112_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_104_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_104_chunk
                     Output: _hyper_3_104_chunk.segment_by_value1
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_113_chunk
                           Output: compress_hyper_4_113_chunk._ts_meta_count, compress_hyper_4_113_chunk.segment_by_value1, compress_hyper_4_113_chunk.segment_by_value2, compress_hyper_4_113_chunk._ts_meta_min_1, compress_hyper_4_113_chunk._ts_meta_max_1, compress_hyper_4_113_chunk."time", compress_hyper_4_113_chunk.int_value, compress_hyper_4_113_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_105_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_105_chunk
                     Output: _hyper_3_105_chunk.segment_by_value1
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_114_chunk
                           Output: compress_hyper_4_114_chunk._ts_meta_count, compress_hyper_4_114_chunk.segment_by_value1, compress_hyper_4_114_chunk.segment_by_value2, compress_hyper_4_114_chunk._ts_meta_min_1, compress_hyper_4_114_chunk._ts_meta_max_1, compress_hyper_4_114_chunk."time", compress_hyper_4_114_chunk.int_value, compress_hyper_4_114_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_106_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_106_chunk
                     Output: _hyper_3_106_chunk.segment_by_value1
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_115_chunk
                           Output: compress_hyper_4_115_chunk._ts_meta_count, compress_hyper_4_115_chunk.segment_by_value1, compress_hyper_4_115_chunk.segment_by_value2, compress_hyper_4_115_chunk._ts_meta_min_1, compress_hyper_4_115_chunk._ts_meta_max_1, compress_hyper_4_115_chunk."time", compress_hyper_4_115_chunk.int_value, compress_hyper_4_115_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_107_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_107_chunk
                     Output: _hyper_3_107_chunk.segment_by_value1
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_116_chunk
                           Output: compress_hyper_4_116_chunk._ts_meta_count, compress_hyper_4_116_chunk.segment_by_value1, compress_hyper_4_116_chunk.segment_by_value2, compress_hyper_4_116_chunk._ts_meta_min_1, compress_hyper_4_116_chunk._ts_meta_max_1, compress_hyper_4_116_chunk."time", compress_hyper_4_116_chunk.int_value, compress_hyper_4_116_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_108_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_108_chunk
                     Output: _hyper_3_108_chunk.segment_by_value1
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_117_chunk
                           Output: compress_hyper_4_117_chunk._ts_meta_count, compress_hyper_4_117_chunk.segment_by_value1, compress_hyper_4_117_chunk.segment_by_value2, compress_hyper_4_117_chunk._ts_meta_min_1, compress_hyper_4_117_chunk._ts_meta_max_1, compress_hyper_4_117_chunk."time", compress_hyper_4_117_chunk.int_value, compress_hyper_4_117_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_109_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_109_chunk
                     Output: _hyper_3_109_chunk.segment_by_value1
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_118_chunk
                           Output: compress_hyper_4_118_chunk._ts_meta_count, compress_hyper_4_118_chunk.segment_by_value1, compress_hyper_4_118_chunk.segment_by_value2, compress_hyper_4_118_chunk._ts_meta_min_1, compress_hyper_4_118_chunk._ts_meta_max_1, compress_hyper_4_118_chunk."time", compress_hyper_4_118_chunk.int_value, compress_hyper_4_118_chunk.float_value

SELECT sum(segment_by_value1) FROM testtable2;
  sum   
--------
 853740

:EXPLAIN
SELECT sum(segment_by_value2) FROM testtable2;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable2.segment_by_value2)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_101_chunk.segment_by_value2))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_101_chunk
                     Output: _hyper_3_101_chunk.segment_by_value2
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_110_chunk
                           Output: compress_hyper_4_110_chunk._ts_meta_count, compress_hyper_4_110_chunk.segment_by_value1, compress_hyper_4_110_chunk.segment_by_value2, compress_hyper_4_110_chunk._ts_meta_min_1, compress_hyper_4_110_chunk._ts_meta_max_1, compress_hyper_4_110_chunk."time", compress_hyper_4_110_chunk.int_value, compress_hyper_4_110_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_102_chunk.segment_by_value2))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_102_chunk
                     Output: _hyper_3_102_chunk.segment_by_value2
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_111_chunk
                           Output: compress_hyper_4_111_chunk._ts_meta_count, compress_hyper_4_111_chunk.segment_by_value1, compress_hyper_4_111_chunk.segment_by_value2, compress_hyper_4_111_chunk._ts_meta_min_1, compress_hyper_4_111_chunk._ts_meta_max_1, compress_hyper_4_111_chunk."time", compress_hyper_4_111_chunk.int_value, compress_hyper_4_111_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_103_chunk.segment_by_value2))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_103_chunk
                     Output: _hyper_3_103_chunk.segment_by_value2
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_112_chunk
                           Output: compress_hyper_4_112_chunk._ts_meta_count, compress_hyper_4_112_chunk.segment_by_value1, compress_hyper_4_112_chunk.segment_by_value2, compress_hyper_4_112_chunk._ts_meta_min_1, compress_hyper_4_112_chunk._ts_meta_max_1, compress_hyper_4_112_chunk."time", compress_hyper_4_112_chunk.int_value, compress_hyper_4_112_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_104_chunk.segment_by_value2))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_104_chunk
                     Output: _hyper_3_104_chunk.segment_by_value2
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_113_chunk
                           Output: compress_hyper_4_113_chunk._ts_meta_count, compress_hyper_4_113_chunk.segment_by_value1, compress_hyper_4_113_chunk.segment_by_value2, compress_hyper_4_113_chunk._ts_meta_min_1, compress_hyper_4_113_chunk._ts_meta_max_1, compress_hyper_4_113_chunk."time", compress_hyper_4_113_chunk.int_value, compress_hyper_4_113_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_105_chunk.segment_by_value2))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_105_chunk
                     Output: _hyper_3_105_chunk.segment_by_value2
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_114_chunk
                           Output: compress_hyper_4_114_chunk._ts_meta_count, compress_hyper_4_114_chunk.segment_by_value1, compress_hyper_4_114_chunk.segment_by_value2, compress_hyper_4_114_chunk._ts_meta_min_1, compress_hyper_4_114_chunk._ts_meta_max_1, compress_hyper_4_114_chunk."time", compress_hyper_4_114_chunk.int_value, compress_hyper_4_114_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_106_chunk.segment_by_value2))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_106_chunk
                     Output: _hyper_3_106_chunk.segment_by_value2
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_115_chunk
                           Output: compress_hyper_4_115_chunk._ts_meta_count, compress_hyper_4_115_chunk.segment_by_value1, compress_hyper_4_115_chunk.segment_by_value2, compress_hyper_4_115_chunk._ts_meta_min_1, compress_hyper_4_115_chunk._ts_meta_max_1, compress_hyper_4_115_chunk."time", compress_hyper_4_115_chunk.int_value, compress_hyper_4_115_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_107_chunk.segment_by_value2))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_107_chunk
                     Output: _hyper_3_107_chunk.segment_by_value2
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_116_chunk
                           Output: compress_hyper_4_116_chunk._ts_meta_count, compress_hyper_4_116_chunk.segment_by_value1, compress_hyper_4_116_chunk.segment_by_value2, compress_hyper_4_116_chunk._ts_meta_min_1, compress_hyper_4_116_chunk._ts_meta_max_1, compress_hyper_4_116_chunk."time", compress_hyper_4_116_chunk.int_value, compress_hyper_4_116_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_108_chunk.segment_by_value2))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_108_chunk
                     Output: _hyper_3_108_chunk.segment_by_value2
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_117_chunk
                           Output: compress_hyper_4_117_chunk._ts_meta_count, compress_hyper_4_117_chunk.segment_by_value1, compress_hyper_4_117_chunk.segment_by_value2, compress_hyper_4_117_chunk._ts_meta_min_1, compress_hyper_4_117_chunk._ts_meta_max_1, compress_hyper_4_117_chunk."time", compress_hyper_4_117_chunk.int_value, compress_hyper_4_117_chunk.float_value
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_109_chunk.segment_by_value2))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_109_chunk
                     Output: _hyper_3_109_chunk.segment_by_value2
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_4_118_chunk
                           Output: compress_hyper_4_118_chunk._ts_meta_count, compress_hyper_4_118_chunk.segment_by_value1, compress_hyper_4_118_chunk.segment_by_value2, compress_hyper_4_118_chunk._ts_meta_min_1, compress_hyper_4_118_chunk._ts_meta_max_1, compress_hyper_4_118_chunk."time", compress_hyper_4_118_chunk.int_value, compress_hyper_4_118_chunk.float_value

SELECT sum(segment_by_value2) FROM testtable2;
   sum   
---------
 -569160

-- Vectorization possible - filter on segment_by
:EXPLAIN
SELECT sum(segment_by_value1) FROM testtable2 WHERE segment_by_value1 > 0;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable2.segment_by_value1)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_101_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_101_chunk
                     Output: _hyper_3_101_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_110_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_110_chunk
                           Output: compress_hyper_4_110_chunk._ts_meta_count, compress_hyper_4_110_chunk.segment_by_value1, compress_hyper_4_110_chunk.segment_by_value2, compress_hyper_4_110_chunk._ts_meta_min_1, compress_hyper_4_110_chunk._ts_meta_max_1, compress_hyper_4_110_chunk."time", compress_hyper_4_110_chunk.int_value, compress_hyper_4_110_chunk.float_value
                           Index Cond: (compress_hyper_4_110_chunk.segment_by_value1 > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_102_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_102_chunk
                     Output: _hyper_3_102_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_111_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_111_chunk
                           Output: compress_hyper_4_111_chunk._ts_meta_count, compress_hyper_4_111_chunk.segment_by_value1, compress_hyper_4_111_chunk.segment_by_value2, compress_hyper_4_111_chunk._ts_meta_min_1, compress_hyper_4_111_chunk._ts_meta_max_1, compress_hyper_4_111_chunk."time", compress_hyper_4_111_chunk.int_value, compress_hyper_4_111_chunk.float_value
                           Index Cond: (compress_hyper_4_111_chunk.segment_by_value1 > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_103_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_103_chunk
                     Output: _hyper_3_103_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_112_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_112_chunk
                           Output: compress_hyper_4_112_chunk._ts_meta_count, compress_hyper_4_112_chunk.segment_by_value1, compress_hyper_4_112_chunk.segment_by_value2, compress_hyper_4_112_chunk._ts_meta_min_1, compress_hyper_4_112_chunk._ts_meta_max_1, compress_hyper_4_112_chunk."time", compress_hyper_4_112_chunk.int_value, compress_hyper_4_112_chunk.float_value
                           Index Cond: (compress_hyper_4_112_chunk.segment_by_value1 > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_104_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_104_chunk
                     Output: _hyper_3_104_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_113_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_113_chunk
                           Output: compress_hyper_4_113_chunk._ts_meta_count, compress_hyper_4_113_chunk.segment_by_value1, compress_hyper_4_113_chunk.segment_by_value2, compress_hyper_4_113_chunk._ts_meta_min_1, compress_hyper_4_113_chunk._ts_meta_max_1, compress_hyper_4_113_chunk."time", compress_hyper_4_113_chunk.int_value, compress_hyper_4_113_chunk.float_value
                           Index Cond: (compress_hyper_4_113_chunk.segment_by_value1 > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_105_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_105_chunk
                     Output: _hyper_3_105_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_114_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_114_chunk
                           Output: compress_hyper_4_114_chunk._ts_meta_count, compress_hyper_4_114_chunk.segment_by_value1, compress_hyper_4_114_chunk.segment_by_value2, compress_hyper_4_114_chunk._ts_meta_min_1, compress_hyper_4_114_chunk._ts_meta_max_1, compress_hyper_4_114_chunk."time", compress_hyper_4_114_chunk.int_value, compress_hyper_4_114_chunk.float_value
                           Index Cond: (compress_hyper_4_114_chunk.segment_by_value1 > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_106_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_106_chunk
                     Output: _hyper_3_106_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_115_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_115_chunk
                           Output: compress_hyper_4_115_chunk._ts_meta_count, compress_hyper_4_115_chunk.segment_by_value1, compress_hyper_4_115_chunk.segment_by_value2, compress_hyper_4_115_chunk._ts_meta_min_1, compress_hyper_4_115_chunk._ts_meta_max_1, compress_hyper_4_115_chunk."time", compress_hyper_4_115_chunk.int_value, compress_hyper_4_115_chunk.float_value
                           Index Cond: (compress_hyper_4_115_chunk.segment_by_value1 > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_107_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_107_chunk
                     Output: _hyper_3_107_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_116_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_116_chunk
                           Output: compress_hyper_4_116_chunk._ts_meta_count, compress_hyper_4_116_chunk.segment_by_value1, compress_hyper_4_116_chunk.segment_by_value2, compress_hyper_4_116_chunk._ts_meta_min_1, compress_hyper_4_116_chunk._ts_meta_max_1, compress_hyper_4_116_chunk."time", compress_hyper_4_116_chunk.int_value, compress_hyper_4_116_chunk.float_value
                           Index Cond: (compress_hyper_4_116_chunk.segment_by_value1 > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_108_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_108_chunk
                     Output: _hyper_3_108_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_117_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_117_chunk
                           Output: compress_hyper_4_117_chunk._ts_meta_count, compress_hyper_4_117_chunk.segment_by_value1, compress_hyper_4_117_chunk.segment_by_value2, compress_hyper_4_117_chunk._ts_meta_min_1, compress_hyper_4_117_chunk._ts_meta_max_1, compress_hyper_4_117_chunk."time", compress_hyper_4_117_chunk.int_value, compress_hyper_4_117_chunk.float_value
                           Index Cond: (compress_hyper_4_117_chunk.segment_by_value1 > 0)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_109_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_109_chunk
                     Output: _hyper_3_109_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_118_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_118_chunk
                           Output: compress_hyper_4_118_chunk._ts_meta_count, compress_hyper_4_118_chunk.segment_by_value1, compress_hyper_4_118_chunk.segment_by_value2, compress_hyper_4_118_chunk._ts_meta_min_1, compress_hyper_4_118_chunk._ts_meta_max_1, compress_hyper_4_118_chunk."time", compress_hyper_4_118_chunk.int_value, compress_hyper_4_118_chunk.float_value
                           Index Cond: (compress_hyper_4_118_chunk.segment_by_value1 > 0)

:EXPLAIN
SELECT sum(segment_by_value1) FROM testtable2 WHERE segment_by_value1 > 0 AND segment_by_value2 > 0;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable2.segment_by_value1)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_101_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_101_chunk
                     Output: _hyper_3_101_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_110_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_110_chunk
                           Output: compress_hyper_4_110_chunk._ts_meta_count, compress_hyper_4_110_chunk.segment_by_value1, compress_hyper_4_110_chunk.segment_by_value2, compress_hyper_4_110_chunk._ts_meta_min_1, compress_hyper_4_110_chunk._ts_meta_max_1, compress_hyper_4_110_chunk."time", compress_hyper_4_110_chunk.int_value, compress_hyper_4_110_chunk.float_value
                           Index Cond: ((compress_hyper_4_110_chunk.segment_by_value1 > 0) AND (compress_hyper_4_110_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_102_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_102_chunk
                     Output: _hyper_3_102_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_111_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_111_chunk
                           Output: compress_hyper_4_111_chunk._ts_meta_count, compress_hyper_4_111_chunk.segment_by_value1, compress_hyper_4_111_chunk.segment_by_value2, compress_hyper_4_111_chunk._ts_meta_min_1, compress_hyper_4_111_chunk._ts_meta_max_1, compress_hyper_4_111_chunk."time", compress_hyper_4_111_chunk.int_value, compress_hyper_4_111_chunk.float_value
                           Index Cond: ((compress_hyper_4_111_chunk.segment_by_value1 > 0) AND (compress_hyper_4_111_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_103_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_103_chunk
                     Output: _hyper_3_103_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_112_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_112_chunk
                           Output: compress_hyper_4_112_chunk._ts_meta_count, compress_hyper_4_112_chunk.segment_by_value1, compress_hyper_4_112_chunk.segment_by_value2, compress_hyper_4_112_chunk._ts_meta_min_1, compress_hyper_4_112_chunk._ts_meta_max_1, compress_hyper_4_112_chunk."time", compress_hyper_4_112_chunk.int_value, compress_hyper_4_112_chunk.float_value
                           Index Cond: ((compress_hyper_4_112_chunk.segment_by_value1 > 0) AND (compress_hyper_4_112_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_104_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_104_chunk
                     Output: _hyper_3_104_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_113_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_113_chunk
                           Output: compress_hyper_4_113_chunk._ts_meta_count, compress_hyper_4_113_chunk.segment_by_value1, compress_hyper_4_113_chunk.segment_by_value2, compress_hyper_4_113_chunk._ts_meta_min_1, compress_hyper_4_113_chunk._ts_meta_max_1, compress_hyper_4_113_chunk."time", compress_hyper_4_113_chunk.int_value, compress_hyper_4_113_chunk.float_value
                           Index Cond: ((compress_hyper_4_113_chunk.segment_by_value1 > 0) AND (compress_hyper_4_113_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_105_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_105_chunk
                     Output: _hyper_3_105_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_114_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_114_chunk
                           Output: compress_hyper_4_114_chunk._ts_meta_count, compress_hyper_4_114_chunk.segment_by_value1, compress_hyper_4_114_chunk.segment_by_value2, compress_hyper_4_114_chunk._ts_meta_min_1, compress_hyper_4_114_chunk._ts_meta_max_1, compress_hyper_4_114_chunk."time", compress_hyper_4_114_chunk.int_value, compress_hyper_4_114_chunk.float_value
                           Index Cond: ((compress_hyper_4_114_chunk.segment_by_value1 > 0) AND (compress_hyper_4_114_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_106_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_106_chunk
                     Output: _hyper_3_106_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_115_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_115_chunk
                           Output: compress_hyper_4_115_chunk._ts_meta_count, compress_hyper_4_115_chunk.segment_by_value1, compress_hyper_4_115_chunk.segment_by_value2, compress_hyper_4_115_chunk._ts_meta_min_1, compress_hyper_4_115_chunk._ts_meta_max_1, compress_hyper_4_115_chunk."time", compress_hyper_4_115_chunk.int_value, compress_hyper_4_115_chunk.float_value
                           Index Cond: ((compress_hyper_4_115_chunk.segment_by_value1 > 0) AND (compress_hyper_4_115_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_107_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_107_chunk
                     Output: _hyper_3_107_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_116_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_116_chunk
                           Output: compress_hyper_4_116_chunk._ts_meta_count, compress_hyper_4_116_chunk.segment_by_value1, compress_hyper_4_116_chunk.segment_by_value2, compress_hyper_4_116_chunk._ts_meta_min_1, compress_hyper_4_116_chunk._ts_meta_max_1, compress_hyper_4_116_chunk."time", compress_hyper_4_116_chunk.int_value, compress_hyper_4_116_chunk.float_value
                           Index Cond: ((compress_hyper_4_116_chunk.segment_by_value1 > 0) AND (compress_hyper_4_116_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_108_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_108_chunk
                     Output: _hyper_3_108_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_117_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_117_chunk
                           Output: compress_hyper_4_117_chunk._ts_meta_count, compress_hyper_4_117_chunk.segment_by_value1, compress_hyper_4_117_chunk.segment_by_value2, compress_hyper_4_117_chunk._ts_meta_min_1, compress_hyper_4_117_chunk._ts_meta_max_1, compress_hyper_4_117_chunk."time", compress_hyper_4_117_chunk.int_value, compress_hyper_4_117_chunk.float_value
                           Index Cond: ((compress_hyper_4_117_chunk.segment_by_value1 > 0) AND (compress_hyper_4_117_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_109_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_109_chunk
                     Output: _hyper_3_109_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_118_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_118_chunk
                           Output: compress_hyper_4_118_chunk._ts_meta_count, compress_hyper_4_118_chunk.segment_by_value1, compress_hyper_4_118_chunk.segment_by_value2, compress_hyper_4_118_chunk._ts_meta_min_1, compress_hyper_4_118_chunk._ts_meta_max_1, compress_hyper_4_118_chunk."time", compress_hyper_4_118_chunk.int_value, compress_hyper_4_118_chunk.float_value
                           Index Cond: ((compress_hyper_4_118_chunk.segment_by_value1 > 0) AND (compress_hyper_4_118_chunk.segment_by_value2 > 0))

:EXPLAIN
SELECT sum(segment_by_value1) FROM testtable2 WHERE segment_by_value1 > 0 AND segment_by_value2 > 0 AND 2>1;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable2.segment_by_value1)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_101_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_101_chunk
                     Output: _hyper_3_101_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_110_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_110_chunk
                           Output: compress_hyper_4_110_chunk._ts_meta_count, compress_hyper_4_110_chunk.segment_by_value1, compress_hyper_4_110_chunk.segment_by_value2, compress_hyper_4_110_chunk._ts_meta_min_1, compress_hyper_4_110_chunk._ts_meta_max_1, compress_hyper_4_110_chunk."time", compress_hyper_4_110_chunk.int_value, compress_hyper_4_110_chunk.float_value
                           Index Cond: ((compress_hyper_4_110_chunk.segment_by_value1 > 0) AND (compress_hyper_4_110_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_102_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_102_chunk
                     Output: _hyper_3_102_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_111_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_111_chunk
                           Output: compress_hyper_4_111_chunk._ts_meta_count, compress_hyper_4_111_chunk.segment_by_value1, compress_hyper_4_111_chunk.segment_by_value2, compress_hyper_4_111_chunk._ts_meta_min_1, compress_hyper_4_111_chunk._ts_meta_max_1, compress_hyper_4_111_chunk."time", compress_hyper_4_111_chunk.int_value, compress_hyper_4_111_chunk.float_value
                           Index Cond: ((compress_hyper_4_111_chunk.segment_by_value1 > 0) AND (compress_hyper_4_111_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_103_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_103_chunk
                     Output: _hyper_3_103_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_112_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_112_chunk
                           Output: compress_hyper_4_112_chunk._ts_meta_count, compress_hyper_4_112_chunk.segment_by_value1, compress_hyper_4_112_chunk.segment_by_value2, compress_hyper_4_112_chunk._ts_meta_min_1, compress_hyper_4_112_chunk._ts_meta_max_1, compress_hyper_4_112_chunk."time", compress_hyper_4_112_chunk.int_value, compress_hyper_4_112_chunk.float_value
                           Index Cond: ((compress_hyper_4_112_chunk.segment_by_value1 > 0) AND (compress_hyper_4_112_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_104_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_104_chunk
                     Output: _hyper_3_104_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_113_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_113_chunk
                           Output: compress_hyper_4_113_chunk._ts_meta_count, compress_hyper_4_113_chunk.segment_by_value1, compress_hyper_4_113_chunk.segment_by_value2, compress_hyper_4_113_chunk._ts_meta_min_1, compress_hyper_4_113_chunk._ts_meta_max_1, compress_hyper_4_113_chunk."time", compress_hyper_4_113_chunk.int_value, compress_hyper_4_113_chunk.float_value
                           Index Cond: ((compress_hyper_4_113_chunk.segment_by_value1 > 0) AND (compress_hyper_4_113_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_105_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_105_chunk
                     Output: _hyper_3_105_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_114_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_114_chunk
                           Output: compress_hyper_4_114_chunk._ts_meta_count, compress_hyper_4_114_chunk.segment_by_value1, compress_hyper_4_114_chunk.segment_by_value2, compress_hyper_4_114_chunk._ts_meta_min_1, compress_hyper_4_114_chunk._ts_meta_max_1, compress_hyper_4_114_chunk."time", compress_hyper_4_114_chunk.int_value, compress_hyper_4_114_chunk.float_value
                           Index Cond: ((compress_hyper_4_114_chunk.segment_by_value1 > 0) AND (compress_hyper_4_114_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_106_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_106_chunk
                     Output: _hyper_3_106_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_115_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_115_chunk
                           Output: compress_hyper_4_115_chunk._ts_meta_count, compress_hyper_4_115_chunk.segment_by_value1, compress_hyper_4_115_chunk.segment_by_value2, compress_hyper_4_115_chunk._ts_meta_min_1, compress_hyper_4_115_chunk._ts_meta_max_1, compress_hyper_4_115_chunk."time", compress_hyper_4_115_chunk.int_value, compress_hyper_4_115_chunk.float_value
                           Index Cond: ((compress_hyper_4_115_chunk.segment_by_value1 > 0) AND (compress_hyper_4_115_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_107_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_107_chunk
                     Output: _hyper_3_107_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_116_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_116_chunk
                           Output: compress_hyper_4_116_chunk._ts_meta_count, compress_hyper_4_116_chunk.segment_by_value1, compress_hyper_4_116_chunk.segment_by_value2, compress_hyper_4_116_chunk._ts_meta_min_1, compress_hyper_4_116_chunk._ts_meta_max_1, compress_hyper_4_116_chunk."time", compress_hyper_4_116_chunk.int_value, compress_hyper_4_116_chunk.float_value
                           Index Cond: ((compress_hyper_4_116_chunk.segment_by_value1 > 0) AND (compress_hyper_4_116_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_108_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_108_chunk
                     Output: _hyper_3_108_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_117_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_117_chunk
                           Output: compress_hyper_4_117_chunk._ts_meta_count, compress_hyper_4_117_chunk.segment_by_value1, compress_hyper_4_117_chunk.segment_by_value2, compress_hyper_4_117_chunk._ts_meta_min_1, compress_hyper_4_117_chunk._ts_meta_max_1, compress_hyper_4_117_chunk."time", compress_hyper_4_117_chunk.int_value, compress_hyper_4_117_chunk.float_value
                           Index Cond: ((compress_hyper_4_117_chunk.segment_by_value1 > 0) AND (compress_hyper_4_117_chunk.segment_by_value2 > 0))
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_109_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_109_chunk
                     Output: _hyper_3_109_chunk.segment_by_value1
                     ->  Index Scan using compress_hyper_4_118_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_118_chunk
                           Output: compress_hyper_4_118_chunk._ts_meta_count, compress_hyper_4_118_chunk.segment_by_value1, compress_hyper_4_118_chunk.segment_by_value2, compress_hyper_4_118_chunk._ts_meta_min_1, compress_hyper_4_118_chunk._ts_meta_max_1, compress_hyper_4_118_chunk."time", compress_hyper_4_118_chunk.int_value, compress_hyper_4_118_chunk.float_value
                           Index Cond: ((compress_hyper_4_118_chunk.segment_by_value1 > 0) AND (compress_hyper_4_118_chunk.segment_by_value2 > 0))

-- Vectorization not possible filter on segment_by and compressed value
-- Disable parallel worker to get deterministic query plans on i386
SET max_parallel_workers_per_gather = 0;
:EXPLAIN
SELECT sum(segment_by_value1) FROM testtable2 WHERE segment_by_value1 > 1000 AND int_value > 1000;
--- QUERY PLAN ---
 Finalize Aggregate
   Output: sum(testtable2.segment_by_value1)
   ->  Append
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_101_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_101_chunk
                     Output: _hyper_3_101_chunk.segment_by_value1
                     Vectorized Filter: (_hyper_3_101_chunk.int_value > 1000)
                     ->  Index Scan using compress_hyper_4_110_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_110_chunk
                           Output: compress_hyper_4_110_chunk._ts_meta_count, compress_hyper_4_110_chunk.segment_by_value1, compress_hyper_4_110_chunk.segment_by_value2, compress_hyper_4_110_chunk._ts_meta_min_1, compress_hyper_4_110_chunk._ts_meta_max_1, compress_hyper_4_110_chunk."time", compress_hyper_4_110_chunk.int_value, compress_hyper_4_110_chunk.float_value
                           Index Cond: (compress_hyper_4_110_chunk.segment_by_value1 > 1000)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_102_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_102_chunk
                     Output: _hyper_3_102_chunk.segment_by_value1
                     Vectorized Filter: (_hyper_3_102_chunk.int_value > 1000)
                     ->  Index Scan using compress_hyper_4_111_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_111_chunk
                           Output: compress_hyper_4_111_chunk._ts_meta_count, compress_hyper_4_111_chunk.segment_by_value1, compress_hyper_4_111_chunk.segment_by_value2, compress_hyper_4_111_chunk._ts_meta_min_1, compress_hyper_4_111_chunk._ts_meta_max_1, compress_hyper_4_111_chunk."time", compress_hyper_4_111_chunk.int_value, compress_hyper_4_111_chunk.float_value
                           Index Cond: (compress_hyper_4_111_chunk.segment_by_value1 > 1000)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_103_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_103_chunk
                     Output: _hyper_3_103_chunk.segment_by_value1
                     Vectorized Filter: (_hyper_3_103_chunk.int_value > 1000)
                     ->  Index Scan using compress_hyper_4_112_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_112_chunk
                           Output: compress_hyper_4_112_chunk._ts_meta_count, compress_hyper_4_112_chunk.segment_by_value1, compress_hyper_4_112_chunk.segment_by_value2, compress_hyper_4_112_chunk._ts_meta_min_1, compress_hyper_4_112_chunk._ts_meta_max_1, compress_hyper_4_112_chunk."time", compress_hyper_4_112_chunk.int_value, compress_hyper_4_112_chunk.float_value
                           Index Cond: (compress_hyper_4_112_chunk.segment_by_value1 > 1000)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_104_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_104_chunk
                     Output: _hyper_3_104_chunk.segment_by_value1
                     Vectorized Filter: (_hyper_3_104_chunk.int_value > 1000)
                     ->  Index Scan using compress_hyper_4_113_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_113_chunk
                           Output: compress_hyper_4_113_chunk._ts_meta_count, compress_hyper_4_113_chunk.segment_by_value1, compress_hyper_4_113_chunk.segment_by_value2, compress_hyper_4_113_chunk._ts_meta_min_1, compress_hyper_4_113_chunk._ts_meta_max_1, compress_hyper_4_113_chunk."time", compress_hyper_4_113_chunk.int_value, compress_hyper_4_113_chunk.float_value
                           Index Cond: (compress_hyper_4_113_chunk.segment_by_value1 > 1000)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_105_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_105_chunk
                     Output: _hyper_3_105_chunk.segment_by_value1
                     Vectorized Filter: (_hyper_3_105_chunk.int_value > 1000)
                     ->  Index Scan using compress_hyper_4_114_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_114_chunk
                           Output: compress_hyper_4_114_chunk._ts_meta_count, compress_hyper_4_114_chunk.segment_by_value1, compress_hyper_4_114_chunk.segment_by_value2, compress_hyper_4_114_chunk._ts_meta_min_1, compress_hyper_4_114_chunk._ts_meta_max_1, compress_hyper_4_114_chunk."time", compress_hyper_4_114_chunk.int_value, compress_hyper_4_114_chunk.float_value
                           Index Cond: (compress_hyper_4_114_chunk.segment_by_value1 > 1000)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_106_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_106_chunk
                     Output: _hyper_3_106_chunk.segment_by_value1
                     Vectorized Filter: (_hyper_3_106_chunk.int_value > 1000)
                     ->  Index Scan using compress_hyper_4_115_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_115_chunk
                           Output: compress_hyper_4_115_chunk._ts_meta_count, compress_hyper_4_115_chunk.segment_by_value1, compress_hyper_4_115_chunk.segment_by_value2, compress_hyper_4_115_chunk._ts_meta_min_1, compress_hyper_4_115_chunk._ts_meta_max_1, compress_hyper_4_115_chunk."time", compress_hyper_4_115_chunk.int_value, compress_hyper_4_115_chunk.float_value
                           Index Cond: (compress_hyper_4_115_chunk.segment_by_value1 > 1000)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_107_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_107_chunk
                     Output: _hyper_3_107_chunk.segment_by_value1
                     Vectorized Filter: (_hyper_3_107_chunk.int_value > 1000)
                     ->  Index Scan using compress_hyper_4_116_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_116_chunk
                           Output: compress_hyper_4_116_chunk._ts_meta_count, compress_hyper_4_116_chunk.segment_by_value1, compress_hyper_4_116_chunk.segment_by_value2, compress_hyper_4_116_chunk._ts_meta_min_1, compress_hyper_4_116_chunk._ts_meta_max_1, compress_hyper_4_116_chunk."time", compress_hyper_4_116_chunk.int_value, compress_hyper_4_116_chunk.float_value
                           Index Cond: (compress_hyper_4_116_chunk.segment_by_value1 > 1000)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_108_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_108_chunk
                     Output: _hyper_3_108_chunk.segment_by_value1
                     Vectorized Filter: (_hyper_3_108_chunk.int_value > 1000)
                     ->  Index Scan using compress_hyper_4_117_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_117_chunk
                           Output: compress_hyper_4_117_chunk._ts_meta_count, compress_hyper_4_117_chunk.segment_by_value1, compress_hyper_4_117_chunk.segment_by_value2, compress_hyper_4_117_chunk._ts_meta_min_1, compress_hyper_4_117_chunk._ts_meta_max_1, compress_hyper_4_117_chunk."time", compress_hyper_4_117_chunk.int_value, compress_hyper_4_117_chunk.float_value
                           Index Cond: (compress_hyper_4_117_chunk.segment_by_value1 > 1000)
         ->  Custom Scan (VectorAgg)
               Output: (PARTIAL sum(_hyper_3_109_chunk.segment_by_value1))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_3_109_chunk
                     Output: _hyper_3_109_chunk.segment_by_value1
                     Vectorized Filter: (_hyper_3_109_chunk.int_value > 1000)
                     ->  Index Scan using compress_hyper_4_118_chunk_segment_by_value1_segment_by_val_idx on _timescaledb_internal.compress_hyper_4_118_chunk
                           Output: compress_hyper_4_118_chunk._ts_meta_count, compress_hyper_4_118_chunk.segment_by_value1, compress_hyper_4_118_chunk.segment_by_value2, compress_hyper_4_118_chunk._ts_meta_min_1, compress_hyper_4_118_chunk._ts_meta_max_1, compress_hyper_4_118_chunk."time", compress_hyper_4_118_chunk.int_value, compress_hyper_4_118_chunk.float_value
                           Index Cond: (compress_hyper_4_118_chunk.segment_by_value1 > 1000)

RESET max_parallel_workers_per_gather;
-- Can't group by a system column
SELECT sum(float_value) FROM testtable2 GROUP BY tableoid ORDER BY 1 LIMIT 1;
  sum  
-------
 82620

-- Postgres versions starting with 16 remove the grouping columns that are
-- equated to a constant. Check that our planning code handles this well.
SELECT sum(float_value), int_value FROM testtable2 WHERE int_value = 1 GROUP BY int_value;
 sum  | int_value 
------+-----------
 3162 |         1

--
-- Test handling of Agg on top of ChunkAppend. This reproduces a crash
-- in the vector agg planning code introduced in commit 947f7f400.
--
CREATE TABLE testtable3 (time timestamptz, location_id int, device_id int, sensor_id int);
SELECT create_hypertable('testtable3', 'time');
    create_hypertable    
-------------------------
 (5,public,testtable3,t)

ALTER TABLE testtable3 SET (timescaledb.compress_orderby='time', timescaledb.compress_segmentby='location_id');
INSERT INTO testtable3 SELECT t, ceil(random() * 20)::int, ceil(random() * 30)::int, ceil(random() * 20)::int FROM generate_series('2024-01-01'::timestamptz, '2024-01-10'::timestamptz, '1h') AS t;
SELECT count(compress_chunk(ch)) FROM show_chunks('testtable3') ch;
 count 
-------
     2

VACUUM FULL ANALYZE testtable3;
EXPLAIN (buffers off, costs off)
SELECT (date_trunc('hour', '2024-01-09'::timestamptz) - interval '1 hour')::timestamp as time,
    TT.location_id as location_id, TT.device_id as device_id, 0 as sensor_id,
    date_trunc('day', current_timestamp) as discovered_date
FROM testtable3 TT
WHERE time >= date_trunc('hour', '2024-01-09'::timestamptz) - interval '1 hour'
GROUP BY TT.location_id, TT.device_id
;
--- QUERY PLAN ---
 Finalize HashAggregate
   Group Key: tt.location_id, tt.device_id
   ->  Custom Scan (ChunkAppend) on testtable3 tt
         Chunks excluded during startup: 1
         ->  Custom Scan (VectorAgg)
               ->  Custom Scan (ColumnarScan) on _hyper_5_120_chunk tt_1
                     Vectorized Filter: ("time" >= (date_trunc('hour'::text, 'Tue Jan 09 00:00:00 2024 PST'::timestamp with time zone) - '@ 1 hour'::interval))
                     ->  Seq Scan on compress_hyper_6_122_chunk
                           Filter: (_ts_meta_max_1 >= (date_trunc('hour'::text, 'Tue Jan 09 00:00:00 2024 PST'::timestamp with time zone) - '@ 1 hour'::interval))

SELECT (date_trunc('hour', '2024-01-09'::timestamptz) - interval '1 hour')::timestamp as time, TT.location_id as location_id, TT.device_id as device_id, 0 as sensor_id, date_trunc('day', current_timestamp) as discovered_date FROM testtable3 TT WHERE time >= date_trunc('hour', '2024-01-09'::timestamptz) - interval '1 hour' GROUP BY TT.location_id, TT.device_id \g :TEST_OUTPUT_DIR/vectorized_aggregation_query_result.out
-- A version that uses DISTINCT instead
EXPLAIN (buffers off, costs off)
SELECT DISTINCT ON (TT.location_id, TT.device_id)
    (date_trunc('hour', '2024-01-09'::timestamptz) - interval '1 hour')::timestamp as time,
    TT.location_id as location_id, TT.device_id as device_id, 0 as sensor_id,
    date_trunc('day', current_timestamp) as discovered_date
FROM testtable3 TT
WHERE time >= date_trunc('hour', '2024-01-09'::timestamptz) - interval '1 hour'
;
--- QUERY PLAN ---
 Unique
   ->  Sort
         Sort Key: tt.location_id, tt.device_id
         ->  Result
               ->  Custom Scan (ChunkAppend) on testtable3 tt
                     Chunks excluded during startup: 1
                     ->  Custom Scan (ColumnarScan) on _hyper_5_120_chunk tt_1
                           Vectorized Filter: ("time" >= (date_trunc('hour'::text, 'Tue Jan 09 00:00:00 2024 PST'::timestamp with time zone) - '@ 1 hour'::interval))
                           ->  Seq Scan on compress_hyper_6_122_chunk
                                 Filter: (_ts_meta_max_1 >= (date_trunc('hour'::text, 'Tue Jan 09 00:00:00 2024 PST'::timestamp with time zone) - '@ 1 hour'::interval))

EXPLAIN (buffers off, costs off)
SELECT DISTINCT ON (TT.location_id, TT.device_id)
    (date_trunc('hour', '2024-01-09'::timestamptz) - interval '1 hour')::timestamp as time,
    TT.location_id as location_id, TT.device_id as device_id, 0 as sensor_id,
    date_trunc('day', current_timestamp) as discovered_date
FROM testtable3 TT
WHERE time >= date_trunc('hour', '2024-01-09'::timestamptz) - interval '1 hour'
\g :TEST_OUTPUT_DIR/vectorized_aggregation_query_result_distinct.out
