-- 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 TEST_BASE_NAME transparent_decompression
SELECT format('include/%s_load.sql', :'TEST_BASE_NAME') AS "TEST_LOAD_NAME",
    format('include/%s_query.sql', :'TEST_BASE_NAME') AS "TEST_QUERY_NAME",
    format('%s/results/%s_results_uncompressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') AS "TEST_RESULTS_UNCOMPRESSED",
    format('%s/results/%s_results_compressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') AS "TEST_RESULTS_COMPRESSED" \gset
SELECT format('\! diff -u %s %s', :'TEST_RESULTS_UNCOMPRESSED', :'TEST_RESULTS_COMPRESSED') AS "DIFF_CMD" \gset
SET work_mem TO '50MB';
SET enable_incremental_sort TO off;
SET timezone TO 'America/Los_Angeles';
-- disable memoize node to avoid flaky results
SET enable_memoize TO 'off';
CREATE TABLE metrics (
    filler_1 int,
    filler_2 int,
    filler_3 int,
    time timestamptz NOT NULL,
    device_id int,
    device_id_peer int,
    v0 int,
    v1 int,
    v2 float,
    v3 float
);
SELECT create_hypertable ('metrics', 'time');
  create_hypertable   
----------------------
 (1,public,metrics,t)

ALTER TABLE metrics
    DROP COLUMN filler_1;
\set INTERVAL 30m
INSERT INTO metrics (time, device_id, device_id_peer, v0, v1, v2, v3)
SELECT time,
    device_id,
    0,
    device_id + 1,
    device_id + 2,
    device_id + 0.5,
    NULL
FROM generate_series('2000-01-01 0:00:00+0'::timestamptz, '2000-01-05 23:55:00+0', (interval :'INTERVAL') / 3) gtime (time),
    generate_series(1, 5, 1) gdevice (device_id);
ALTER TABLE metrics
    DROP COLUMN filler_2;
INSERT INTO metrics (time, device_id, device_id_peer, v0, v1, v2, v3)
SELECT time,
    device_id,
    0,
    device_id - 1,
    device_id + 2,
    device_id + 0.5,
    NULL
FROM generate_series('2000-01-06 0:00:00+0'::timestamptz, '2000-01-12 23:55:00+0', (interval :'INTERVAL') / 2) gtime (time),
    generate_series(1, 5, 1) gdevice (device_id);
ALTER TABLE metrics
    DROP COLUMN filler_3;
INSERT INTO metrics (time, device_id, device_id_peer, v0, v1, v2, v3)
SELECT time,
    device_id,
    0,
    device_id,
    device_id + 2,
    device_id + 0.5,
    NULL
FROM generate_series('2000-01-13 0:00:00+0'::timestamptz, '2000-01-19 23:55:00+0', :'INTERVAL') gtime (time),
    generate_series(1, 5, 1) gdevice (device_id);
VACUUM ANALYZE metrics;
-- create identical hypertable with space partitioning
CREATE TABLE metrics_space (
    filler_1 int,
    filler_2 int,
    filler_3 int,
    time timestamptz NOT NULL,
    device_id int,
    device_id_peer int,
    v0 int,
    v1 float,
    v2 float,
    v3 float
);
SELECT create_hypertable ('metrics_space', 'time', 'device_id', 3);
     create_hypertable      
----------------------------
 (2,public,metrics_space,t)

ALTER TABLE metrics_space
    DROP COLUMN filler_1;
INSERT INTO metrics_space (time, device_id, device_id_peer, v0, v1, v2, v3)
SELECT time,
    device_id,
    0,
    device_id + 1,
    device_id + 2,
    device_id + 0.5,
    NULL
FROM generate_series('2000-01-01 0:00:00+0'::timestamptz, '2000-01-05 23:55:00+0', (interval :'INTERVAL') / 3) gtime (time),
    generate_series(1, 5, 1) gdevice (device_id);
ALTER TABLE metrics_space
    DROP COLUMN filler_2;
INSERT INTO metrics_space (time, device_id, device_id_peer, v0, v1, v2, v3)
SELECT time,
    device_id,
    0,
    device_id + 1,
    device_id + 2,
    device_id + 0.5,
    NULL
FROM generate_series('2000-01-06 0:00:00+0'::timestamptz, '2000-01-12 23:55:00+0', (interval :'INTERVAL') / 2) gtime (time),
    generate_series(1, 5, 1) gdevice (device_id);
ALTER TABLE metrics_space
    DROP COLUMN filler_3;
INSERT INTO metrics_space (time, device_id, device_id_peer, v0, v1, v2, v3)
SELECT time,
    device_id,
    0,
    device_id + 1,
    device_id + 2,
    device_id + 0.5,
    NULL
FROM generate_series('2000-01-13 0:00:00+0'::timestamptz, '2000-01-19 23:55:00+0', :'INTERVAL') gtime (time),
    generate_series(1, 5, 1) gdevice (device_id);
VACUUM ANALYZE metrics_space;
-- run queries on uncompressed hypertable and store result
\set PREFIX ''
\set PREFIX_VERBOSE ''
\set PREFIX_NO_ANALYZE ''
\set ECHO none
-- compress first and last chunk on the hypertable
ALTER TABLE metrics SET (timescaledb.compress, timescaledb.compress_orderby = 'v0, v1 desc, time', timescaledb.compress_segmentby = 'device_id,device_id_peer');
select compress_chunk(x)
from (select row_number() over (order by x) n, x from show_chunks('metrics') x) t
where n in (1, 3)
;
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk
 _timescaledb_internal._hyper_1_3_chunk

VACUUM ANALYZE metrics;
-- compress some chunks on space partitioned hypertable
-- we compress all chunks of first time slice, none of second, and 2 of the last time slice
ALTER TABLE metrics_space SET (timescaledb.compress, timescaledb.compress_orderby = 'v0, v1 desc, time', timescaledb.compress_segmentby = 'device_id,device_id_peer');
select compress_chunk(x)
from (select row_number() over (order by x) n, x from show_chunks('metrics_space') x) t
where n in (1, 2, 3, 7, 8)
;
             compress_chunk              
-----------------------------------------
 _timescaledb_internal._hyper_2_4_chunk
 _timescaledb_internal._hyper_2_5_chunk
 _timescaledb_internal._hyper_2_6_chunk
 _timescaledb_internal._hyper_2_10_chunk
 _timescaledb_internal._hyper_2_11_chunk

SELECT ht.schema_name || '.' || ht.table_name AS "METRICS_COMPRESSED"
FROM _timescaledb_catalog.hypertable ht
    INNER JOIN _timescaledb_catalog.hypertable ht2 ON ht.id = ht2.compressed_hypertable_id
        AND ht2.table_name = 'metrics' \gset
SELECT ht.schema_name || '.' || ht.table_name AS "METRICS_SPACE_COMPRESSED"
FROM _timescaledb_catalog.hypertable ht
    INNER JOIN _timescaledb_catalog.hypertable ht2 ON ht.id = ht2.compressed_hypertable_id
        AND ht2.table_name = 'metrics_space' \gset
\c :TEST_DBNAME :ROLE_SUPERUSER
-- Index created using query saved in variable used because there was
-- no standard way to create an index on a compressed table.
-- Once a standard way exists, modify this test to use that method.
\c :TEST_DBNAME :ROLE_DEFAULT_PERM_USER
SET timezone TO 'America/Los_Angeles';
CREATE INDEX ON metrics_space (device_id, device_id_peer, v0, v1 DESC, time);
CREATE INDEX ON metrics_space (device_id, device_id_peer DESC, v0, v1 DESC, time);
CREATE INDEX ON metrics_space (device_id DESC, device_id_peer DESC, v0, v1 DESC, time);
VACUUM ANALYZE metrics_space;
SET enable_incremental_sort TO off;
-- run queries on compressed hypertable and store result
\set PREFIX ''
\set PREFIX_VERBOSE ''
\set PREFIX_NO_ANALYZE ''
\set ECHO none
\set PREFIX 'EXPLAIN (analyze, buffers off, costs off, timing off, summary off)'
\set PREFIX_VERBOSE 'EXPLAIN (analyze, buffers off, costs off, timing off, summary off, verbose)'
\set PREFIX_NO_ANALYZE 'EXPLAIN (verbose, buffers off, costs off)'
-- we disable parallelism here otherwise EXPLAIN ANALYZE output
-- will be not stable and differ depending on worker assignment
SET max_parallel_workers_per_gather TO 0;
-- get explain for queries on hypertable with compression
\set TEST_TABLE 'metrics'
\ir :TEST_QUERY_NAME
-- 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.
-- this should use DecompressChunk node
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY time
LIMIT 5;
--- QUERY PLAN ---
 Limit (actual rows=5.00 loops=1)
   Output: metrics."time", metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1, metrics.v2, metrics.v3
   ->  Custom Scan (ChunkAppend) on public.metrics (actual rows=5.00 loops=1)
         Output: metrics."time", metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1, metrics.v2, metrics.v3
         Order: metrics."time"
         Startup Exclusion: false
         Runtime Exclusion: false
         ->  Sort (actual rows=5.00 loops=1)
               Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id, _hyper_1_1_chunk.device_id_peer, _hyper_1_1_chunk.v0, _hyper_1_1_chunk.v1, _hyper_1_1_chunk.v2, _hyper_1_1_chunk.v3
               Sort Key: _hyper_1_1_chunk."time"
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=720.00 loops=1)
                     Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id, _hyper_1_1_chunk.device_id_peer, _hyper_1_1_chunk.v0, _hyper_1_1_chunk.v1, _hyper_1_1_chunk.v2, _hyper_1_1_chunk.v3
                     Bulk Decompression: true
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                           Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
                           Filter: (compress_hyper_5_15_chunk.device_id = 1)
                           Rows Removed by Filter: 4
         ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _timescaledb_internal._hyper_1_2_chunk (never executed)
               Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
               Filter: (_hyper_1_2_chunk.device_id = 1)
         ->  Sort (never executed)
               Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
               Sort Key: _hyper_1_3_chunk."time"
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (never executed)
                     Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
                     Bulk Decompression: true
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (never executed)
                           Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
                           Filter: (compress_hyper_5_16_chunk.device_id = 1)

-- test RECORD by itself
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics (actual rows=1728.00 loops=1)
   Order: metrics."time"
   ->  Sort (actual rows=720.00 loops=1)
         Sort Key: _hyper_1_1_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
               ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Rows Removed by Filter: 4
   ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=672.00 loops=1)
         Filter: (device_id = 1)
         Rows Removed by Filter: 2688
   ->  Sort (actual rows=336.00 loops=1)
         Sort Key: _hyper_1_3_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=336.00 loops=1)
               ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Rows Removed by Filter: 4

-- test empty targetlist
:PREFIX
SELECT
FROM :TEST_TABLE;
--- QUERY PLAN ---
 Append (actual rows=8640.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
         ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
   ->  Seq Scan on _hyper_1_2_chunk (actual rows=3360.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
         ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)

-- test empty resultset
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id < 0;
--- QUERY PLAN ---
 Append (actual rows=0.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=0.00 loops=1)
         ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=0.00 loops=1)
               Filter: (device_id < 0)
               Rows Removed by Filter: 5
   ->  Seq Scan on _hyper_1_2_chunk (actual rows=0.00 loops=1)
         Filter: (device_id < 0)
         Rows Removed by Filter: 3360
   ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=0.00 loops=1)
         ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=0.00 loops=1)
               Filter: (device_id < 0)
               Rows Removed by Filter: 5

-- test targetlist not referencing columns
:PREFIX
SELECT 1
FROM :TEST_TABLE;
--- QUERY PLAN ---
 Result (actual rows=8640.00 loops=1)
   ->  Append (actual rows=8640.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
               ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
         ->  Seq Scan on _hyper_1_2_chunk (actual rows=3360.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
               ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)

-- The following plans are flaky between MergeAppend or Sort + Append.
SET enable_sort = off;
-- test expressions
:PREFIX
SELECT time_bucket ('1d', time),
    v1 + v2 AS "sum",
    COALESCE(NULL, v1, v2) AS "coalesce",
    NULL AS "NULL",
    'text' AS "text",
    :TEST_TABLE AS "RECORD"
FROM :TEST_TABLE
WHERE device_id IN (1, 2)
ORDER BY time,
    device_id
;
--- QUERY PLAN ---
 Sort (actual rows=3456.00 loops=1)
   Sort Key: metrics."time", metrics.device_id
   Sort Method: quicksort 
   ->  Result (actual rows=3456.00 loops=1)
         ->  Append (actual rows=3456.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=1440.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=2.00 loops=1)
                           Filter: (device_id = ANY ('{1,2}'::integer[]))
                           Rows Removed by Filter: 3
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=1344.00 loops=1)
                     Filter: (device_id = ANY ('{1,2}'::integer[]))
                     Rows Removed by Filter: 2016
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=672.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=2.00 loops=1)
                           Filter: (device_id = ANY ('{1,2}'::integer[]))
                           Rows Removed by Filter: 3

-- test constraints not present in targetlist
:PREFIX
SELECT v1
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY v1;
--- QUERY PLAN ---
 Sort (actual rows=1728.00 loops=1)
   Sort Key: metrics.v1
   Sort Method: quicksort 
   ->  Append (actual rows=1728.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
               ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Rows Removed by Filter: 4
         ->  Seq Scan on _hyper_1_2_chunk (actual rows=672.00 loops=1)
               Filter: (device_id = 1)
               Rows Removed by Filter: 2688
         ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=336.00 loops=1)
               ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Rows Removed by Filter: 4

-- test order not present in targetlist
:PREFIX
SELECT v2
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY v1;
--- QUERY PLAN ---
 Sort (actual rows=1728.00 loops=1)
   Sort Key: metrics.v1
   Sort Method: quicksort 
   ->  Append (actual rows=1728.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
               ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Rows Removed by Filter: 4
         ->  Seq Scan on _hyper_1_2_chunk (actual rows=672.00 loops=1)
               Filter: (device_id = 1)
               Rows Removed by Filter: 2688
         ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=336.00 loops=1)
               ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Rows Removed by Filter: 4

-- test column with all NULL
:PREFIX
SELECT v3
FROM :TEST_TABLE
WHERE device_id = 1;
--- QUERY PLAN ---
 Append (actual rows=1728.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
         ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
               Filter: (device_id = 1)
               Rows Removed by Filter: 4
   ->  Seq Scan on _hyper_1_2_chunk (actual rows=672.00 loops=1)
         Filter: (device_id = 1)
         Rows Removed by Filter: 2688
   ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=336.00 loops=1)
         ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
               Filter: (device_id = 1)
               Rows Removed by Filter: 4

--
-- test qual pushdown
--
-- v3 is not segment by or order by column so should not be pushed down
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE v3 > 10.0
ORDER BY time,
    device_id;
--- QUERY PLAN ---
 Sort (actual rows=0.00 loops=1)
   Output: metrics."time", metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1, metrics.v2, metrics.v3
   Sort Key: metrics."time", metrics.device_id
   Sort Method: quicksort 
   ->  Append (actual rows=0.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=0.00 loops=1)
               Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id, _hyper_1_1_chunk.device_id_peer, _hyper_1_1_chunk.v0, _hyper_1_1_chunk.v1, _hyper_1_1_chunk.v2, _hyper_1_1_chunk.v3
               Vectorized Filter: (_hyper_1_1_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 3600
               Batches Removed by Filter: 5
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                     Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=0.00 loops=1)
               Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
               Filter: (_hyper_1_2_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 3360
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=0.00 loops=1)
               Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
               Vectorized Filter: (_hyper_1_3_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 1680
               Batches Removed by Filter: 5
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3

-- device_id constraint should be pushed down
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time"
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time"
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)
                           Rows Removed by Filter: 4
         ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed)
               Filter: (device_id = 1)
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time"
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: (device_id = 1)

RESET enable_sort;
-- test IS NULL / IS NOT NULL
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id IS NOT NULL
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                           Filter: (device_id IS NOT NULL)
         ->  Sort (never executed)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               ->  Seq Scan on _hyper_1_2_chunk (never executed)
                     Filter: (device_id IS NOT NULL)
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: (device_id IS NOT NULL)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id IS NULL
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=0.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=0.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=0.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=0.00 loops=1)
                           Filter: (device_id IS NULL)
                           Rows Removed by Filter: 5
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=0.00 loops=1)
                     Filter: (device_id IS NULL)
                     Rows Removed by Filter: 3360
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=0.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=0.00 loops=1)
                           Filter: (device_id IS NULL)
                           Rows Removed by Filter: 5

-- test IN (Const,Const)
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id IN (1, 2)
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=1440.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=2.00 loops=1)
                           Filter: (device_id = ANY ('{1,2}'::integer[]))
                           Rows Removed by Filter: 3
         ->  Sort (never executed)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               ->  Seq Scan on _hyper_1_2_chunk (never executed)
                     Filter: (device_id = ANY ('{1,2}'::integer[]))
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: (device_id = ANY ('{1,2}'::integer[]))

-- test cast pushdown
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = '1'::text::int
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time"
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time"
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)
                           Rows Removed by Filter: 4
         ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed)
               Filter: (device_id = 1)
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time"
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: (device_id = 1)

--test var op var with two segment by
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = device_id_peer
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=0.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=0.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=0.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=0.00 loops=1)
                           Filter: (device_id = device_id_peer)
                           Rows Removed by Filter: 5
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=0.00 loops=1)
                     Filter: (device_id = device_id_peer)
                     Rows Removed by Filter: 3360
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=0.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=0.00 loops=1)
                           Filter: (device_id = device_id_peer)
                           Rows Removed by Filter: 5

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id_peer < device_id
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                           Filter: (device_id_peer < device_id)
         ->  Sort (never executed)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               ->  Seq Scan on _hyper_1_2_chunk (never executed)
                     Filter: (device_id_peer < device_id)
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: (device_id_peer < device_id)

-- test expressions
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = 1 + 4 / 2
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time"
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time"
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 3)
                           Rows Removed by Filter: 4
         ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed)
               Filter: (device_id = 3)
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time"
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: (device_id = 3)

-- test function calls
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = length(substring(version(), 1, 3))
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 0
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time"
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = length("substring"(version(), 1, 3)))
                           Rows Removed by Filter: 4
         ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed)
               Filter: (device_id = length("substring"(version(), 1, 3)))
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time"
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: (device_id = length("substring"(version(), 1, 3)))

--
-- test segment meta pushdown
--
-- order by column and const
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time = '2000-01-01 1:00:00+0'
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=5.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=5.00 loops=1)
         Vectorized Filter: ("time" = 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
         Rows Removed by Filter: 3595
         ->  Sort (actual rows=5.00 loops=1)
               Sort Key: compress_hyper_5_15_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                     Filter: ((_ts_meta_min_3 <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) AND (_ts_meta_max_3 >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone))

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time < '2000-01-01 1:00:00+0'
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Sort (actual rows=10.00 loops=1)
         Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
         Sort Method: top-N heapsort 
         ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=30.00 loops=1)
               Vectorized Filter: ("time" < 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               Rows Removed by Filter: 3570
               ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                     Filter: (_ts_meta_min_3 < 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time <= '2000-01-01 1:00:00+0'
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Sort (actual rows=10.00 loops=1)
         Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
         Sort Method: top-N heapsort 
         ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=35.00 loops=1)
               Vectorized Filter: ("time" <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               Rows Removed by Filter: 3565
               ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                     Filter: (_ts_meta_min_3 <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time >= '2000-01-01 1:00:00+0'
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3570.00 loops=1)
                     Vectorized Filter: ("time" >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                     Rows Removed by Filter: 30
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                           Filter: (_ts_meta_max_3 >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
         ->  Sort (never executed)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               ->  Seq Scan on _hyper_1_2_chunk (never executed)
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-01 1:00:00+0'
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3565.00 loops=1)
                     Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                     Rows Removed by Filter: 35
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                           Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
         ->  Sort (never executed)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               ->  Seq Scan on _hyper_1_2_chunk (never executed)
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE '2000-01-01 1:00:00+0' < time
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3565.00 loops=1)
                     Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                     Rows Removed by Filter: 35
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                           Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
         ->  Sort (never executed)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               ->  Seq Scan on _hyper_1_2_chunk (never executed)
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)

--pushdowns between order by and segment by columns
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE v0 < 1
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=0.00 loops=1)
                     Vectorized Filter: (v0 < 1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=0.00 loops=1)
                           Filter: (_ts_meta_min_1 < 1)
                           Rows Removed by Filter: 5
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=672.00 loops=1)
                     Filter: (v0 < 1)
                     Rows Removed by Filter: 2688
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     Vectorized Filter: (v0 < 1)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: (_ts_meta_min_1 < 1)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE v0 < device_id
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=0.00 loops=1)
                     Filter: (v0 < device_id)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=0.00 loops=1)
                           Filter: (_ts_meta_min_1 < device_id)
                           Rows Removed by Filter: 5
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=3360.00 loops=1)
                     Filter: (v0 < device_id)
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     Filter: (v0 < device_id)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: (_ts_meta_min_1 < device_id)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id < v0
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
                     Filter: (device_id < v0)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                           Filter: (_ts_meta_max_1 > device_id)
         ->  Sort (never executed)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               ->  Seq Scan on _hyper_1_2_chunk (never executed)
                     Filter: (device_id < v0)
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     Filter: (device_id < v0)
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: (_ts_meta_max_1 > device_id)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE v1 = device_id
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=0.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=0.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=0.00 loops=1)
                     Filter: (v1 = device_id)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=0.00 loops=1)
                           Filter: ((_ts_meta_min_2 <= device_id) AND (_ts_meta_max_2 >= device_id))
                           Rows Removed by Filter: 5
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=0.00 loops=1)
                     Filter: (v1 = device_id)
                     Rows Removed by Filter: 3360
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=0.00 loops=1)
                     Filter: (v1 = device_id)
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=0.00 loops=1)
                           Filter: ((_ts_meta_min_2 <= device_id) AND (_ts_meta_max_2 >= device_id))
                           Rows Removed by Filter: 5

--pushdown between two order by column (not pushed down)
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE v0 = v1
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=0.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=0.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=0.00 loops=1)
                     Filter: (v0 = v1)
                     Rows Removed by Filter: 3600
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=0.00 loops=1)
                     Filter: (v0 = v1)
                     Rows Removed by Filter: 3360
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=0.00 loops=1)
                     Filter: (v0 = v1)
                     Rows Removed by Filter: 1680
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)

--pushdown of quals on order by and segment by cols anded together
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-01 1:00:00+0'
    AND device_id = 1
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   Output: metrics."time", metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1, metrics.v2, metrics.v3
   ->  Custom Scan (ChunkAppend) on public.metrics (actual rows=10.00 loops=1)
         Output: metrics."time", metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1, metrics.v2, metrics.v3
         Order: metrics."time"
         Startup Exclusion: false
         Runtime Exclusion: false
         ->  Sort (actual rows=10.00 loops=1)
               Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id, _hyper_1_1_chunk.device_id_peer, _hyper_1_1_chunk.v0, _hyper_1_1_chunk.v1, _hyper_1_1_chunk.v2, _hyper_1_1_chunk.v3
               Sort Key: _hyper_1_1_chunk."time"
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=713.00 loops=1)
                     Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id, _hyper_1_1_chunk.device_id_peer, _hyper_1_1_chunk.v0, _hyper_1_1_chunk.v1, _hyper_1_1_chunk.v2, _hyper_1_1_chunk.v3
                     Vectorized Filter: (_hyper_1_1_chunk."time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                     Rows Removed by Filter: 7
                     Bulk Decompression: true
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                           Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
                           Filter: ((compress_hyper_5_15_chunk._ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) AND (compress_hyper_5_15_chunk.device_id = 1))
                           Rows Removed by Filter: 4
         ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _timescaledb_internal._hyper_1_2_chunk (never executed)
               Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
               Filter: (_hyper_1_2_chunk.device_id = 1)
         ->  Sort (never executed)
               Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
               Sort Key: _hyper_1_3_chunk."time"
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (never executed)
                     Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
                     Bulk Decompression: true
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (never executed)
                           Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
                           Filter: (compress_hyper_5_16_chunk.device_id = 1)

--pushdown of quals on order by and segment by cols or together (not pushed down)
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-01 1:00:00+0'
    OR device_id = 1
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time", metrics.device_id
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3572.00 loops=1)
                     Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
                     Rows Removed by Filter: 28
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                           Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
         ->  Sort (never executed)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               ->  Seq Scan on _hyper_1_2_chunk (never executed)
                     Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))

--functions are pushed down as well
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time < now()
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time", metrics.device_id
         Chunks excluded during startup: 0
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
                     Vectorized Filter: ("time" < now())
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                           Filter: (_ts_meta_min_3 < now())
         ->  Sort (never executed)
               Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
               ->  Seq Scan on _hyper_1_2_chunk (never executed)
                     Filter: ("time" < now())
         ->  Sort (never executed)
               Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                     Vectorized Filter: ("time" < now())
                     ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                           Filter: (_ts_meta_min_3 < now())

-- test sort optimization interaction
:PREFIX
SELECT time
FROM :TEST_TABLE
ORDER BY time DESC
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time" DESC
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_3_chunk."time" DESC
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
         ->  Index Only Scan using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed)
         ->  Sort (never executed)
               Sort Key: _hyper_1_1_chunk."time" DESC
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_15_chunk (never executed)

:PREFIX
SELECT time,
    device_id
FROM :TEST_TABLE
ORDER BY time DESC,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time" DESC, metrics.device_id
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_3_chunk."time" DESC, _hyper_1_3_chunk.device_id
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
         ->  Sort (never executed)
               Sort Key: _hyper_1_2_chunk."time" DESC, _hyper_1_2_chunk.device_id
               ->  Seq Scan on _hyper_1_2_chunk (never executed)
         ->  Sort (never executed)
               Sort Key: _hyper_1_1_chunk."time" DESC, _hyper_1_1_chunk.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_15_chunk (never executed)

:PREFIX
SELECT time,
    device_id
FROM :TEST_TABLE
ORDER BY device_id,
    time DESC
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Merge Append (actual rows=10.00 loops=1)
         Sort Key: metrics.device_id, metrics."time" DESC
         ->  Sort (actual rows=1.00 loops=1)
               Sort Key: _hyper_1_1_chunk.device_id, _hyper_1_1_chunk."time" DESC
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
         ->  Sort (actual rows=1.00 loops=1)
               Sort Key: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk."time" DESC
               Sort Method: top-N heapsort 
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=3360.00 loops=1)
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_3_chunk.device_id, _hyper_1_3_chunk."time" DESC
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)

--
-- test ordered path
--
-- should not produce ordered path
-- This plan is flaky between MergeAppend over Sorts and Sort over Append
SET enable_sort TO off;
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY time,
    device_id;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on public.metrics (actual rows=3915.00 loops=1)
   Output: metrics."time", metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1, metrics.v2, metrics.v3
   Order: metrics."time", metrics.device_id
   Startup Exclusion: false
   Runtime Exclusion: false
   ->  Sort (actual rows=2235.00 loops=1)
         Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
         Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
         Sort Method: quicksort 
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=2235.00 loops=1)
               Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
               Filter: (_hyper_1_2_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 1125
   ->  Sort (actual rows=1680.00 loops=1)
         Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
         Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=1680.00 loops=1)
               Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3

RESET enable_sort;
-- should produce ordered path
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer,
    v0,
    v1 DESC,
    time;
--- QUERY PLAN ---
 Merge Append (actual rows=3915.00 loops=1)
   Sort Key: metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1 DESC, metrics."time"
   ->  Sort (actual rows=2235.00 loops=1)
         Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
         Sort Key: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1 DESC, _hyper_1_2_chunk."time"
         Sort Method: quicksort 
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=2235.00 loops=1)
               Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
               Filter: (_hyper_1_2_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 1125
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=1680.00 loops=1)
         Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
         Bulk Decompression: true
         ->  Sort (actual rows=5.00 loops=1)
               Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
               Sort Key: compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk._ts_meta_min_2 DESC, compress_hyper_5_16_chunk._ts_meta_max_2 DESC, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3
               Sort Method: quicksort 
               ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3

-- test order by columns not in targetlist
:PREFIX_VERBOSE
SELECT device_id,
    device_id_peer
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer,
    v0,
    v1 DESC,
    time
LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   Output: metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1, metrics."time"
   ->  Merge Append (actual rows=100.00 loops=1)
         Sort Key: metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1 DESC, metrics."time"
         ->  Sort (actual rows=100.00 loops=1)
               Output: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk."time"
               Sort Key: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1 DESC, _hyper_1_2_chunk."time"
               Sort Method: top-N heapsort 
               ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=2235.00 loops=1)
                     Output: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk."time"
                     Filter: (_hyper_1_2_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
                     Rows Removed by Filter: 1125
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=1.00 loops=1)
               Output: _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk."time"
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3

-- test ordering only by segmentby columns
-- should produce ordered path and not have sequence number in targetlist of compressed scan
:PREFIX_VERBOSE
SELECT device_id,
    device_id_peer
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer
LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   Output: metrics.device_id, metrics.device_id_peer
   ->  Merge Append (actual rows=100.00 loops=1)
         Sort Key: metrics.device_id, metrics.device_id_peer
         ->  Sort (actual rows=100.00 loops=1)
               Output: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer
               Sort Key: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer
               Sort Method: top-N heapsort 
               ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=2235.00 loops=1)
                     Output: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer
                     Filter: (_hyper_1_2_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
                     Rows Removed by Filter: 1125
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=1.00 loops=1)
               Output: _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer
               Bulk Decompression: false
               ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3

-- should produce ordered path
-- only referencing PREFIX_VERBOSE should work
:PREFIX_VERBOSE
SELECT device_id,
    device_id_peer,
    v0
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer,
    v0;
--- QUERY PLAN ---
 Merge Append (actual rows=3915.00 loops=1)
   Sort Key: metrics.device_id, metrics.device_id_peer, metrics.v0
   ->  Sort (actual rows=2235.00 loops=1)
         Output: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0
         Sort Key: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0
         Sort Method: quicksort 
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=2235.00 loops=1)
               Output: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0
               Filter: (_hyper_1_2_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 1125
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=1680.00 loops=1)
         Output: _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0
         Bulk Decompression: true
         ->  Sort (actual rows=5.00 loops=1)
               Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
               Sort Key: compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1
               Sort Method: quicksort 
               ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3

-- should produce ordered path
-- only referencing PREFIX_VERBOSE should work
:PREFIX_VERBOSE
SELECT device_id,
    device_id_peer,
    v0,
    v1
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer,
    v0,
    v1 DESC;
--- QUERY PLAN ---
 Merge Append (actual rows=3915.00 loops=1)
   Sort Key: metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1 DESC
   ->  Sort (actual rows=2235.00 loops=1)
         Output: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1
         Sort Key: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1 DESC
         Sort Method: quicksort 
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=2235.00 loops=1)
               Output: _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1
               Filter: (_hyper_1_2_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 1125
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=1680.00 loops=1)
         Output: _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1
         Bulk Decompression: true
         ->  Sort (actual rows=5.00 loops=1)
               Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
               Sort Key: compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk._ts_meta_min_2 DESC, compress_hyper_5_16_chunk._ts_meta_max_2 DESC
               Sort Method: quicksort 
               ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3

-- These plans are flaky between MergeAppend and Sort over Append.
SET enable_sort TO OFF;
-- should not produce ordered path.
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer,
    v0,
    v1 DESC,
    time,
    v3;
--- QUERY PLAN ---
 Sort (actual rows=3915.00 loops=1)
   Output: metrics."time", metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1, metrics.v2, metrics.v3
   Sort Key: metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1 DESC, metrics."time", metrics.v3
   Sort Method: quicksort 
   ->  Append (actual rows=3915.00 loops=1)
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=2235.00 loops=1)
               Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
               Filter: (_hyper_1_2_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 1125
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=1680.00 loops=1)
               Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3

-- should produce ordered path
-- ASC/DESC for segmentby columns can be pushed down
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id DESC,
    device_id_peer DESC,
    v0,
    v1 DESC,
    time;
--- QUERY PLAN ---
 Sort (actual rows=3915.00 loops=1)
   Output: metrics."time", metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1, metrics.v2, metrics.v3
   Sort Key: metrics.device_id DESC, metrics.device_id_peer DESC, metrics.v0, metrics.v1 DESC, metrics."time"
   Sort Method: quicksort 
   ->  Append (actual rows=3915.00 loops=1)
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=2235.00 loops=1)
               Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
               Filter: (_hyper_1_2_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 1125
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=1680.00 loops=1)
               Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3

-- should not produce ordered path
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id DESC,
    device_id_peer DESC,
    v0,
    v1,
    time;
--- QUERY PLAN ---
 Sort (actual rows=3915.00 loops=1)
   Output: metrics."time", metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1, metrics.v2, metrics.v3
   Sort Key: metrics.device_id DESC, metrics.device_id_peer DESC, metrics.v0, metrics.v1, metrics."time"
   Sort Method: quicksort 
   ->  Append (actual rows=3915.00 loops=1)
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=2235.00 loops=1)
               Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
               Filter: (_hyper_1_2_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 1125
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=1680.00 loops=1)
               Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3

--
-- test constraint exclusion
--
-- test plan time exclusion
-- first chunk should be excluded
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY time,
    device_id;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics (actual rows=3915.00 loops=1)
   Order: metrics."time", metrics.device_id
   ->  Sort (actual rows=2235.00 loops=1)
         Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
         Sort Method: quicksort 
         ->  Seq Scan on _hyper_1_2_chunk (actual rows=2235.00 loops=1)
               Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 1125
   ->  Sort (actual rows=1680.00 loops=1)
         Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
               ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)

RESET enable_sort;
-- test runtime exclusion
-- first chunk should be excluded
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'::text::timestamptz
ORDER BY time,
    device_id;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics (actual rows=3915.00 loops=1)
   Order: metrics."time", metrics.device_id
   Chunks excluded during startup: 1
   ->  Sort (actual rows=2235.00 loops=1)
         Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
         Sort Method: quicksort 
         ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=2235.00 loops=1)
               Index Cond: ("time" > ('2000-01-08'::cstring)::timestamp with time zone)
   ->  Sort (actual rows=1680.00 loops=1)
         Sort Key: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
               Vectorized Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone)
               ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
                     Filter: (_ts_meta_max_3 > ('2000-01-08'::cstring)::timestamp with time zone)

-- test aggregate
:PREFIX
SELECT count(*)
FROM :TEST_TABLE;
--- QUERY PLAN ---
 Finalize Aggregate (actual rows=1.00 loops=1)
   ->  Append (actual rows=3.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
         ->  Partial Aggregate (actual rows=1.00 loops=1)
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=3360.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)

-- test aggregate with GROUP BY
-- Disable hash aggregation to get a deterministic test output
SET enable_hashagg = OFF;
:PREFIX
SELECT count(*)
FROM :TEST_TABLE
GROUP BY device_id
ORDER BY device_id;
--- QUERY PLAN ---
 Finalize GroupAggregate (actual rows=5.00 loops=1)
   Group Key: metrics.device_id
   ->  Merge Append (actual rows=15.00 loops=1)
         Sort Key: metrics.device_id
         ->  Custom Scan (VectorAgg) (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
                     ->  Sort (actual rows=5.00 loops=1)
                           Sort Key: compress_hyper_5_15_chunk.device_id
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
         ->  Partial GroupAggregate (actual rows=5.00 loops=1)
               Group Key: _hyper_1_2_chunk.device_id
               ->  Sort (actual rows=3360.00 loops=1)
                     Sort Key: _hyper_1_2_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_1_2_chunk (actual rows=3360.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
                     ->  Sort (actual rows=5.00 loops=1)
                           Sort Key: compress_hyper_5_16_chunk.device_id
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)

-- test window functions with GROUP BY
:PREFIX
SELECT sum(count(*)) OVER ()
FROM :TEST_TABLE
GROUP BY device_id
ORDER BY device_id;
--- QUERY PLAN ---
 WindowAgg (actual rows=5.00 loops=1)
   ->  Finalize GroupAggregate (actual rows=5.00 loops=1)
         Group Key: metrics.device_id
         ->  Merge Append (actual rows=15.00 loops=1)
               Sort Key: metrics.device_id
               ->  Custom Scan (VectorAgg) (actual rows=5.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
                           ->  Sort (actual rows=5.00 loops=1)
                                 Sort Key: compress_hyper_5_15_chunk.device_id
                                 Sort Method: quicksort 
                                 ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
               ->  Partial GroupAggregate (actual rows=5.00 loops=1)
                     Group Key: _hyper_1_2_chunk.device_id
                     ->  Sort (actual rows=3360.00 loops=1)
                           Sort Key: _hyper_1_2_chunk.device_id
                           Sort Method: quicksort 
                           ->  Seq Scan on _hyper_1_2_chunk (actual rows=3360.00 loops=1)
               ->  Custom Scan (VectorAgg) (actual rows=5.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
                           ->  Sort (actual rows=5.00 loops=1)
                                 Sort Key: compress_hyper_5_16_chunk.device_id
                                 Sort Method: quicksort 
                                 ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)

SET enable_hashagg = ON;
-- test CTE
:PREFIX WITH q AS (
    SELECT v1
    FROM :TEST_TABLE
    ORDER BY time
)
SELECT *
FROM q
ORDER BY v1;
--- QUERY PLAN ---
 Sort (actual rows=8640.00 loops=1)
   Sort Key: q.v1
   Sort Method: quicksort 
   ->  Subquery Scan on q (actual rows=8640.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics (actual rows=8640.00 loops=1)
               Order: metrics."time"
               ->  Sort (actual rows=3600.00 loops=1)
                     Sort Key: _hyper_1_1_chunk."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
               ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=3360.00 loops=1)
               ->  Sort (actual rows=1680.00 loops=1)
                     Sort Key: _hyper_1_3_chunk."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)

-- test CTE join
:PREFIX WITH q1 AS (
    SELECT time,
        v1
    FROM :TEST_TABLE
    WHERE device_id = 1
    ORDER BY time
),
q2 AS (
    SELECT time,
        v2
    FROM :TEST_TABLE
    WHERE device_id = 2
    ORDER BY time
)
SELECT *
FROM q1
    INNER JOIN q2 ON q1.time = q2.time
ORDER BY q1.time;
--- QUERY PLAN ---
 Merge Join (actual rows=1728.00 loops=1)
   Merge Cond: (metrics."time" = metrics_1."time")
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=1728.00 loops=1)
         Order: metrics."time"
         ->  Sort (actual rows=720.00 loops=1)
               Sort Key: _hyper_1_1_chunk."time"
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)
                           Rows Removed by Filter: 4
         ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=672.00 loops=1)
               Filter: (device_id = 1)
               Rows Removed by Filter: 2688
         ->  Sort (actual rows=336.00 loops=1)
               Sort Key: _hyper_1_3_chunk."time"
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=336.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)
                           Rows Removed by Filter: 4
   ->  Materialize (actual rows=1728.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics metrics_1 (actual rows=1728.00 loops=1)
               Order: metrics_1."time"
               ->  Sort (actual rows=720.00 loops=1)
                     Sort Key: _hyper_1_1_chunk_1."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk compress_hyper_5_15_chunk_1 (actual rows=1.00 loops=1)
                                 Filter: (device_id = 2)
                                 Rows Removed by Filter: 4
               ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk _hyper_1_2_chunk_1 (actual rows=672.00 loops=1)
                     Filter: (device_id = 2)
                     Rows Removed by Filter: 2688
               ->  Sort (actual rows=336.00 loops=1)
                     Sort Key: _hyper_1_3_chunk_1."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk _hyper_1_3_chunk_1 (actual rows=336.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_16_chunk compress_hyper_5_16_chunk_1 (actual rows=1.00 loops=1)
                                 Filter: (device_id = 2)
                                 Rows Removed by Filter: 4

:PREFIX WITH q1 AS (
    SELECT time,
        v1
    FROM :TEST_TABLE
    WHERE device_id = 1
    ORDER BY time
	LIMIT 5
),
q2 AS (
    SELECT time,
        v2
    FROM :TEST_TABLE
    WHERE device_id = 2
    ORDER BY time
	LIMIT 5
)
SELECT *
FROM q1, q2;
--- QUERY PLAN ---
 Nested Loop (actual rows=25.00 loops=1)
   ->  Limit (actual rows=5.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics (actual rows=5.00 loops=1)
               Order: metrics."time"
               ->  Sort (actual rows=5.00 loops=1)
                     Sort Key: _hyper_1_1_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = 1)
                                 Rows Removed by Filter: 4
               ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed)
                     Filter: (device_id = 1)
               ->  Sort (never executed)
                     Sort Key: _hyper_1_3_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                           ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                                 Filter: (device_id = 1)
   ->  Materialize (actual rows=5.00 loops=5)
         ->  Limit (actual rows=5.00 loops=1)
               ->  Custom Scan (ChunkAppend) on metrics metrics_1 (actual rows=5.00 loops=1)
                     Order: metrics_1."time"
                     ->  Sort (actual rows=5.00 loops=1)
                           Sort Key: _hyper_1_1_chunk_1."time"
                           Sort Method: top-N heapsort 
                           ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_15_chunk compress_hyper_5_15_chunk_1 (actual rows=1.00 loops=1)
                                       Filter: (device_id = 2)
                                       Rows Removed by Filter: 4
                     ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk _hyper_1_2_chunk_1 (never executed)
                           Filter: (device_id = 2)
                     ->  Sort (never executed)
                           Sort Key: _hyper_1_3_chunk_1."time"
                           ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk _hyper_1_3_chunk_1 (never executed)
                                 ->  Seq Scan on compress_hyper_5_16_chunk compress_hyper_5_16_chunk_1 (never executed)
                                       Filter: (device_id = 2)

-- test prepared statement
PREPARE prep AS
SELECT count(time)
FROM :TEST_TABLE
WHERE device_id = 1;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Finalize Aggregate (actual rows=1.00 loops=1)
   ->  Append (actual rows=3.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)
                           Rows Removed by Filter: 4
         ->  Partial Aggregate (actual rows=1.00 loops=1)
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=672.00 loops=1)
                     Filter: (device_id = 1)
                     Rows Removed by Filter: 2688
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=336.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)
                           Rows Removed by Filter: 4

EXECUTE prep;
 count 
-------
  1728

EXECUTE prep;
 count 
-------
  1728

EXECUTE prep;
 count 
-------
  1728

EXECUTE prep;
 count 
-------
  1728

EXECUTE prep;
 count 
-------
  1728

EXECUTE prep;
 count 
-------
  1728

DEALLOCATE prep;
--
-- test indexes
--
SET enable_seqscan TO FALSE;
-- IndexScans should work
:PREFIX_VERBOSE
SELECT time,
    device_id
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY device_id,
    time;
--- QUERY PLAN ---
 Merge Append (actual rows=1728.00 loops=1)
   Sort Key: metrics."time"
   ->  Sort (actual rows=720.00 loops=1)
         Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
         Sort Key: _hyper_1_1_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=720.00 loops=1)
               Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
                     Index Cond: (compress_hyper_5_15_chunk.device_id = 1)
   ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _timescaledb_internal._hyper_1_2_chunk (actual rows=672.00 loops=1)
         Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id
         Filter: (_hyper_1_2_chunk.device_id = 1)
         Rows Removed by Filter: 2688
   ->  Sort (actual rows=336.00 loops=1)
         Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
         Sort Key: _hyper_1_3_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=336.00 loops=1)
               Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
                     Index Cond: (compress_hyper_5_16_chunk.device_id = 1)

-- globs should not plan IndexOnlyScans
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY device_id,
    time;
--- QUERY PLAN ---
 Merge Append (actual rows=1728.00 loops=1)
   Sort Key: metrics."time"
   ->  Sort (actual rows=720.00 loops=1)
         Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id, _hyper_1_1_chunk.device_id_peer, _hyper_1_1_chunk.v0, _hyper_1_1_chunk.v1, _hyper_1_1_chunk.v2, _hyper_1_1_chunk.v3
         Sort Key: _hyper_1_1_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=720.00 loops=1)
               Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id, _hyper_1_1_chunk.device_id_peer, _hyper_1_1_chunk.v0, _hyper_1_1_chunk.v1, _hyper_1_1_chunk.v2, _hyper_1_1_chunk.v3
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
                     Index Cond: (compress_hyper_5_15_chunk.device_id = 1)
   ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _timescaledb_internal._hyper_1_2_chunk (actual rows=672.00 loops=1)
         Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
         Filter: (_hyper_1_2_chunk.device_id = 1)
         Rows Removed by Filter: 2688
   ->  Sort (actual rows=336.00 loops=1)
         Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
         Sort Key: _hyper_1_3_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=336.00 loops=1)
               Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
                     Index Cond: (compress_hyper_5_16_chunk.device_id = 1)

-- whole row reference should work
:PREFIX_VERBOSE
SELECT test_table
FROM :TEST_TABLE AS test_table
WHERE device_id = 1
ORDER BY device_id,
    time;
--- QUERY PLAN ---
 Merge Append (actual rows=1728.00 loops=1)
   Sort Key: test_table."time"
   ->  Sort (actual rows=720.00 loops=1)
         Output: ((test_table_1.*)::metrics), test_table_1.device_id, test_table_1."time"
         Sort Key: test_table_1."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk test_table_1 (actual rows=720.00 loops=1)
               Output: test_table_1.*, test_table_1.device_id, test_table_1."time"
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
                     Index Cond: (compress_hyper_5_15_chunk.device_id = 1)
   ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _timescaledb_internal._hyper_1_2_chunk test_table_2 (actual rows=672.00 loops=1)
         Output: test_table_2.*, test_table_2.device_id, test_table_2."time"
         Filter: (test_table_2.device_id = 1)
         Rows Removed by Filter: 2688
   ->  Sort (actual rows=336.00 loops=1)
         Output: ((test_table_3.*)::metrics), test_table_3.device_id, test_table_3."time"
         Sort Key: test_table_3."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk test_table_3 (actual rows=336.00 loops=1)
               Output: test_table_3.*, test_table_3.device_id, test_table_3."time"
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
                     Index Cond: (compress_hyper_5_16_chunk.device_id = 1)

-- even when we select only a segmentby column, we still need count
:PREFIX_VERBOSE
SELECT device_id
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY device_id;
--- QUERY PLAN ---
 Append (actual rows=1728.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=720.00 loops=1)
         Output: _hyper_1_1_chunk.device_id
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
               Index Cond: (compress_hyper_5_15_chunk.device_id = 1)
   ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=672.00 loops=1)
         Output: _hyper_1_2_chunk.device_id
         Filter: (_hyper_1_2_chunk.device_id = 1)
         Rows Removed by Filter: 2688
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=336.00 loops=1)
         Output: _hyper_1_3_chunk.device_id
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
               Index Cond: (compress_hyper_5_16_chunk.device_id = 1)

:PREFIX_VERBOSE
SELECT count(*)
FROM :TEST_TABLE
WHERE device_id = 1;
--- QUERY PLAN ---
 Finalize Aggregate (actual rows=1.00 loops=1)
   Output: count(*)
   ->  Append (actual rows=3.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               Output: (PARTIAL count(*))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=720.00 loops=1)
                     Bulk Decompression: false
                     ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                           Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
                           Index Cond: (compress_hyper_5_15_chunk.device_id = 1)
         ->  Partial Aggregate (actual rows=1.00 loops=1)
               Output: PARTIAL count(*)
               ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=672.00 loops=1)
                     Filter: (_hyper_1_2_chunk.device_id = 1)
                     Rows Removed by Filter: 2688
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               Output: (PARTIAL count(*))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=336.00 loops=1)
                     Bulk Decompression: false
                     ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                           Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
                           Index Cond: (compress_hyper_5_16_chunk.device_id = 1)

-- should be able to order using an index
CREATE INDEX tmp_idx ON :TEST_TABLE (device_id);
:PREFIX_VERBOSE
SELECT device_id
FROM :TEST_TABLE
ORDER BY device_id;
--- QUERY PLAN ---
 Merge Append (actual rows=8640.00 loops=1)
   Sort Key: metrics.device_id
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=3600.00 loops=1)
         Output: _hyper_1_1_chunk.device_id
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
               Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
   ->  Index Only Scan using _hyper_1_2_chunk_tmp_idx on _timescaledb_internal._hyper_1_2_chunk (actual rows=3360.00 loops=1)
         Output: _hyper_1_2_chunk.device_id
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=1680.00 loops=1)
         Output: _hyper_1_3_chunk.device_id
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
               Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3

DROP INDEX tmp_idx CASCADE;
-- These plans are flaky between MergeAppend and Sort over Append.
SET enable_sort TO OFF;
--use the peer index
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE device_id_peer = 1
ORDER BY device_id_peer,
    time;
--- QUERY PLAN ---
 Sort (actual rows=0.00 loops=1)
   Output: metrics."time", metrics.device_id, metrics.device_id_peer, metrics.v0, metrics.v1, metrics.v2, metrics.v3
   Sort Key: metrics."time"
   Sort Method: quicksort 
   ->  Append (actual rows=0.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=0.00 loops=1)
               Output: _hyper_1_1_chunk."time", _hyper_1_1_chunk.device_id, _hyper_1_1_chunk.device_id_peer, _hyper_1_1_chunk.v0, _hyper_1_1_chunk.v1, _hyper_1_1_chunk.v2, _hyper_1_1_chunk.v3
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=0.00 loops=1)
                     Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
                     Index Cond: (compress_hyper_5_15_chunk.device_id_peer = 1)
         ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _timescaledb_internal._hyper_1_2_chunk (actual rows=0.00 loops=1)
               Output: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id, _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.v0, _hyper_1_2_chunk.v1, _hyper_1_2_chunk.v2, _hyper_1_2_chunk.v3
               Filter: (_hyper_1_2_chunk.device_id_peer = 1)
               Rows Removed by Filter: 3360
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=0.00 loops=1)
               Output: _hyper_1_3_chunk."time", _hyper_1_3_chunk.device_id, _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.v0, _hyper_1_3_chunk.v1, _hyper_1_3_chunk.v2, _hyper_1_3_chunk.v3
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=0.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
                     Index Cond: (compress_hyper_5_16_chunk.device_id_peer = 1)

RESET enable_sort;
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id_peer = 1
ORDER BY device_id_peer;
--- QUERY PLAN ---
 Append (actual rows=0.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=0.00 loops=1)
         Output: _hyper_1_1_chunk.device_id_peer
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
               Index Cond: (compress_hyper_5_15_chunk.device_id_peer = 1)
   ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=0.00 loops=1)
         Output: _hyper_1_2_chunk.device_id_peer
         Filter: (_hyper_1_2_chunk.device_id_peer = 1)
         Rows Removed by Filter: 3360
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=0.00 loops=1)
         Output: _hyper_1_3_chunk.device_id_peer
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
               Index Cond: (compress_hyper_5_16_chunk.device_id_peer = 1)

--ensure that we can get a nested loop
SET enable_seqscan TO TRUE;
SET enable_hashjoin TO FALSE;
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id_peer IN (
        VALUES (1));
--- QUERY PLAN ---
 Append (actual rows=0.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=0.00 loops=1)
         Output: _hyper_1_1_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
               Filter: (compress_hyper_5_15_chunk.device_id_peer = 1)
               Rows Removed by Filter: 5
   ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=0.00 loops=1)
         Output: _hyper_1_2_chunk.device_id_peer
         Filter: (_hyper_1_2_chunk.device_id_peer = 1)
         Rows Removed by Filter: 3360
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=0.00 loops=1)
         Output: _hyper_1_3_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
               Filter: (compress_hyper_5_16_chunk.device_id_peer = 1)
               Rows Removed by Filter: 5

--with multiple values can get a nested loop.
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id_peer IN (
        VALUES (1),
            (2));
--- QUERY PLAN ---
 Nested Loop Semi Join (actual rows=0.00 loops=1)
   Output: metrics.device_id_peer
   Join Filter: (metrics.device_id_peer = "*VALUES*".column1)
   Rows Removed by Join Filter: 17280
   ->  Append (actual rows=8640.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=3600.00 loops=1)
               Output: _hyper_1_1_chunk.device_id_peer
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                     Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=3360.00 loops=1)
               Output: _hyper_1_2_chunk.device_id_peer
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=1680.00 loops=1)
               Output: _hyper_1_3_chunk.device_id_peer
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
   ->  Materialize (actual rows=2.00 loops=8640)
         Output: "*VALUES*".column1
         ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
               Output: "*VALUES*".column1

RESET enable_hashjoin;
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id IN (
        VALUES (1));
--- QUERY PLAN ---
 Append (actual rows=1728.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=720.00 loops=1)
         Output: _hyper_1_1_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
               Filter: (compress_hyper_5_15_chunk.device_id = 1)
               Rows Removed by Filter: 4
   ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=672.00 loops=1)
         Output: _hyper_1_2_chunk.device_id_peer
         Filter: (_hyper_1_2_chunk.device_id = 1)
         Rows Removed by Filter: 2688
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=336.00 loops=1)
         Output: _hyper_1_3_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
               Filter: (compress_hyper_5_16_chunk.device_id = 1)
               Rows Removed by Filter: 4

--with multiple values can get a semi-join or nested loop depending on seq_page_cost.
SET enable_hashjoin TO OFF;
SET enable_mergejoin TO OFF;
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id IN (
        VALUES (1),
            (2));
--- QUERY PLAN ---
 Nested Loop (actual rows=3456.00 loops=1)
   Output: metrics.device_id_peer
   ->  Unique (actual rows=2.00 loops=1)
         Output: "*VALUES*".column1
         ->  Sort (actual rows=2.00 loops=1)
               Output: "*VALUES*".column1
               Sort Key: "*VALUES*".column1
               Sort Method: quicksort 
               ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
                     Output: "*VALUES*".column1
   ->  Append (actual rows=1728.00 loops=2)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=720.00 loops=2)
               Output: _hyper_1_1_chunk.device_id_peer, _hyper_1_1_chunk.device_id
               Bulk Decompression: false
               ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=1.00 loops=2)
                     Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
                     Index Cond: (compress_hyper_5_15_chunk.device_id = "*VALUES*".column1)
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=672.00 loops=2)
               Output: _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.device_id
               Filter: ("*VALUES*".column1 = _hyper_1_2_chunk.device_id)
               Rows Removed by Filter: 2688
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=336.00 loops=2)
               Output: _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.device_id
               Bulk Decompression: false
               ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=1.00 loops=2)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
                     Index Cond: (compress_hyper_5_16_chunk.device_id = "*VALUES*".column1)

RESET enable_hashjoin;
RESET enable_mergejoin;
SET seq_page_cost = 100;
-- loop/row counts of this query is different on windows so we run it without analyze
:PREFIX_NO_ANALYZE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id IN (
        VALUES (1),
            (2));
--- QUERY PLAN ---
 Hash Semi Join
   Output: metrics.device_id_peer
   Hash Cond: (metrics.device_id = "*VALUES*".column1)
   ->  Append
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk
               Output: _hyper_1_1_chunk.device_id_peer, _hyper_1_1_chunk.device_id
               ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_15_chunk
                     Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk
               Output: _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.device_id
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk
               Output: _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.device_id
               ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
   ->  Hash
         Output: "*VALUES*".column1
         ->  Values Scan on "*VALUES*"
               Output: "*VALUES*".column1

RESET seq_page_cost;
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id IN (
        VALUES (1));
--- QUERY PLAN ---
 Append (actual rows=1728.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=720.00 loops=1)
         Output: _hyper_1_1_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
               Filter: (compress_hyper_5_15_chunk.device_id = 1)
               Rows Removed by Filter: 4
   ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=672.00 loops=1)
         Output: _hyper_1_2_chunk.device_id_peer
         Filter: (_hyper_1_2_chunk.device_id = 1)
         Rows Removed by Filter: 2688
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=336.00 loops=1)
         Output: _hyper_1_3_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
               Filter: (compress_hyper_5_16_chunk.device_id = 1)
               Rows Removed by Filter: 4

:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id IN (
        VALUES (1),
            (2));
--- QUERY PLAN ---
 Nested Loop (actual rows=3456.00 loops=1)
   Output: metrics.device_id_peer
   ->  Unique (actual rows=2.00 loops=1)
         Output: "*VALUES*".column1
         ->  Sort (actual rows=2.00 loops=1)
               Output: "*VALUES*".column1
               Sort Key: "*VALUES*".column1
               Sort Method: quicksort 
               ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
                     Output: "*VALUES*".column1
   ->  Append (actual rows=1728.00 loops=2)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_1_chunk (actual rows=720.00 loops=2)
               Output: _hyper_1_1_chunk.device_id_peer, _hyper_1_1_chunk.device_id
               Bulk Decompression: false
               ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_15_chunk (actual rows=1.00 loops=2)
                     Output: compress_hyper_5_15_chunk._ts_meta_count, compress_hyper_5_15_chunk.device_id, compress_hyper_5_15_chunk.device_id_peer, compress_hyper_5_15_chunk._ts_meta_min_3, compress_hyper_5_15_chunk._ts_meta_max_3, compress_hyper_5_15_chunk."time", compress_hyper_5_15_chunk._ts_meta_min_1, compress_hyper_5_15_chunk._ts_meta_max_1, compress_hyper_5_15_chunk.v0, compress_hyper_5_15_chunk._ts_meta_min_2, compress_hyper_5_15_chunk._ts_meta_max_2, compress_hyper_5_15_chunk.v1, compress_hyper_5_15_chunk.v2, compress_hyper_5_15_chunk.v3
                     Index Cond: (compress_hyper_5_15_chunk.device_id = "*VALUES*".column1)
         ->  Seq Scan on _timescaledb_internal._hyper_1_2_chunk (actual rows=672.00 loops=2)
               Output: _hyper_1_2_chunk.device_id_peer, _hyper_1_2_chunk.device_id
               Filter: ("*VALUES*".column1 = _hyper_1_2_chunk.device_id)
               Rows Removed by Filter: 2688
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_1_3_chunk (actual rows=336.00 loops=2)
               Output: _hyper_1_3_chunk.device_id_peer, _hyper_1_3_chunk.device_id
               Bulk Decompression: false
               ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_5_16_chunk (actual rows=1.00 loops=2)
                     Output: compress_hyper_5_16_chunk._ts_meta_count, compress_hyper_5_16_chunk.device_id, compress_hyper_5_16_chunk.device_id_peer, compress_hyper_5_16_chunk._ts_meta_min_3, compress_hyper_5_16_chunk._ts_meta_max_3, compress_hyper_5_16_chunk."time", compress_hyper_5_16_chunk._ts_meta_min_1, compress_hyper_5_16_chunk._ts_meta_max_1, compress_hyper_5_16_chunk.v0, compress_hyper_5_16_chunk._ts_meta_min_2, compress_hyper_5_16_chunk._ts_meta_max_2, compress_hyper_5_16_chunk.v1, compress_hyper_5_16_chunk.v2, compress_hyper_5_16_chunk.v3
                     Index Cond: (compress_hyper_5_16_chunk.device_id = "*VALUES*".column1)

-- test view
CREATE OR REPLACE VIEW compressed_view AS
SELECT time,
    device_id,
    v1,
    v2
FROM :TEST_TABLE;
:PREFIX
SELECT *
FROM compressed_view
WHERE device_id = 1
ORDER BY time DESC
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=10.00 loops=1)
         Order: metrics."time" DESC
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_1_3_chunk."time" DESC
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=336.00 loops=1)
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)
                           Rows Removed by Filter: 4
         ->  Index Scan using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed)
               Filter: (device_id = 1)
         ->  Sort (never executed)
               Sort Key: _hyper_1_1_chunk."time" DESC
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (never executed)
                     ->  Seq Scan on compress_hyper_5_15_chunk (never executed)
                           Filter: (device_id = 1)

DROP VIEW compressed_view;
-- test INNER JOIN
:PREFIX
SELECT *
FROM :TEST_TABLE m1
    INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time
        AND m1.device_id = m2.device_id
    ORDER BY m1.time,
        m1.device_id
    LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Merge Join (actual rows=10.00 loops=1)
         Merge Cond: ((m1."time" = m2."time") AND (m1.device_id = m2.device_id))
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=10.00 loops=1)
               Order: m1."time", m1.device_id
               ->  Sort (actual rows=10.00 loops=1)
                     Sort Key: m1_1."time", m1_1.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=3600.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
               ->  Sort (never executed)
                     Sort Key: m1_2."time", m1_2.device_id
                     ->  Seq Scan on _hyper_1_2_chunk m1_2 (never executed)
               ->  Sort (never executed)
                     Sort Key: m1_3."time", m1_3.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (never executed)
                           ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
         ->  Materialize (actual rows=10.00 loops=1)
               ->  Custom Scan (ChunkAppend) on metrics m2 (actual rows=10.00 loops=1)
                     Order: m2."time", m2.device_id
                     ->  Sort (actual rows=10.00 loops=1)
                           Sort Key: m2_1."time", m2_1.device_id
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m2_1 (actual rows=3600.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_15_chunk compress_hyper_5_15_chunk_1 (actual rows=5.00 loops=1)
                     ->  Sort (never executed)
                           Sort Key: m2_2."time", m2_2.device_id
                           ->  Seq Scan on _hyper_1_2_chunk m2_2 (never executed)
                     ->  Sort (never executed)
                           Sort Key: m2_3."time", m2_3.device_id
                           ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m2_3 (never executed)
                                 ->  Seq Scan on compress_hyper_5_16_chunk compress_hyper_5_16_chunk_1 (never executed)

:PREFIX
SELECT *
FROM :TEST_TABLE m1
    INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time
    INNER JOIN :TEST_TABLE m3 ON m2.time = m3.time
        AND m1.device_id = m2.device_id
        AND m3.device_id = 3
    ORDER BY m1.time,
        m1.device_id
    LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Merge Join (actual rows=10.00 loops=1)
         Merge Cond: (m1."time" = m3."time")
         ->  Merge Join (actual rows=10.00 loops=1)
               Merge Cond: ((m1."time" = m2."time") AND (m1.device_id = m2.device_id))
               ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=10.00 loops=1)
                     Order: m1."time", m1.device_id
                     ->  Sort (actual rows=10.00 loops=1)
                           Sort Key: m1_1."time", m1_1.device_id
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=3600.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                     ->  Sort (never executed)
                           Sort Key: m1_2."time", m1_2.device_id
                           ->  Seq Scan on _hyper_1_2_chunk m1_2 (never executed)
                     ->  Sort (never executed)
                           Sort Key: m1_3."time", m1_3.device_id
                           ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (never executed)
                                 ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
               ->  Materialize (actual rows=10.00 loops=1)
                     ->  Custom Scan (ChunkAppend) on metrics m2 (actual rows=10.00 loops=1)
                           Order: m2."time", m2.device_id
                           ->  Sort (actual rows=10.00 loops=1)
                                 Sort Key: m2_1."time", m2_1.device_id
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m2_1 (actual rows=3600.00 loops=1)
                                       ->  Seq Scan on compress_hyper_5_15_chunk compress_hyper_5_15_chunk_1 (actual rows=5.00 loops=1)
                           ->  Sort (never executed)
                                 Sort Key: m2_2."time", m2_2.device_id
                                 ->  Seq Scan on _hyper_1_2_chunk m2_2 (never executed)
                           ->  Sort (never executed)
                                 Sort Key: m2_3."time", m2_3.device_id
                                 ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m2_3 (never executed)
                                       ->  Seq Scan on compress_hyper_5_16_chunk compress_hyper_5_16_chunk_1 (never executed)
         ->  Materialize (actual rows=10.00 loops=1)
               ->  Custom Scan (ChunkAppend) on metrics m3 (actual rows=3.00 loops=1)
                     Order: m3."time"
                     ->  Sort (actual rows=3.00 loops=1)
                           Sort Key: m3_1."time"
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m3_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_15_chunk compress_hyper_5_15_chunk_2 (actual rows=1.00 loops=1)
                                       Filter: (device_id = 3)
                                       Rows Removed by Filter: 4
                     ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk m3_2 (never executed)
                           Filter: (device_id = 3)
                     ->  Sort (never executed)
                           Sort Key: m3_3."time"
                           ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m3_3 (never executed)
                                 ->  Seq Scan on compress_hyper_5_16_chunk compress_hyper_5_16_chunk_2 (never executed)
                                       Filter: (device_id = 3)

:PREFIX
SELECT *
FROM :TEST_TABLE m1
    INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time
        AND m1.device_id = 1
        AND m2.device_id = 2
    ORDER BY m1.time,
        m1.device_id,
        m2.time,
        m2.device_id
    LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Merge Join (actual rows=100.00 loops=1)
         Merge Cond: (m1."time" = m2."time")
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Sort (actual rows=100.00 loops=1)
                     Sort Key: m1_1."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = 1)
                                 Rows Removed by Filter: 4
               ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk m1_2 (never executed)
                     Filter: (device_id = 1)
               ->  Sort (never executed)
                     Sort Key: m1_3."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (never executed)
                           ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                                 Filter: (device_id = 1)
         ->  Materialize (actual rows=100.00 loops=1)
               ->  Custom Scan (ChunkAppend) on metrics m2 (actual rows=100.00 loops=1)
                     Order: m2."time"
                     ->  Sort (actual rows=100.00 loops=1)
                           Sort Key: m2_1."time"
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m2_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_15_chunk compress_hyper_5_15_chunk_1 (actual rows=1.00 loops=1)
                                       Filter: (device_id = 2)
                                       Rows Removed by Filter: 4
                     ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk m2_2 (never executed)
                           Filter: (device_id = 2)
                     ->  Sort (never executed)
                           Sort Key: m2_3."time"
                           ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m2_3 (never executed)
                                 ->  Seq Scan on compress_hyper_5_16_chunk compress_hyper_5_16_chunk_1 (never executed)
                                       Filter: (device_id = 2)

:PREFIX
SELECT *
FROM metrics m1
    INNER JOIN metrics_space m2 ON m1.time = m2.time
        AND m1.device_id = 1
        AND m2.device_id = 2
    ORDER BY m1.time,
        m1.device_id,
        m2.time,
        m2.device_id
    LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Merge Join (actual rows=100.00 loops=1)
         Merge Cond: (m1."time" = m2."time")
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Sort (actual rows=100.00 loops=1)
                     Sort Key: m1_1."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = 1)
                                 Rows Removed by Filter: 4
               ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk m1_2 (never executed)
                     Filter: (device_id = 1)
               ->  Sort (never executed)
                     Sort Key: m1_3."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (never executed)
                           ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                                 Filter: (device_id = 1)
         ->  Materialize (actual rows=100.00 loops=1)
               ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=100.00 loops=1)
                     Order: m2."time"
                     ->  Sort (actual rows=100.00 loops=1)
                           Sort Key: m2_1."time"
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m2_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=1.00 loops=1)
                                       Filter: (device_id = 2)
                                       Rows Removed by Filter: 2
                     ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk m2_2 (never executed)
                           Index Cond: (device_id = 2)
                     ->  Sort (never executed)
                           Sort Key: m2_3."time"
                           ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m2_3 (never executed)
                                 ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                       Filter: (device_id = 2)

-- test OUTER JOIN
:PREFIX
SELECT *
FROM :TEST_TABLE m1
    LEFT OUTER JOIN :TEST_TABLE m2 ON m1.time = m2.time
    AND m1.device_id = m2.device_id
ORDER BY m1.time,
    m1.device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Merge Left Join (actual rows=10.00 loops=1)
         Merge Cond: (m1."time" = m2."time")
         Join Filter: (m1.device_id = m2.device_id)
         Rows Removed by Join Filter: 38
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=10.00 loops=1)
               Order: m1."time", m1.device_id
               ->  Sort (actual rows=10.00 loops=1)
                     Sort Key: m1_1."time", m1_1.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=3600.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
               ->  Sort (never executed)
                     Sort Key: m1_2."time", m1_2.device_id
                     ->  Seq Scan on _hyper_1_2_chunk m1_2 (never executed)
               ->  Sort (never executed)
                     Sort Key: m1_3."time", m1_3.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (never executed)
                           ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
         ->  Materialize (actual rows=48.00 loops=1)
               ->  Custom Scan (ChunkAppend) on metrics m2 (actual rows=11.00 loops=1)
                     Order: m2."time"
                     ->  Sort (actual rows=11.00 loops=1)
                           Sort Key: m2_1."time"
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m2_1 (actual rows=3600.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_15_chunk compress_hyper_5_15_chunk_1 (actual rows=5.00 loops=1)
                     ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk m2_2 (never executed)
                     ->  Sort (never executed)
                           Sort Key: m2_3."time"
                           ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m2_3 (never executed)
                                 ->  Seq Scan on compress_hyper_5_16_chunk compress_hyper_5_16_chunk_1 (never executed)

:PREFIX
SELECT *
FROM :TEST_TABLE m1
    LEFT OUTER JOIN :TEST_TABLE m2 ON m1.time = m2.time
    AND m1.device_id = 1
    AND m2.device_id = 2
ORDER BY m1.time,
    m1.device_id,
    m2.time,
    m2.device_id
LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Sort (actual rows=100.00 loops=1)
         Sort Key: m1."time", m1.device_id, m2."time", m2.device_id
         Sort Method: top-N heapsort 
         ->  Hash Left Join (actual rows=8640.00 loops=1)
               Hash Cond: (m1."time" = m2."time")
               Join Filter: (m1.device_id = 1)
               Rows Removed by Join Filter: 6912
               ->  Append (actual rows=8640.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=3600.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                     ->  Seq Scan on _hyper_1_2_chunk m1_2 (actual rows=3360.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (actual rows=1680.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
               ->  Hash (actual rows=1728.00 loops=1)
                     ->  Append (actual rows=1728.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m2_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_15_chunk compress_hyper_5_15_chunk_1 (actual rows=1.00 loops=1)
                                       Filter: (device_id = 2)
                                       Rows Removed by Filter: 4
                           ->  Seq Scan on _hyper_1_2_chunk m2_2 (actual rows=672.00 loops=1)
                                 Filter: (device_id = 2)
                                 Rows Removed by Filter: 2688
                           ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m2_3 (actual rows=336.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_16_chunk compress_hyper_5_16_chunk_1 (actual rows=1.00 loops=1)
                                       Filter: (device_id = 2)
                                       Rows Removed by Filter: 4

:PREFIX
SELECT *
FROM metrics m1
    LEFT OUTER JOIN metrics_space m2 ON m1.time = m2.time
    AND m1.device_id = 1
    AND m2.device_id = 2
ORDER BY m1.time,
    m1.device_id,
    m2.time,
    m2.device_id
LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Sort (actual rows=100.00 loops=1)
         Sort Key: m1."time", m1.device_id, m2."time", m2.device_id
         Sort Method: top-N heapsort 
         ->  Hash Left Join (actual rows=8640.00 loops=1)
               Hash Cond: (m1."time" = m2."time")
               Join Filter: (m1.device_id = 1)
               Rows Removed by Join Filter: 6912
               ->  Append (actual rows=8640.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=3600.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                     ->  Seq Scan on _hyper_1_2_chunk m1_2 (actual rows=3360.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (actual rows=1680.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
               ->  Hash (actual rows=1728.00 loops=1)
                     ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=1728.00 loops=1)
                           Order: m2."time"
                           ->  Sort (actual rows=720.00 loops=1)
                                 Sort Key: m2_1."time"
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m2_1 (actual rows=720.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=1.00 loops=1)
                                             Filter: (device_id = 2)
                                             Rows Removed by Filter: 2
                           ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk m2_2 (actual rows=672.00 loops=1)
                                 Index Cond: (device_id = 2)
                           ->  Sort (actual rows=336.00 loops=1)
                                 Sort Key: m2_3."time"
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m2_3 (actual rows=336.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=1.00 loops=1)
                                             Filter: (device_id = 2)
                                             Rows Removed by Filter: 2

-- test implicit self-join
:PREFIX
SELECT *
FROM :TEST_TABLE m1,
    :TEST_TABLE m2
WHERE m1.time = m2.time
ORDER BY m1.time,
    m1.device_id,
    m2.time,
    m2.device_id
LIMIT 20;
--- QUERY PLAN ---
 Limit (actual rows=20.00 loops=1)
   ->  Sort (actual rows=20.00 loops=1)
         Sort Key: m1."time", m1.device_id, m2.device_id
         Sort Method: top-N heapsort 
         ->  Hash Join (actual rows=43200.00 loops=1)
               Hash Cond: (m1."time" = m2."time")
               ->  Append (actual rows=8640.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=3600.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                     ->  Seq Scan on _hyper_1_2_chunk m1_2 (actual rows=3360.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (actual rows=1680.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
               ->  Hash (actual rows=8640.00 loops=1)
                     ->  Append (actual rows=8640.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m2_1 (actual rows=3600.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_15_chunk compress_hyper_5_15_chunk_1 (actual rows=5.00 loops=1)
                           ->  Seq Scan on _hyper_1_2_chunk m2_2 (actual rows=3360.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m2_3 (actual rows=1680.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_16_chunk compress_hyper_5_16_chunk_1 (actual rows=5.00 loops=1)

-- test self-join with sub-query
:PREFIX
SELECT *
FROM (
    SELECT *
    FROM :TEST_TABLE m1) m1
    INNER JOIN (
        SELECT *
        FROM :TEST_TABLE m2) m2 ON m1.time = m2.time
ORDER BY m1.time,
    m1.device_id,
    m2.device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Sort (actual rows=10.00 loops=1)
         Sort Key: m1."time", m1.device_id, m2.device_id
         Sort Method: top-N heapsort 
         ->  Hash Join (actual rows=43200.00 loops=1)
               Hash Cond: (m1."time" = m2."time")
               ->  Append (actual rows=8640.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=3600.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                     ->  Seq Scan on _hyper_1_2_chunk m1_2 (actual rows=3360.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (actual rows=1680.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
               ->  Hash (actual rows=8640.00 loops=1)
                     ->  Append (actual rows=8640.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m2_1 (actual rows=3600.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_15_chunk compress_hyper_5_15_chunk_1 (actual rows=5.00 loops=1)
                           ->  Seq Scan on _hyper_1_2_chunk m2_2 (actual rows=3360.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m2_3 (actual rows=1680.00 loops=1)
                                 ->  Seq Scan on compress_hyper_5_16_chunk compress_hyper_5_16_chunk_1 (actual rows=5.00 loops=1)

:PREFIX
SELECT *
FROM generate_series('2000-01-01'::timestamptz, '2000-02-01'::timestamptz, '1d'::interval) g (time)
        INNER JOIN LATERAL (
            SELECT time
            FROM :TEST_TABLE m1
            WHERE m1.time = g.time
            LIMIT 1) m1 ON TRUE;
--- QUERY PLAN ---
 Nested Loop (actual rows=19.00 loops=1)
   ->  Function Scan on generate_series g (actual rows=32.00 loops=1)
   ->  Limit (actual rows=1.00 loops=32)
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=1.00 loops=32)
               Chunks excluded during runtime: 2
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=1.00 loops=5)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 336
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=5)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time"))
               ->  Index Only Scan using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk m1_2 (actual rows=1.00 loops=7)
                     Index Cond: ("time" = g."time")
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (actual rows=1.00 loops=7)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 160
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=1.00 loops=7)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time"))

-- test prepared statement with params pushdown
PREPARE param_prep (int) AS
SELECT *
FROM generate_series('2000-01-01'::timestamptz, '2000-02-01'::timestamptz, '1d'::interval) g (time)
        INNER JOIN LATERAL (
            SELECT time
            FROM :TEST_TABLE m1
            WHERE m1.time = g.time
                AND device_id = $1
            LIMIT 1) m1 ON TRUE;
:PREFIX EXECUTE param_prep (1);
--- QUERY PLAN ---
 Nested Loop (actual rows=19.00 loops=1)
   ->  Function Scan on generate_series g (actual rows=32.00 loops=1)
   ->  Limit (actual rows=1.00 loops=32)
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=1.00 loops=32)
               Chunks excluded during runtime: 2
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=1.00 loops=5)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 336
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=5)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time") AND (device_id = 1))
               ->  Index Scan using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk m1_2 (actual rows=1.00 loops=7)
                     Index Cond: ("time" = g."time")
                     Filter: (device_id = 1)
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (actual rows=1.00 loops=7)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 160
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=1.00 loops=7)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time") AND (device_id = 1))

:PREFIX EXECUTE param_prep (2);
--- QUERY PLAN ---
 Nested Loop (actual rows=19.00 loops=1)
   ->  Function Scan on generate_series g (actual rows=32.00 loops=1)
   ->  Limit (actual rows=1.00 loops=32)
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=1.00 loops=32)
               Chunks excluded during runtime: 2
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=1.00 loops=5)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 336
                     ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=5)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time") AND (device_id = 2))
                           Rows Removed by Filter: 1
               ->  Index Scan using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk m1_2 (actual rows=1.00 loops=7)
                     Index Cond: ("time" = g."time")
                     Filter: (device_id = 2)
                     Rows Removed by Filter: 1
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (actual rows=1.00 loops=7)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 160
                     ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=1.00 loops=7)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time") AND (device_id = 2))
                           Rows Removed by Filter: 1

EXECUTE param_prep (1);
             time             |             time             
------------------------------+------------------------------
 Sat Jan 01 00:00:00 2000 PST | Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST | Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST | Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST | Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST | Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST | Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST | Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST | Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST | Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST | Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST | Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST | Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST | Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST | Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST | Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST | Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST | Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST | Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST | Wed Jan 19 00:00:00 2000 PST

EXECUTE param_prep (2);
             time             |             time             
------------------------------+------------------------------
 Sat Jan 01 00:00:00 2000 PST | Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST | Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST | Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST | Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST | Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST | Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST | Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST | Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST | Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST | Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST | Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST | Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST | Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST | Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST | Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST | Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST | Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST | Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST | Wed Jan 19 00:00:00 2000 PST

EXECUTE param_prep (1);
             time             |             time             
------------------------------+------------------------------
 Sat Jan 01 00:00:00 2000 PST | Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST | Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST | Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST | Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST | Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST | Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST | Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST | Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST | Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST | Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST | Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST | Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST | Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST | Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST | Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST | Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST | Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST | Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST | Wed Jan 19 00:00:00 2000 PST

EXECUTE param_prep (2);
             time             |             time             
------------------------------+------------------------------
 Sat Jan 01 00:00:00 2000 PST | Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST | Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST | Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST | Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST | Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST | Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST | Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST | Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST | Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST | Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST | Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST | Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST | Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST | Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST | Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST | Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST | Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST | Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST | Wed Jan 19 00:00:00 2000 PST

EXECUTE param_prep (1);
             time             |             time             
------------------------------+------------------------------
 Sat Jan 01 00:00:00 2000 PST | Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST | Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST | Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST | Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST | Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST | Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST | Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST | Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST | Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST | Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST | Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST | Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST | Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST | Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST | Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST | Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST | Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST | Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST | Wed Jan 19 00:00:00 2000 PST

DEALLOCATE param_prep;
-- test continuous aggs
SET client_min_messages TO error;
CREATE MATERIALIZED VIEW cagg_test WITH (timescaledb.continuous, timescaledb.materialized_only = TRUE) AS
SELECT time_bucket ('1d', time) AS time,
    device_id,
    avg(v1)
FROM :TEST_TABLE
WHERE device_id = 1
GROUP BY 1,
    2 WITH DATA;
SELECT time
FROM cagg_test
ORDER BY time
LIMIT 1;
             time             
------------------------------
 Fri Dec 31 16:00:00 1999 PST

DROP MATERIALIZED VIEW cagg_test;
RESET client_min_messages;
--github issue 1558. nested loop with index scan needed
--disables parallel scan
SET enable_seqscan = FALSE;
SET enable_bitmapscan = FALSE;
SET max_parallel_workers_per_gather = 0;
SET enable_hashjoin = FALSE;
SET enable_mergejoin = FALSE;
:PREFIX
SELECT *
FROM metrics,
    metrics_space
WHERE metrics.time > metrics_space.time
    AND metrics.device_id = metrics_space.device_id
    AND metrics.time < metrics_space.time;
--- QUERY PLAN ---
 Nested Loop (actual rows=0.00 loops=1)
   ->  Append (actual rows=8640.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
               ->  Index Scan using compress_hyper_6_17_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
               ->  Index Scan using compress_hyper_6_18_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
               ->  Index Scan using compress_hyper_6_19_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
         ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_7_chunk (actual rows=672.00 loops=1)
         ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_8_chunk (actual rows=2016.00 loops=1)
         ->  Index Scan Backward using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_9_chunk (actual rows=672.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
               ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
               ->  Index Scan using compress_hyper_6_21_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
         ->  Index Scan Backward using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v_2 on _hyper_2_12_chunk (actual rows=336.00 loops=1)
   ->  Append (actual rows=0.00 loops=8640)
         ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=0.00 loops=8640)
               Filter: (("time" > metrics_space."time") AND ("time" < metrics_space."time"))
               Rows Removed by Filter: 720
               ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_5_15_chunk (actual rows=1.00 loops=8640)
                     Index Cond: (device_id = metrics_space.device_id)
         ->  Index Scan using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=0.00 loops=8640)
               Index Cond: (("time" > metrics_space."time") AND ("time" < metrics_space."time"))
               Filter: (metrics_space.device_id = device_id)
         ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=0.00 loops=8640)
               Filter: (("time" > metrics_space."time") AND ("time" < metrics_space."time"))
               Rows Removed by Filter: 336
               ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_5_16_chunk (actual rows=1.00 loops=8640)
                     Index Cond: (device_id = metrics_space.device_id)

SET enable_seqscan = TRUE;
SET enable_bitmapscan = TRUE;
SET max_parallel_workers_per_gather = 0;
SET enable_hashjoin = TRUE;
SET enable_mergejoin = TRUE;
---end github issue 1558
\set TEST_TABLE 'metrics_space'
\ir :TEST_QUERY_NAME
-- 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.
-- this should use DecompressChunk node
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY time
LIMIT 5;
--- QUERY PLAN ---
 Limit (actual rows=5.00 loops=1)
   Output: metrics_space."time", metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1, metrics_space.v2, metrics_space.v3
   ->  Custom Scan (ChunkAppend) on public.metrics_space (actual rows=5.00 loops=1)
         Output: metrics_space."time", metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1, metrics_space.v2, metrics_space.v3
         Order: metrics_space."time"
         Startup Exclusion: false
         Runtime Exclusion: false
         ->  Sort (actual rows=5.00 loops=1)
               Output: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id, _hyper_2_4_chunk.device_id_peer, _hyper_2_4_chunk.v0, _hyper_2_4_chunk.v1, _hyper_2_4_chunk.v2, _hyper_2_4_chunk.v3
               Sort Key: _hyper_2_4_chunk."time"
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=720.00 loops=1)
                     Output: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id, _hyper_2_4_chunk.device_id_peer, _hyper_2_4_chunk.v0, _hyper_2_4_chunk.v1, _hyper_2_4_chunk.v2, _hyper_2_4_chunk.v3
                     Bulk Decompression: true
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                           Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
                           Filter: (compress_hyper_6_17_chunk.device_id = 1)
         ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _timescaledb_internal._hyper_2_7_chunk (never executed)
               Output: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1, _hyper_2_7_chunk.v2, _hyper_2_7_chunk.v3
               Filter: (_hyper_2_7_chunk.device_id = 1)
         ->  Sort (never executed)
               Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
               Sort Key: _hyper_2_10_chunk."time"
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (never executed)
                     Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
                     Bulk Decompression: true
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (never executed)
                           Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                           Filter: (compress_hyper_6_20_chunk.device_id = 1)

-- test RECORD by itself
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_space (actual rows=1728.00 loops=1)
   Order: metrics_space."time"
   ->  Sort (actual rows=720.00 loops=1)
         Sort Key: _hyper_2_4_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
               ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
   ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (actual rows=672.00 loops=1)
         Filter: (device_id = 1)
   ->  Sort (actual rows=336.00 loops=1)
         Sort Key: _hyper_2_10_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
               ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)

-- test empty targetlist
:PREFIX
SELECT
FROM :TEST_TABLE;
--- QUERY PLAN ---
 Append (actual rows=8640.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
         ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
         ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
         ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_2_7_chunk (actual rows=672.00 loops=1)
   ->  Seq Scan on _hyper_2_8_chunk (actual rows=2016.00 loops=1)
   ->  Seq Scan on _hyper_2_9_chunk (actual rows=672.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
         ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
         ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
   ->  Seq Scan on _hyper_2_12_chunk (actual rows=336.00 loops=1)

-- test empty resultset
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id < 0;
--- QUERY PLAN ---
 Append (actual rows=0.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=0.00 loops=1)
         ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=0.00 loops=1)
               Filter: (device_id < 0)
               Rows Removed by Filter: 1
   ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=0.00 loops=1)
         ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=0.00 loops=1)
               Filter: (device_id < 0)
               Rows Removed by Filter: 3
   ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=0.00 loops=1)
         ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=0.00 loops=1)
               Filter: (device_id < 0)
               Rows Removed by Filter: 1
   ->  Index Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_7_chunk (actual rows=0.00 loops=1)
         Index Cond: (device_id < 0)
   ->  Index Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_8_chunk (actual rows=0.00 loops=1)
         Index Cond: (device_id < 0)
   ->  Index Scan using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_9_chunk (actual rows=0.00 loops=1)
         Index Cond: (device_id < 0)
   ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=0.00 loops=1)
         ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=0.00 loops=1)
               Filter: (device_id < 0)
               Rows Removed by Filter: 1
   ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=0.00 loops=1)
         ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=0.00 loops=1)
               Filter: (device_id < 0)
               Rows Removed by Filter: 3
   ->  Index Scan using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v_2 on _hyper_2_12_chunk (actual rows=0.00 loops=1)
         Index Cond: (device_id < 0)

-- test targetlist not referencing columns
:PREFIX
SELECT 1
FROM :TEST_TABLE;
--- QUERY PLAN ---
 Result (actual rows=8640.00 loops=1)
   ->  Append (actual rows=8640.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
               ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
               ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
               ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
         ->  Seq Scan on _hyper_2_7_chunk (actual rows=672.00 loops=1)
         ->  Seq Scan on _hyper_2_8_chunk (actual rows=2016.00 loops=1)
         ->  Seq Scan on _hyper_2_9_chunk (actual rows=672.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
               ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
               ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
         ->  Seq Scan on _hyper_2_12_chunk (actual rows=336.00 loops=1)

-- The following plans are flaky between MergeAppend or Sort + Append.
SET enable_sort = off;
-- test expressions
:PREFIX
SELECT time_bucket ('1d', time),
    v1 + v2 AS "sum",
    COALESCE(NULL, v1, v2) AS "coalesce",
    NULL AS "NULL",
    'text' AS "text",
    :TEST_TABLE AS "RECORD"
FROM :TEST_TABLE
WHERE device_id IN (1, 2)
ORDER BY time,
    device_id
;
--- QUERY PLAN ---
 Sort (actual rows=3456.00 loops=1)
   Sort Key: metrics_space."time", metrics_space.device_id
   Sort Method: quicksort 
   ->  Result (actual rows=3456.00 loops=1)
         ->  Append (actual rows=3456.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = ANY ('{1,2}'::integer[]))
               ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = ANY ('{1,2}'::integer[]))
                           Rows Removed by Filter: 2
               ->  Seq Scan on _hyper_2_7_chunk (actual rows=672.00 loops=1)
                     Filter: (device_id = ANY ('{1,2}'::integer[]))
               ->  Index Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_8_chunk (actual rows=672.00 loops=1)
                     Index Cond: (device_id = ANY ('{1,2}'::integer[]))
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = ANY ('{1,2}'::integer[]))
               ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=336.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = ANY ('{1,2}'::integer[]))
                           Rows Removed by Filter: 2

-- test constraints not present in targetlist
:PREFIX
SELECT v1
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY v1;
--- QUERY PLAN ---
 Sort (actual rows=1728.00 loops=1)
   Sort Key: metrics_space.v1
   Sort Method: quicksort 
   ->  Append (actual rows=1728.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
               ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
         ->  Seq Scan on _hyper_2_7_chunk (actual rows=672.00 loops=1)
               Filter: (device_id = 1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
               ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)

-- test order not present in targetlist
:PREFIX
SELECT v2
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY v1;
--- QUERY PLAN ---
 Sort (actual rows=1728.00 loops=1)
   Sort Key: metrics_space.v1
   Sort Method: quicksort 
   ->  Append (actual rows=1728.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
               ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
         ->  Seq Scan on _hyper_2_7_chunk (actual rows=672.00 loops=1)
               Filter: (device_id = 1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
               ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)

-- test column with all NULL
:PREFIX
SELECT v3
FROM :TEST_TABLE
WHERE device_id = 1;
--- QUERY PLAN ---
 Append (actual rows=1728.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
         ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
               Filter: (device_id = 1)
   ->  Seq Scan on _hyper_2_7_chunk (actual rows=672.00 loops=1)
         Filter: (device_id = 1)
   ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
         ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
               Filter: (device_id = 1)

--
-- test qual pushdown
--
-- v3 is not segment by or order by column so should not be pushed down
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE v3 > 10.0
ORDER BY time,
    device_id;
--- QUERY PLAN ---
 Sort (actual rows=0.00 loops=1)
   Output: metrics_space."time", metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1, metrics_space.v2, metrics_space.v3
   Sort Key: metrics_space."time", metrics_space.device_id
   Sort Method: quicksort 
   ->  Append (actual rows=0.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id, _hyper_2_4_chunk.device_id_peer, _hyper_2_4_chunk.v0, _hyper_2_4_chunk.v1, _hyper_2_4_chunk.v2, _hyper_2_4_chunk.v3
               Vectorized Filter: (_hyper_2_4_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 720
               Batches Removed by Filter: 1
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_5_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id, _hyper_2_5_chunk.device_id_peer, _hyper_2_5_chunk.v0, _hyper_2_5_chunk.v1, _hyper_2_5_chunk.v2, _hyper_2_5_chunk.v3
               Vectorized Filter: (_hyper_2_5_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 2160
               Batches Removed by Filter: 3
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_18_chunk._ts_meta_count, compress_hyper_6_18_chunk.device_id, compress_hyper_6_18_chunk.device_id_peer, compress_hyper_6_18_chunk._ts_meta_min_3, compress_hyper_6_18_chunk._ts_meta_max_3, compress_hyper_6_18_chunk."time", compress_hyper_6_18_chunk._ts_meta_min_1, compress_hyper_6_18_chunk._ts_meta_max_1, compress_hyper_6_18_chunk.v0, compress_hyper_6_18_chunk._ts_meta_min_2, compress_hyper_6_18_chunk._ts_meta_max_2, compress_hyper_6_18_chunk.v1, compress_hyper_6_18_chunk.v2, compress_hyper_6_18_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_6_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id, _hyper_2_6_chunk.device_id_peer, _hyper_2_6_chunk.v0, _hyper_2_6_chunk.v1, _hyper_2_6_chunk.v2, _hyper_2_6_chunk.v3
               Vectorized Filter: (_hyper_2_6_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 720
               Batches Removed by Filter: 1
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_19_chunk._ts_meta_count, compress_hyper_6_19_chunk.device_id, compress_hyper_6_19_chunk.device_id_peer, compress_hyper_6_19_chunk._ts_meta_min_3, compress_hyper_6_19_chunk._ts_meta_max_3, compress_hyper_6_19_chunk."time", compress_hyper_6_19_chunk._ts_meta_min_1, compress_hyper_6_19_chunk._ts_meta_max_1, compress_hyper_6_19_chunk.v0, compress_hyper_6_19_chunk._ts_meta_min_2, compress_hyper_6_19_chunk._ts_meta_max_2, compress_hyper_6_19_chunk.v1, compress_hyper_6_19_chunk.v2, compress_hyper_6_19_chunk.v3
         ->  Seq Scan on _timescaledb_internal._hyper_2_7_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1, _hyper_2_7_chunk.v2, _hyper_2_7_chunk.v3
               Filter: (_hyper_2_7_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 672
         ->  Seq Scan on _timescaledb_internal._hyper_2_8_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id, _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.v0, _hyper_2_8_chunk.v1, _hyper_2_8_chunk.v2, _hyper_2_8_chunk.v3
               Filter: (_hyper_2_8_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 2016
         ->  Seq Scan on _timescaledb_internal._hyper_2_9_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id, _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.v0, _hyper_2_9_chunk.v1, _hyper_2_9_chunk.v2, _hyper_2_9_chunk.v3
               Filter: (_hyper_2_9_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 672
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
               Vectorized Filter: (_hyper_2_10_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 336
               Batches Removed by Filter: 1
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id, _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.v0, _hyper_2_11_chunk.v1, _hyper_2_11_chunk.v2, _hyper_2_11_chunk.v3
               Vectorized Filter: (_hyper_2_11_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 1008
               Batches Removed by Filter: 3
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
         ->  Seq Scan on _timescaledb_internal._hyper_2_12_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id, _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.v0, _hyper_2_12_chunk.v1, _hyper_2_12_chunk.v2, _hyper_2_12_chunk.v3
               Filter: (_hyper_2_12_chunk.v3 > '10'::double precision)
               Rows Removed by Filter: 336

-- device_id constraint should be pushed down
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time"
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_2_4_chunk."time"
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)
         ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed)
               Filter: (device_id = 1)
         ->  Sort (never executed)
               Sort Key: _hyper_2_10_chunk."time"
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                     ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                           Filter: (device_id = 1)

RESET enable_sort;
-- test IS NULL / IS NOT NULL
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id IS NOT NULL
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id IS NOT NULL)
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                                 Filter: (device_id IS NOT NULL)
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id IS NOT NULL)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     ->  Seq Scan on _hyper_2_7_chunk (never executed)
                           Filter: (device_id IS NOT NULL)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     ->  Seq Scan on _hyper_2_8_chunk (never executed)
                           Filter: (device_id IS NOT NULL)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     ->  Seq Scan on _hyper_2_9_chunk (never executed)
                           Filter: (device_id IS NOT NULL)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 Filter: (device_id IS NOT NULL)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 Filter: (device_id IS NOT NULL)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     ->  Seq Scan on _hyper_2_12_chunk (never executed)
                           Filter: (device_id IS NOT NULL)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id IS NULL
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=0.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=0.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id IS NULL)
                                 Rows Removed by Filter: 1
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id IS NULL)
                                 Rows Removed by Filter: 3
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id IS NULL)
                                 Rows Removed by Filter: 1
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     Sort Method: quicksort 
                     ->  Index Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_7_chunk (actual rows=0.00 loops=1)
                           Index Cond: (device_id IS NULL)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     Sort Method: quicksort 
                     ->  Index Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_8_chunk (actual rows=0.00 loops=1)
                           Index Cond: (device_id IS NULL)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     Sort Method: quicksort 
                     ->  Index Scan using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_9_chunk (actual rows=0.00 loops=1)
                           Index Cond: (device_id IS NULL)
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id IS NULL)
                                 Rows Removed by Filter: 1
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id IS NULL)
                                 Rows Removed by Filter: 3
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     Sort Method: quicksort 
                     ->  Index Scan using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v_2 on _hyper_2_12_chunk (actual rows=0.00 loops=1)
                           Index Cond: (device_id IS NULL)

-- test IN (Const,Const)
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id IN (1, 2)
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = ANY ('{1,2}'::integer[]))
               ->  Sort (actual rows=5.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = ANY ('{1,2}'::integer[]))
                                 Rows Removed by Filter: 2
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     ->  Seq Scan on _hyper_2_7_chunk (never executed)
                           Filter: (device_id = ANY ('{1,2}'::integer[]))
               ->  Sort (never executed)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     ->  Index Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_8_chunk (never executed)
                           Index Cond: (device_id = ANY ('{1,2}'::integer[]))
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 Filter: (device_id = ANY ('{1,2}'::integer[]))
               ->  Sort (never executed)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 Filter: (device_id = ANY ('{1,2}'::integer[]))

-- test cast pushdown
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = '1'::text::int
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time"
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_2_4_chunk."time"
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)
         ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed)
               Filter: (device_id = 1)
         ->  Sort (never executed)
               Sort Key: _hyper_2_10_chunk."time"
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                     ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                           Filter: (device_id = 1)

--test var op var with two segment by
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = device_id_peer
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=0.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=0.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id = device_id_peer)
                                 Rows Removed by Filter: 1
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id = device_id_peer)
                                 Rows Removed by Filter: 3
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id = device_id_peer)
                                 Rows Removed by Filter: 1
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_7_chunk (actual rows=0.00 loops=1)
                           Filter: (device_id = device_id_peer)
                           Rows Removed by Filter: 672
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_8_chunk (actual rows=0.00 loops=1)
                           Filter: (device_id = device_id_peer)
                           Rows Removed by Filter: 2016
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_9_chunk (actual rows=0.00 loops=1)
                           Filter: (device_id = device_id_peer)
                           Rows Removed by Filter: 672
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id = device_id_peer)
                                 Rows Removed by Filter: 1
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id = device_id_peer)
                                 Rows Removed by Filter: 3
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_12_chunk (actual rows=0.00 loops=1)
                           Filter: (device_id = device_id_peer)
                           Rows Removed by Filter: 336

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id_peer < device_id
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id_peer < device_id)
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                                 Filter: (device_id_peer < device_id)
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id_peer < device_id)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     ->  Seq Scan on _hyper_2_7_chunk (never executed)
                           Filter: (device_id_peer < device_id)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     ->  Seq Scan on _hyper_2_8_chunk (never executed)
                           Filter: (device_id_peer < device_id)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     ->  Seq Scan on _hyper_2_9_chunk (never executed)
                           Filter: (device_id_peer < device_id)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 Filter: (device_id_peer < device_id)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 Filter: (device_id_peer < device_id)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     ->  Seq Scan on _hyper_2_12_chunk (never executed)
                           Filter: (device_id_peer < device_id)

-- test expressions
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = 1 + 4 / 2
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time"
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_2_6_chunk."time"
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 3)
         ->  Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk (never executed)
               Filter: (device_id = 3)
         ->  Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk (never executed)
               Filter: (device_id = 3)

-- test function calls
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id = length(substring(version(), 1, 3))
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time"
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time"
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id = length("substring"(version(), 1, 3)))
                                 Rows Removed by Filter: 1
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=0.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=0.00 loops=1)
                                 Filter: (device_id = length("substring"(version(), 1, 3)))
                                 Rows Removed by Filter: 3
               ->  Sort (actual rows=10.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = length("substring"(version(), 1, 3)))
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_device_id_time_idx on _hyper_2_7_chunk (never executed)
                     Index Cond: (device_id = length("substring"(version(), 1, 3)))
               ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk (never executed)
                     Index Cond: (device_id = length("substring"(version(), 1, 3)))
               ->  Index Scan Backward using _hyper_2_9_chunk_metrics_space_device_id_time_idx on _hyper_2_9_chunk (never executed)
                     Index Cond: (device_id = length("substring"(version(), 1, 3)))
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Sort (never executed)
                     Sort Key: _hyper_2_10_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 Filter: (device_id = length("substring"(version(), 1, 3)))
               ->  Sort (never executed)
                     Sort Key: _hyper_2_11_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 Filter: (device_id = length("substring"(version(), 1, 3)))
               ->  Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk (never executed)
                     Filter: (device_id = length("substring"(version(), 1, 3)))

--
-- test segment meta pushdown
--
-- order by column and const
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time = '2000-01-01 1:00:00+0'
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=5.00 loops=1)
   ->  Merge Append (actual rows=5.00 loops=1)
         Sort Key: metrics_space.device_id
         ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=1.00 loops=1)
               Vectorized Filter: ("time" = 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               Rows Removed by Filter: 719
               ->  Sort (actual rows=1.00 loops=1)
                     Sort Key: compress_hyper_6_17_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                           Filter: ((_ts_meta_min_3 <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) AND (_ts_meta_max_3 >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=3.00 loops=1)
               Vectorized Filter: ("time" = 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               Rows Removed by Filter: 2157
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: compress_hyper_6_18_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                           Filter: ((_ts_meta_min_3 <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) AND (_ts_meta_max_3 >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=1.00 loops=1)
               Vectorized Filter: ("time" = 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               Rows Removed by Filter: 719
               ->  Sort (actual rows=1.00 loops=1)
                     Sort Key: compress_hyper_6_19_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                           Filter: ((_ts_meta_min_3 <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) AND (_ts_meta_max_3 >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone))

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time < '2000-01-01 1:00:00+0'
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=6.00 loops=1)
                           Vectorized Filter: ("time" < 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 714
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_min_3 < 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=18.00 loops=1)
                           Vectorized Filter: ("time" < 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 2142
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                                 Filter: (_ts_meta_min_3 < 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=6.00 loops=1)
                           Vectorized Filter: ("time" < 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 714
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_min_3 < 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time <= '2000-01-01 1:00:00+0'
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=7.00 loops=1)
                           Vectorized Filter: ("time" <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 713
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_min_3 <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=21.00 loops=1)
                           Vectorized Filter: ("time" <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 2139
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                                 Filter: (_ts_meta_min_3 <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=7.00 loops=1)
                           Vectorized Filter: ("time" <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 713
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_min_3 <= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time >= '2000-01-01 1:00:00+0'
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=714.00 loops=1)
                           Vectorized Filter: ("time" >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 6
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_max_3 >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2142.00 loops=1)
                           Vectorized Filter: ("time" >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 18
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                                 Filter: (_ts_meta_max_3 >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=714.00 loops=1)
                           Vectorized Filter: ("time" >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 6
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_max_3 >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     ->  Seq Scan on _hyper_2_7_chunk (never executed)
                           Filter: ("time" >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     ->  Seq Scan on _hyper_2_8_chunk (never executed)
                           Filter: ("time" >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     ->  Seq Scan on _hyper_2_9_chunk (never executed)
                           Filter: ("time" >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                           Vectorized Filter: ("time" >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 Filter: (_ts_meta_max_3 >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (never executed)
                           Vectorized Filter: ("time" >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 Filter: (_ts_meta_max_3 >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     ->  Seq Scan on _hyper_2_12_chunk (never executed)
                           Filter: ("time" >= 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-01 1:00:00+0'
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=713.00 loops=1)
                           Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 7
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2139.00 loops=1)
                           Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 21
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                                 Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=713.00 loops=1)
                           Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 7
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     ->  Seq Scan on _hyper_2_7_chunk (never executed)
                           Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     ->  Seq Scan on _hyper_2_8_chunk (never executed)
                           Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     ->  Seq Scan on _hyper_2_9_chunk (never executed)
                           Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                           Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (never executed)
                           Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     ->  Seq Scan on _hyper_2_12_chunk (never executed)
                           Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE '2000-01-01 1:00:00+0' < time
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=713.00 loops=1)
                           Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 7
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2139.00 loops=1)
                           Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 21
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                                 Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=713.00 loops=1)
                           Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           Rows Removed by Filter: 7
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     ->  Seq Scan on _hyper_2_7_chunk (never executed)
                           Filter: ('Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone < "time")
               ->  Sort (never executed)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     ->  Seq Scan on _hyper_2_8_chunk (never executed)
                           Filter: ('Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone < "time")
               ->  Sort (never executed)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     ->  Seq Scan on _hyper_2_9_chunk (never executed)
                           Filter: ('Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone < "time")
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                           Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (never executed)
                           Vectorized Filter: ("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                           ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 Filter: (_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     ->  Seq Scan on _hyper_2_12_chunk (never executed)
                           Filter: ('Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone < "time")

--pushdowns between order by and segment by columns
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE v0 < 1
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=0.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=0.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=0.00 loops=1)
                           Vectorized Filter: (v0 < 1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=0.00 loops=1)
                                 Filter: (_ts_meta_min_1 < 1)
                                 Rows Removed by Filter: 1
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=0.00 loops=1)
                           Vectorized Filter: (v0 < 1)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=0.00 loops=1)
                                 Filter: (_ts_meta_min_1 < 1)
                                 Rows Removed by Filter: 3
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=0.00 loops=1)
                           Vectorized Filter: (v0 < 1)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=0.00 loops=1)
                                 Filter: (_ts_meta_min_1 < 1)
                                 Rows Removed by Filter: 1
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     Sort Method: quicksort 
                     ->  Index Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_7_chunk (actual rows=0.00 loops=1)
                           Index Cond: (v0 < 1)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     Sort Method: quicksort 
                     ->  Index Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_8_chunk (actual rows=0.00 loops=1)
                           Index Cond: (v0 < 1)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     Sort Method: quicksort 
                     ->  Index Scan using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_9_chunk (actual rows=0.00 loops=1)
                           Index Cond: (v0 < 1)
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=0.00 loops=1)
                           Vectorized Filter: (v0 < 1)
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=0.00 loops=1)
                                 Filter: (_ts_meta_min_1 < 1)
                                 Rows Removed by Filter: 1
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=0.00 loops=1)
                           Vectorized Filter: (v0 < 1)
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=0.00 loops=1)
                                 Filter: (_ts_meta_min_1 < 1)
                                 Rows Removed by Filter: 3
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_12_chunk (actual rows=0.00 loops=1)
                           Filter: (v0 < 1)
                           Rows Removed by Filter: 336

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE v0 < device_id
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=0.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=0.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=0.00 loops=1)
                           Filter: (v0 < device_id)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=0.00 loops=1)
                                 Filter: (_ts_meta_min_1 < device_id)
                                 Rows Removed by Filter: 1
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=0.00 loops=1)
                           Filter: (v0 < device_id)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=0.00 loops=1)
                                 Filter: (_ts_meta_min_1 < device_id)
                                 Rows Removed by Filter: 3
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=0.00 loops=1)
                           Filter: (v0 < device_id)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=0.00 loops=1)
                                 Filter: (_ts_meta_min_1 < device_id)
                                 Rows Removed by Filter: 1
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_7_chunk (actual rows=0.00 loops=1)
                           Filter: (v0 < device_id)
                           Rows Removed by Filter: 672
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_8_chunk (actual rows=0.00 loops=1)
                           Filter: (v0 < device_id)
                           Rows Removed by Filter: 2016
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_9_chunk (actual rows=0.00 loops=1)
                           Filter: (v0 < device_id)
                           Rows Removed by Filter: 672
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=0.00 loops=1)
                           Filter: (v0 < device_id)
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=0.00 loops=1)
                                 Filter: (_ts_meta_min_1 < device_id)
                                 Rows Removed by Filter: 1
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=0.00 loops=1)
                           Filter: (v0 < device_id)
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=0.00 loops=1)
                                 Filter: (_ts_meta_min_1 < device_id)
                                 Rows Removed by Filter: 3
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_12_chunk (actual rows=0.00 loops=1)
                           Filter: (v0 < device_id)
                           Rows Removed by Filter: 336

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE device_id < v0
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                           Filter: (device_id < v0)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_max_1 > device_id)
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
                           Filter: (device_id < v0)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                                 Filter: (_ts_meta_max_1 > device_id)
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
                           Filter: (device_id < v0)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_max_1 > device_id)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     ->  Seq Scan on _hyper_2_7_chunk (never executed)
                           Filter: (device_id < v0)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     ->  Seq Scan on _hyper_2_8_chunk (never executed)
                           Filter: (device_id < v0)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     ->  Seq Scan on _hyper_2_9_chunk (never executed)
                           Filter: (device_id < v0)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                           Filter: (device_id < v0)
                           ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 Filter: (_ts_meta_max_1 > device_id)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (never executed)
                           Filter: (device_id < v0)
                           ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 Filter: (_ts_meta_max_1 > device_id)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     ->  Seq Scan on _hyper_2_12_chunk (never executed)
                           Filter: (device_id < v0)

:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE v1 = device_id
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=0.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=0.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=0.00 loops=1)
                           Filter: (v1 = (device_id)::double precision)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=0.00 loops=1)
                                 Filter: ((_ts_meta_min_2 <= (device_id)::double precision) AND (_ts_meta_max_2 >= (device_id)::double precision))
                                 Rows Removed by Filter: 1
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=0.00 loops=1)
                           Filter: (v1 = (device_id)::double precision)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=0.00 loops=1)
                                 Filter: ((_ts_meta_min_2 <= (device_id)::double precision) AND (_ts_meta_max_2 >= (device_id)::double precision))
                                 Rows Removed by Filter: 3
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=0.00 loops=1)
                           Filter: (v1 = (device_id)::double precision)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=0.00 loops=1)
                                 Filter: ((_ts_meta_min_2 <= (device_id)::double precision) AND (_ts_meta_max_2 >= (device_id)::double precision))
                                 Rows Removed by Filter: 1
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_7_chunk (actual rows=0.00 loops=1)
                           Filter: (v1 = (device_id)::double precision)
                           Rows Removed by Filter: 672
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_8_chunk (actual rows=0.00 loops=1)
                           Filter: (v1 = (device_id)::double precision)
                           Rows Removed by Filter: 2016
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_9_chunk (actual rows=0.00 loops=1)
                           Filter: (v1 = (device_id)::double precision)
                           Rows Removed by Filter: 672
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=0.00 loops=1)
                           Filter: (v1 = (device_id)::double precision)
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=0.00 loops=1)
                                 Filter: ((_ts_meta_min_2 <= (device_id)::double precision) AND (_ts_meta_max_2 >= (device_id)::double precision))
                                 Rows Removed by Filter: 1
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=0.00 loops=1)
                           Filter: (v1 = (device_id)::double precision)
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=0.00 loops=1)
                                 Filter: ((_ts_meta_min_2 <= (device_id)::double precision) AND (_ts_meta_max_2 >= (device_id)::double precision))
                                 Rows Removed by Filter: 3
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_12_chunk (actual rows=0.00 loops=1)
                           Filter: (v1 = (device_id)::double precision)
                           Rows Removed by Filter: 336

--pushdown between two order by column (not pushed down)
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE v0 = v1
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=0.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=0.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=0.00 loops=1)
                           Filter: ((v0)::double precision = v1)
                           Rows Removed by Filter: 720
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=0.00 loops=1)
                           Filter: ((v0)::double precision = v1)
                           Rows Removed by Filter: 2160
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=0.00 loops=1)
                           Filter: ((v0)::double precision = v1)
                           Rows Removed by Filter: 720
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_7_chunk (actual rows=0.00 loops=1)
                           Filter: ((v0)::double precision = v1)
                           Rows Removed by Filter: 672
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_8_chunk (actual rows=0.00 loops=1)
                           Filter: ((v0)::double precision = v1)
                           Rows Removed by Filter: 2016
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_9_chunk (actual rows=0.00 loops=1)
                           Filter: ((v0)::double precision = v1)
                           Rows Removed by Filter: 672
         ->  Merge Append (actual rows=0.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=0.00 loops=1)
                           Filter: ((v0)::double precision = v1)
                           Rows Removed by Filter: 336
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=0.00 loops=1)
                           Filter: ((v0)::double precision = v1)
                           Rows Removed by Filter: 1008
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     Sort Method: quicksort 
                     ->  Seq Scan on _hyper_2_12_chunk (actual rows=0.00 loops=1)
                           Filter: ((v0)::double precision = v1)
                           Rows Removed by Filter: 336

--pushdown of quals on order by and segment by cols anded together
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-01 1:00:00+0'
    AND device_id = 1
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   Output: metrics_space."time", metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1, metrics_space.v2, metrics_space.v3
   ->  Custom Scan (ChunkAppend) on public.metrics_space (actual rows=10.00 loops=1)
         Output: metrics_space."time", metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1, metrics_space.v2, metrics_space.v3
         Order: metrics_space."time"
         Startup Exclusion: false
         Runtime Exclusion: false
         ->  Sort (actual rows=10.00 loops=1)
               Output: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id, _hyper_2_4_chunk.device_id_peer, _hyper_2_4_chunk.v0, _hyper_2_4_chunk.v1, _hyper_2_4_chunk.v2, _hyper_2_4_chunk.v3
               Sort Key: _hyper_2_4_chunk."time"
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=713.00 loops=1)
                     Output: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id, _hyper_2_4_chunk.device_id_peer, _hyper_2_4_chunk.v0, _hyper_2_4_chunk.v1, _hyper_2_4_chunk.v2, _hyper_2_4_chunk.v3
                     Vectorized Filter: (_hyper_2_4_chunk."time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                     Rows Removed by Filter: 7
                     Bulk Decompression: true
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                           Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
                           Filter: ((compress_hyper_6_17_chunk._ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) AND (compress_hyper_6_17_chunk.device_id = 1))
         ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _timescaledb_internal._hyper_2_7_chunk (never executed)
               Output: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1, _hyper_2_7_chunk.v2, _hyper_2_7_chunk.v3
               Index Cond: (_hyper_2_7_chunk."time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
               Filter: (_hyper_2_7_chunk.device_id = 1)
         ->  Sort (never executed)
               Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
               Sort Key: _hyper_2_10_chunk."time"
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (never executed)
                     Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
                     Vectorized Filter: (_hyper_2_10_chunk."time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone)
                     Bulk Decompression: true
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (never executed)
                           Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                           Filter: ((compress_hyper_6_20_chunk._ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) AND (compress_hyper_6_20_chunk.device_id = 1))

--pushdown of quals on order by and segment by cols or together (not pushed down)
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-01 1:00:00+0'
    OR device_id = 1
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=9.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                           Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
               ->  Sort (actual rows=2.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2139.00 loops=1)
                           Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
                           Rows Removed by Filter: 21
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                                 Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
               ->  Sort (actual rows=1.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=713.00 loops=1)
                           Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
                           Rows Removed by Filter: 7
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                                 Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     ->  Seq Scan on _hyper_2_7_chunk (never executed)
                           Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
               ->  Sort (never executed)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     ->  Seq Scan on _hyper_2_8_chunk (never executed)
                           Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
               ->  Sort (never executed)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     ->  Seq Scan on _hyper_2_9_chunk (never executed)
                           Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                           Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
                           ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
               ->  Sort (never executed)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (never executed)
                           Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
                           ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))
               ->  Sort (never executed)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     ->  Seq Scan on _hyper_2_12_chunk (never executed)
                           Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1))

--functions are pushed down as well
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time < now()
ORDER BY time,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time", metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                           Vectorized Filter: ("time" < now())
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_min_3 < now())
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
                           Vectorized Filter: ("time" < now())
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                                 Filter: (_ts_meta_min_3 < now())
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
                           Vectorized Filter: ("time" < now())
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                                 Filter: (_ts_meta_min_3 < now())
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
                     ->  Seq Scan on _hyper_2_7_chunk (never executed)
                           Filter: ("time" < now())
               ->  Sort (never executed)
                     Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
                     ->  Seq Scan on _hyper_2_8_chunk (never executed)
                           Filter: ("time" < now())
               ->  Sort (never executed)
                     Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
                     ->  Seq Scan on _hyper_2_9_chunk (never executed)
                           Filter: ("time" < now())
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time", metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                           Vectorized Filter: ("time" < now())
                           ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 Filter: (_ts_meta_min_3 < now())
               ->  Sort (never executed)
                     Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (never executed)
                           Vectorized Filter: ("time" < now())
                           ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 Filter: (_ts_meta_min_3 < now())
               ->  Sort (never executed)
                     Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
                     ->  Seq Scan on _hyper_2_12_chunk (never executed)
                           Filter: ("time" < now())

-- test sort optimization interaction
:PREFIX
SELECT time
FROM :TEST_TABLE
ORDER BY time DESC
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time" DESC
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time" DESC
               ->  Index Only Scan using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk (actual rows=3.00 loops=1)
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_11_chunk."time" DESC
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_10_chunk."time" DESC
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time" DESC
               ->  Index Only Scan using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk (never executed)
               ->  Index Only Scan using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk (never executed)
               ->  Index Only Scan using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time" DESC
               ->  Sort (never executed)
                     Sort Key: _hyper_2_6_chunk."time" DESC
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_19_chunk (never executed)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_5_chunk."time" DESC
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_18_chunk (never executed)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_4_chunk."time" DESC
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_17_chunk (never executed)

:PREFIX
SELECT time,
    device_id
FROM :TEST_TABLE
ORDER BY time DESC,
    device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time" DESC, metrics_space.device_id
         ->  Merge Append (actual rows=10.00 loops=1)
               Sort Key: metrics_space."time" DESC, metrics_space.device_id
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_12_chunk."time" DESC, _hyper_2_12_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Seq Scan on _hyper_2_12_chunk (actual rows=336.00 loops=1)
               ->  Sort (actual rows=6.00 loops=1)
                     Sort Key: _hyper_2_11_chunk."time" DESC, _hyper_2_11_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
               ->  Sort (actual rows=3.00 loops=1)
                     Sort Key: _hyper_2_10_chunk."time" DESC, _hyper_2_10_chunk.device_id
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time" DESC, metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_9_chunk."time" DESC, _hyper_2_9_chunk.device_id
                     ->  Seq Scan on _hyper_2_9_chunk (never executed)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_8_chunk."time" DESC, _hyper_2_8_chunk.device_id
                     ->  Seq Scan on _hyper_2_8_chunk (never executed)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_7_chunk."time" DESC, _hyper_2_7_chunk.device_id
                     ->  Seq Scan on _hyper_2_7_chunk (never executed)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time" DESC, metrics_space.device_id
               ->  Sort (never executed)
                     Sort Key: _hyper_2_6_chunk."time" DESC, _hyper_2_6_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_19_chunk (never executed)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_5_chunk."time" DESC, _hyper_2_5_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_18_chunk (never executed)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_4_chunk."time" DESC, _hyper_2_4_chunk.device_id
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_17_chunk (never executed)

:PREFIX
SELECT time,
    device_id
FROM :TEST_TABLE
ORDER BY device_id,
    time DESC
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Merge Append (actual rows=10.00 loops=1)
         Sort Key: metrics_space.device_id, metrics_space."time" DESC
         ->  Sort (actual rows=1.00 loops=1)
               Sort Key: _hyper_2_4_chunk.device_id, _hyper_2_4_chunk."time" DESC
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
         ->  Sort (actual rows=1.00 loops=1)
               Sort Key: _hyper_2_5_chunk.device_id, _hyper_2_5_chunk."time" DESC
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
         ->  Sort (actual rows=1.00 loops=1)
               Sort Key: _hyper_2_6_chunk.device_id, _hyper_2_6_chunk."time" DESC
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
         ->  Index Only Scan using _hyper_2_7_chunk_metrics_space_device_id_time_idx on _hyper_2_7_chunk (actual rows=1.00 loops=1)
         ->  Index Only Scan using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk (actual rows=1.00 loops=1)
         ->  Index Only Scan using _hyper_2_9_chunk_metrics_space_device_id_time_idx on _hyper_2_9_chunk (actual rows=1.00 loops=1)
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_2_10_chunk.device_id, _hyper_2_10_chunk."time" DESC
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
         ->  Sort (actual rows=1.00 loops=1)
               Sort Key: _hyper_2_11_chunk.device_id, _hyper_2_11_chunk."time" DESC
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
         ->  Index Only Scan using _hyper_2_12_chunk_metrics_space_device_id_time_idx on _hyper_2_12_chunk (actual rows=1.00 loops=1)

--
-- test ordered path
--
-- should not produce ordered path
-- This plan is flaky between MergeAppend over Sorts and Sort over Append
SET enable_sort TO off;
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY time,
    device_id;
--- QUERY PLAN ---
 Sort (actual rows=3915.00 loops=1)
   Output: metrics_space."time", metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1, metrics_space.v2, metrics_space.v3
   Sort Key: metrics_space."time", metrics_space.device_id
   Sort Method: quicksort 
   ->  Append (actual rows=3915.00 loops=1)
         ->  Seq Scan on _timescaledb_internal._hyper_2_7_chunk (actual rows=447.00 loops=1)
               Output: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1, _hyper_2_7_chunk.v2, _hyper_2_7_chunk.v3
               Filter: (_hyper_2_7_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 225
         ->  Seq Scan on _timescaledb_internal._hyper_2_8_chunk (actual rows=1341.00 loops=1)
               Output: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id, _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.v0, _hyper_2_8_chunk.v1, _hyper_2_8_chunk.v2, _hyper_2_8_chunk.v3
               Filter: (_hyper_2_8_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 675
         ->  Seq Scan on _timescaledb_internal._hyper_2_9_chunk (actual rows=447.00 loops=1)
               Output: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id, _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.v0, _hyper_2_9_chunk.v1, _hyper_2_9_chunk.v2, _hyper_2_9_chunk.v3
               Filter: (_hyper_2_9_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 225
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
               Vectorized Filter: (_hyper_2_10_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Filter: (compress_hyper_6_20_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1008.00 loops=1)
               Output: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id, _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.v0, _hyper_2_11_chunk.v1, _hyper_2_11_chunk.v2, _hyper_2_11_chunk.v3
               Vectorized Filter: (_hyper_2_11_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                     Filter: (compress_hyper_6_21_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Seq Scan on _timescaledb_internal._hyper_2_12_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id, _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.v0, _hyper_2_12_chunk.v1, _hyper_2_12_chunk.v2, _hyper_2_12_chunk.v3
               Filter: (_hyper_2_12_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)

RESET enable_sort;
-- should produce ordered path
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer,
    v0,
    v1 DESC,
    time;
--- QUERY PLAN ---
 Merge Append (actual rows=3915.00 loops=1)
   Sort Key: metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1 DESC, metrics_space."time"
   ->  Index Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_7_chunk (actual rows=447.00 loops=1)
         Output: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1, _hyper_2_7_chunk.v2, _hyper_2_7_chunk.v3
         Index Cond: (_hyper_2_7_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_8_chunk (actual rows=1341.00 loops=1)
         Output: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id, _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.v0, _hyper_2_8_chunk.v1, _hyper_2_8_chunk.v2, _hyper_2_8_chunk.v3
         Index Cond: (_hyper_2_8_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_9_chunk (actual rows=447.00 loops=1)
         Output: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id, _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.v0, _hyper_2_9_chunk.v1, _hyper_2_9_chunk.v2, _hyper_2_9_chunk.v3
         Index Cond: (_hyper_2_9_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
         Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
         Vectorized Filter: (_hyper_2_10_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         Bulk Decompression: true
         ->  Sort (actual rows=1.00 loops=1)
               Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
               Sort Key: compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk._ts_meta_min_2 DESC, compress_hyper_6_20_chunk._ts_meta_max_2 DESC, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3
               Sort Method: quicksort 
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Filter: (compress_hyper_6_20_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1008.00 loops=1)
         Output: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id, _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.v0, _hyper_2_11_chunk.v1, _hyper_2_11_chunk.v2, _hyper_2_11_chunk.v3
         Vectorized Filter: (_hyper_2_11_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         Bulk Decompression: true
         ->  Sort (actual rows=3.00 loops=1)
               Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
               Sort Key: compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk._ts_meta_min_2 DESC, compress_hyper_6_21_chunk._ts_meta_max_2 DESC, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3
               Sort Method: quicksort 
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                     Filter: (compress_hyper_6_21_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v1_ on _timescaledb_internal._hyper_2_12_chunk (actual rows=336.00 loops=1)
         Output: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id, _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.v0, _hyper_2_12_chunk.v1, _hyper_2_12_chunk.v2, _hyper_2_12_chunk.v3
         Index Cond: (_hyper_2_12_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)

-- test order by columns not in targetlist
:PREFIX_VERBOSE
SELECT device_id,
    device_id_peer
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer,
    v0,
    v1 DESC,
    time
LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   Output: metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1, metrics_space."time"
   ->  Merge Append (actual rows=100.00 loops=1)
         Sort Key: metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1 DESC, metrics_space."time"
         ->  Index Only Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_7_chunk (actual rows=100.00 loops=1)
               Output: _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1, _hyper_2_7_chunk."time"
               Index Cond: (_hyper_2_7_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Index Only Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_8_chunk (actual rows=1.00 loops=1)
               Output: _hyper_2_8_chunk.device_id, _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.v0, _hyper_2_8_chunk.v1, _hyper_2_8_chunk."time"
               Index Cond: (_hyper_2_8_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Index Only Scan using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_9_chunk (actual rows=1.00 loops=1)
               Output: _hyper_2_9_chunk.device_id, _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.v0, _hyper_2_9_chunk.v1, _hyper_2_9_chunk."time"
               Index Cond: (_hyper_2_9_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=1.00 loops=1)
               Output: _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk."time"
               Vectorized Filter: (_hyper_2_10_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Sort (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Sort Key: compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk._ts_meta_min_2 DESC, compress_hyper_6_20_chunk._ts_meta_max_2 DESC, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3
                     Sort Method: quicksort 
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                           Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                           Filter: (compress_hyper_6_20_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1.00 loops=1)
               Output: _hyper_2_11_chunk.device_id, _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.v0, _hyper_2_11_chunk.v1, _hyper_2_11_chunk."time"
               Vectorized Filter: (_hyper_2_11_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Sort (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                     Sort Key: compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk._ts_meta_min_2 DESC, compress_hyper_6_21_chunk._ts_meta_max_2 DESC, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3
                     Sort Method: quicksort 
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                           Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                           Filter: (compress_hyper_6_21_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Index Only Scan using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v1_ on _timescaledb_internal._hyper_2_12_chunk (actual rows=1.00 loops=1)
               Output: _hyper_2_12_chunk.device_id, _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.v0, _hyper_2_12_chunk.v1, _hyper_2_12_chunk."time"
               Index Cond: (_hyper_2_12_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)

-- test ordering only by segmentby columns
-- should produce ordered path and not have sequence number in targetlist of compressed scan
:PREFIX_VERBOSE
SELECT device_id,
    device_id_peer
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer
LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   Output: metrics_space.device_id, metrics_space.device_id_peer
   ->  Merge Append (actual rows=100.00 loops=1)
         Sort Key: metrics_space.device_id, metrics_space.device_id_peer
         ->  Index Only Scan Backward using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_7_chunk (actual rows=100.00 loops=1)
               Output: _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer
               Index Cond: (_hyper_2_7_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Index Only Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_8_chunk (actual rows=1.00 loops=1)
               Output: _hyper_2_8_chunk.device_id, _hyper_2_8_chunk.device_id_peer
               Index Cond: (_hyper_2_8_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Index Only Scan Backward using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_9_chunk (actual rows=1.00 loops=1)
               Output: _hyper_2_9_chunk.device_id, _hyper_2_9_chunk.device_id_peer
               Index Cond: (_hyper_2_9_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=1.00 loops=1)
               Output: _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer
               Vectorized Filter: (_hyper_2_10_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Sort (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Sort Key: compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer
                     Sort Method: quicksort 
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                           Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                           Filter: (compress_hyper_6_20_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1.00 loops=1)
               Output: _hyper_2_11_chunk.device_id, _hyper_2_11_chunk.device_id_peer
               Vectorized Filter: (_hyper_2_11_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Sort (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                     Sort Key: compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer
                     Sort Method: quicksort 
                     ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                           Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                           Filter: (compress_hyper_6_21_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Index Only Scan Backward using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v_2 on _timescaledb_internal._hyper_2_12_chunk (actual rows=1.00 loops=1)
               Output: _hyper_2_12_chunk.device_id, _hyper_2_12_chunk.device_id_peer
               Index Cond: (_hyper_2_12_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)

-- should produce ordered path
-- only referencing PREFIX_VERBOSE should work
:PREFIX_VERBOSE
SELECT device_id,
    device_id_peer,
    v0
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer,
    v0;
--- QUERY PLAN ---
 Merge Append (actual rows=3915.00 loops=1)
   Sort Key: metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0
   ->  Index Only Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_7_chunk (actual rows=447.00 loops=1)
         Output: _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0
         Index Cond: (_hyper_2_7_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Only Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_8_chunk (actual rows=1341.00 loops=1)
         Output: _hyper_2_8_chunk.device_id, _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.v0
         Index Cond: (_hyper_2_8_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Only Scan using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_9_chunk (actual rows=447.00 loops=1)
         Output: _hyper_2_9_chunk.device_id, _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.v0
         Index Cond: (_hyper_2_9_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
         Output: _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0
         Vectorized Filter: (_hyper_2_10_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         Bulk Decompression: true
         ->  Sort (actual rows=1.00 loops=1)
               Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
               Sort Key: compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1
               Sort Method: quicksort 
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Filter: (compress_hyper_6_20_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1008.00 loops=1)
         Output: _hyper_2_11_chunk.device_id, _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.v0
         Vectorized Filter: (_hyper_2_11_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         Bulk Decompression: true
         ->  Sort (actual rows=3.00 loops=1)
               Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
               Sort Key: compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1
               Sort Method: quicksort 
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                     Filter: (compress_hyper_6_21_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Only Scan using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v1_ on _timescaledb_internal._hyper_2_12_chunk (actual rows=336.00 loops=1)
         Output: _hyper_2_12_chunk.device_id, _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.v0
         Index Cond: (_hyper_2_12_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)

-- should produce ordered path
-- only referencing PREFIX_VERBOSE should work
:PREFIX_VERBOSE
SELECT device_id,
    device_id_peer,
    v0,
    v1
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer,
    v0,
    v1 DESC;
--- QUERY PLAN ---
 Merge Append (actual rows=3915.00 loops=1)
   Sort Key: metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1 DESC
   ->  Index Only Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_7_chunk (actual rows=447.00 loops=1)
         Output: _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1
         Index Cond: (_hyper_2_7_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Only Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_8_chunk (actual rows=1341.00 loops=1)
         Output: _hyper_2_8_chunk.device_id, _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.v0, _hyper_2_8_chunk.v1
         Index Cond: (_hyper_2_8_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Only Scan using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_t on _timescaledb_internal._hyper_2_9_chunk (actual rows=447.00 loops=1)
         Output: _hyper_2_9_chunk.device_id, _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.v0, _hyper_2_9_chunk.v1
         Index Cond: (_hyper_2_9_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
         Output: _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1
         Vectorized Filter: (_hyper_2_10_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         Bulk Decompression: true
         ->  Sort (actual rows=1.00 loops=1)
               Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
               Sort Key: compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk._ts_meta_min_2 DESC, compress_hyper_6_20_chunk._ts_meta_max_2 DESC
               Sort Method: quicksort 
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Filter: (compress_hyper_6_20_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1008.00 loops=1)
         Output: _hyper_2_11_chunk.device_id, _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.v0, _hyper_2_11_chunk.v1
         Vectorized Filter: (_hyper_2_11_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         Bulk Decompression: true
         ->  Sort (actual rows=3.00 loops=1)
               Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
               Sort Key: compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk._ts_meta_min_2 DESC, compress_hyper_6_21_chunk._ts_meta_max_2 DESC
               Sort Method: quicksort 
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                     Filter: (compress_hyper_6_21_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Only Scan using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v1_ on _timescaledb_internal._hyper_2_12_chunk (actual rows=336.00 loops=1)
         Output: _hyper_2_12_chunk.device_id, _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.v0, _hyper_2_12_chunk.v1
         Index Cond: (_hyper_2_12_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)

-- These plans are flaky between MergeAppend and Sort over Append.
SET enable_sort TO OFF;
-- should not produce ordered path.
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id,
    device_id_peer,
    v0,
    v1 DESC,
    time,
    v3;
--- QUERY PLAN ---
 Sort (actual rows=3915.00 loops=1)
   Output: metrics_space."time", metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1, metrics_space.v2, metrics_space.v3
   Sort Key: metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1 DESC, metrics_space."time", metrics_space.v3
   Sort Method: quicksort 
   ->  Append (actual rows=3915.00 loops=1)
         ->  Seq Scan on _timescaledb_internal._hyper_2_7_chunk (actual rows=447.00 loops=1)
               Output: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1, _hyper_2_7_chunk.v2, _hyper_2_7_chunk.v3
               Filter: (_hyper_2_7_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 225
         ->  Seq Scan on _timescaledb_internal._hyper_2_8_chunk (actual rows=1341.00 loops=1)
               Output: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id, _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.v0, _hyper_2_8_chunk.v1, _hyper_2_8_chunk.v2, _hyper_2_8_chunk.v3
               Filter: (_hyper_2_8_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 675
         ->  Seq Scan on _timescaledb_internal._hyper_2_9_chunk (actual rows=447.00 loops=1)
               Output: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id, _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.v0, _hyper_2_9_chunk.v1, _hyper_2_9_chunk.v2, _hyper_2_9_chunk.v3
               Filter: (_hyper_2_9_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 225
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
               Vectorized Filter: (_hyper_2_10_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Filter: (compress_hyper_6_20_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1008.00 loops=1)
               Output: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id, _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.v0, _hyper_2_11_chunk.v1, _hyper_2_11_chunk.v2, _hyper_2_11_chunk.v3
               Vectorized Filter: (_hyper_2_11_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                     Filter: (compress_hyper_6_21_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Seq Scan on _timescaledb_internal._hyper_2_12_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id, _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.v0, _hyper_2_12_chunk.v1, _hyper_2_12_chunk.v2, _hyper_2_12_chunk.v3
               Filter: (_hyper_2_12_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)

-- should produce ordered path
-- ASC/DESC for segmentby columns can be pushed down
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id DESC,
    device_id_peer DESC,
    v0,
    v1 DESC,
    time;
--- QUERY PLAN ---
 Sort (actual rows=3915.00 loops=1)
   Output: metrics_space."time", metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1, metrics_space.v2, metrics_space.v3
   Sort Key: metrics_space.device_id DESC, metrics_space.device_id_peer DESC, metrics_space.v0, metrics_space.v1 DESC, metrics_space."time"
   Sort Method: quicksort 
   ->  Append (actual rows=3915.00 loops=1)
         ->  Seq Scan on _timescaledb_internal._hyper_2_7_chunk (actual rows=447.00 loops=1)
               Output: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1, _hyper_2_7_chunk.v2, _hyper_2_7_chunk.v3
               Filter: (_hyper_2_7_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 225
         ->  Seq Scan on _timescaledb_internal._hyper_2_8_chunk (actual rows=1341.00 loops=1)
               Output: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id, _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.v0, _hyper_2_8_chunk.v1, _hyper_2_8_chunk.v2, _hyper_2_8_chunk.v3
               Filter: (_hyper_2_8_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 675
         ->  Seq Scan on _timescaledb_internal._hyper_2_9_chunk (actual rows=447.00 loops=1)
               Output: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id, _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.v0, _hyper_2_9_chunk.v1, _hyper_2_9_chunk.v2, _hyper_2_9_chunk.v3
               Filter: (_hyper_2_9_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 225
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
               Vectorized Filter: (_hyper_2_10_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Filter: (compress_hyper_6_20_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1008.00 loops=1)
               Output: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id, _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.v0, _hyper_2_11_chunk.v1, _hyper_2_11_chunk.v2, _hyper_2_11_chunk.v3
               Vectorized Filter: (_hyper_2_11_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                     Filter: (compress_hyper_6_21_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Seq Scan on _timescaledb_internal._hyper_2_12_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id, _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.v0, _hyper_2_12_chunk.v1, _hyper_2_12_chunk.v2, _hyper_2_12_chunk.v3
               Filter: (_hyper_2_12_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)

-- should not produce ordered path
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY device_id DESC,
    device_id_peer DESC,
    v0,
    v1,
    time;
--- QUERY PLAN ---
 Sort (actual rows=3915.00 loops=1)
   Output: metrics_space."time", metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1, metrics_space.v2, metrics_space.v3
   Sort Key: metrics_space.device_id DESC, metrics_space.device_id_peer DESC, metrics_space.v0, metrics_space.v1, metrics_space."time"
   Sort Method: quicksort 
   ->  Append (actual rows=3915.00 loops=1)
         ->  Seq Scan on _timescaledb_internal._hyper_2_7_chunk (actual rows=447.00 loops=1)
               Output: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1, _hyper_2_7_chunk.v2, _hyper_2_7_chunk.v3
               Filter: (_hyper_2_7_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 225
         ->  Seq Scan on _timescaledb_internal._hyper_2_8_chunk (actual rows=1341.00 loops=1)
               Output: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id, _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.v0, _hyper_2_8_chunk.v1, _hyper_2_8_chunk.v2, _hyper_2_8_chunk.v3
               Filter: (_hyper_2_8_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 675
         ->  Seq Scan on _timescaledb_internal._hyper_2_9_chunk (actual rows=447.00 loops=1)
               Output: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id, _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.v0, _hyper_2_9_chunk.v1, _hyper_2_9_chunk.v2, _hyper_2_9_chunk.v3
               Filter: (_hyper_2_9_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 225
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
               Vectorized Filter: (_hyper_2_10_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Filter: (compress_hyper_6_20_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1008.00 loops=1)
               Output: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id, _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.v0, _hyper_2_11_chunk.v1, _hyper_2_11_chunk.v2, _hyper_2_11_chunk.v3
               Vectorized Filter: (_hyper_2_11_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Bulk Decompression: true
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                     Filter: (compress_hyper_6_21_chunk._ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Seq Scan on _timescaledb_internal._hyper_2_12_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id, _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.v0, _hyper_2_12_chunk.v1, _hyper_2_12_chunk.v2, _hyper_2_12_chunk.v3
               Filter: (_hyper_2_12_chunk."time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)

--
-- test constraint exclusion
--
-- test plan time exclusion
-- first chunk should be excluded
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'
ORDER BY time,
    device_id;
--- QUERY PLAN ---
 Sort (actual rows=3915.00 loops=1)
   Sort Key: metrics_space."time", metrics_space.device_id
   Sort Method: quicksort 
   ->  Append (actual rows=3915.00 loops=1)
         ->  Seq Scan on _hyper_2_7_chunk (actual rows=447.00 loops=1)
               Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 225
         ->  Seq Scan on _hyper_2_8_chunk (actual rows=1341.00 loops=1)
               Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 675
         ->  Seq Scan on _hyper_2_9_chunk (actual rows=447.00 loops=1)
               Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               Rows Removed by Filter: 225
         ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
               Vectorized Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Filter: (_ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
               Vectorized Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
               ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Filter: (_ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_2_12_chunk (actual rows=336.00 loops=1)
               Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)

RESET enable_sort;
-- test runtime exclusion
-- first chunk should be excluded
:PREFIX
SELECT *
FROM :TEST_TABLE
WHERE time > '2000-01-08'::text::timestamptz
ORDER BY time,
    device_id;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_space (actual rows=3915.00 loops=1)
   Order: metrics_space."time", metrics_space.device_id
   ->  Merge Append (actual rows=0.00 loops=1)
         Sort Key: metrics_space."time", metrics_space.device_id
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=0.00 loops=1)
                     Vectorized Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone)
                     ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=0.00 loops=1)
                           Filter: (_ts_meta_max_3 > ('2000-01-08'::cstring)::timestamp with time zone)
                           Rows Removed by Filter: 1
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=0.00 loops=1)
                     Vectorized Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone)
                     ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=0.00 loops=1)
                           Filter: (_ts_meta_max_3 > ('2000-01-08'::cstring)::timestamp with time zone)
                           Rows Removed by Filter: 3
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=0.00 loops=1)
                     Vectorized Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone)
                     ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=0.00 loops=1)
                           Filter: (_ts_meta_max_3 > ('2000-01-08'::cstring)::timestamp with time zone)
                           Rows Removed by Filter: 1
   ->  Merge Append (actual rows=2235.00 loops=1)
         Sort Key: metrics_space."time", metrics_space.device_id
         ->  Sort (actual rows=447.00 loops=1)
               Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
               Sort Method: quicksort 
               ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (actual rows=447.00 loops=1)
                     Index Cond: ("time" > ('2000-01-08'::cstring)::timestamp with time zone)
         ->  Sort (actual rows=1341.00 loops=1)
               Sort Key: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id
               Sort Method: quicksort 
               ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk (actual rows=1341.00 loops=1)
                     Index Cond: ("time" > ('2000-01-08'::cstring)::timestamp with time zone)
         ->  Sort (actual rows=447.00 loops=1)
               Sort Key: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id
               Sort Method: quicksort 
               ->  Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk (actual rows=447.00 loops=1)
                     Index Cond: ("time" > ('2000-01-08'::cstring)::timestamp with time zone)
   ->  Merge Append (actual rows=1680.00 loops=1)
         Sort Key: metrics_space."time", metrics_space.device_id
         ->  Sort (actual rows=336.00 loops=1)
               Sort Key: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                     Vectorized Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone)
                     ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                           Filter: (_ts_meta_max_3 > ('2000-01-08'::cstring)::timestamp with time zone)
         ->  Sort (actual rows=1008.00 loops=1)
               Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
                     Vectorized Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone)
                     ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                           Filter: (_ts_meta_max_3 > ('2000-01-08'::cstring)::timestamp with time zone)
         ->  Sort (actual rows=336.00 loops=1)
               Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on _hyper_2_12_chunk (actual rows=336.00 loops=1)
                     Filter: ("time" > ('2000-01-08'::cstring)::timestamp with time zone)

-- test aggregate
:PREFIX
SELECT count(*)
FROM :TEST_TABLE;
--- QUERY PLAN ---
 Finalize Aggregate (actual rows=1.00 loops=1)
   ->  Append (actual rows=9.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
         ->  Partial Aggregate (actual rows=1.00 loops=1)
               ->  Seq Scan on _hyper_2_7_chunk (actual rows=672.00 loops=1)
         ->  Partial Aggregate (actual rows=1.00 loops=1)
               ->  Seq Scan on _hyper_2_8_chunk (actual rows=2016.00 loops=1)
         ->  Partial Aggregate (actual rows=1.00 loops=1)
               ->  Seq Scan on _hyper_2_9_chunk (actual rows=672.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
         ->  Partial Aggregate (actual rows=1.00 loops=1)
               ->  Seq Scan on _hyper_2_12_chunk (actual rows=336.00 loops=1)

-- test aggregate with GROUP BY
-- Disable hash aggregation to get a deterministic test output
SET enable_hashagg = OFF;
:PREFIX
SELECT count(*)
FROM :TEST_TABLE
GROUP BY device_id
ORDER BY device_id;
--- QUERY PLAN ---
 Finalize GroupAggregate (actual rows=5.00 loops=1)
   Group Key: metrics_space.device_id
   ->  Merge Append (actual rows=15.00 loops=1)
         Sort Key: metrics_space.device_id
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_6_17_chunk.device_id
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=3.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
                     ->  Sort (actual rows=3.00 loops=1)
                           Sort Key: compress_hyper_6_18_chunk.device_id
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_6_19_chunk.device_id
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
         ->  Partial GroupAggregate (actual rows=1.00 loops=1)
               Group Key: _hyper_2_7_chunk.device_id
               ->  Index Only Scan Backward using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_7_chunk (actual rows=672.00 loops=1)
         ->  Partial GroupAggregate (actual rows=3.00 loops=1)
               Group Key: _hyper_2_8_chunk.device_id
               ->  Index Only Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_8_chunk (actual rows=2016.00 loops=1)
         ->  Partial GroupAggregate (actual rows=1.00 loops=1)
               Group Key: _hyper_2_9_chunk.device_id
               ->  Index Only Scan Backward using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_9_chunk (actual rows=672.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_6_20_chunk.device_id
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=3.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
                     ->  Sort (actual rows=3.00 loops=1)
                           Sort Key: compress_hyper_6_21_chunk.device_id
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
         ->  Partial GroupAggregate (actual rows=1.00 loops=1)
               Group Key: _hyper_2_12_chunk.device_id
               ->  Index Only Scan Backward using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v_2 on _hyper_2_12_chunk (actual rows=336.00 loops=1)

-- test window functions with GROUP BY
:PREFIX
SELECT sum(count(*)) OVER ()
FROM :TEST_TABLE
GROUP BY device_id
ORDER BY device_id;
--- QUERY PLAN ---
 WindowAgg (actual rows=5.00 loops=1)
   ->  Finalize GroupAggregate (actual rows=5.00 loops=1)
         Group Key: metrics_space.device_id
         ->  Merge Append (actual rows=15.00 loops=1)
               Sort Key: metrics_space.device_id
               ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                           ->  Sort (actual rows=1.00 loops=1)
                                 Sort Key: compress_hyper_6_17_chunk.device_id
                                 Sort Method: quicksort 
                                 ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (VectorAgg) (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
                           ->  Sort (actual rows=3.00 loops=1)
                                 Sort Key: compress_hyper_6_18_chunk.device_id
                                 Sort Method: quicksort 
                                 ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
                           ->  Sort (actual rows=1.00 loops=1)
                                 Sort Key: compress_hyper_6_19_chunk.device_id
                                 Sort Method: quicksort 
                                 ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
               ->  Partial GroupAggregate (actual rows=1.00 loops=1)
                     Group Key: _hyper_2_7_chunk.device_id
                     ->  Index Only Scan Backward using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_7_chunk (actual rows=672.00 loops=1)
               ->  Partial GroupAggregate (actual rows=3.00 loops=1)
                     Group Key: _hyper_2_8_chunk.device_id
                     ->  Index Only Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_8_chunk (actual rows=2016.00 loops=1)
               ->  Partial GroupAggregate (actual rows=1.00 loops=1)
                     Group Key: _hyper_2_9_chunk.device_id
                     ->  Index Only Scan Backward using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_9_chunk (actual rows=672.00 loops=1)
               ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                           ->  Sort (actual rows=1.00 loops=1)
                                 Sort Key: compress_hyper_6_20_chunk.device_id
                                 Sort Method: quicksort 
                                 ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (VectorAgg) (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
                           ->  Sort (actual rows=3.00 loops=1)
                                 Sort Key: compress_hyper_6_21_chunk.device_id
                                 Sort Method: quicksort 
                                 ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
               ->  Partial GroupAggregate (actual rows=1.00 loops=1)
                     Group Key: _hyper_2_12_chunk.device_id
                     ->  Index Only Scan Backward using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v_2 on _hyper_2_12_chunk (actual rows=336.00 loops=1)

SET enable_hashagg = ON;
-- test CTE
:PREFIX WITH q AS (
    SELECT v1
    FROM :TEST_TABLE
    ORDER BY time
)
SELECT *
FROM q
ORDER BY v1;
--- QUERY PLAN ---
 Sort (actual rows=8640.00 loops=1)
   Sort Key: q.v1
   Sort Method: quicksort 
   ->  Subquery Scan on q (actual rows=8640.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=8640.00 loops=1)
               Order: metrics_space."time"
               ->  Merge Append (actual rows=3600.00 loops=1)
                     Sort Key: metrics_space."time"
                     ->  Sort (actual rows=720.00 loops=1)
                           Sort Key: _hyper_2_4_chunk."time"
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     ->  Sort (actual rows=2160.00 loops=1)
                           Sort Key: _hyper_2_5_chunk."time"
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                     ->  Sort (actual rows=720.00 loops=1)
                           Sort Key: _hyper_2_6_chunk."time"
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
               ->  Merge Append (actual rows=3360.00 loops=1)
                     Sort Key: metrics_space."time"
                     ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (actual rows=672.00 loops=1)
                     ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk (actual rows=2016.00 loops=1)
                     ->  Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk (actual rows=672.00 loops=1)
               ->  Merge Append (actual rows=1680.00 loops=1)
                     Sort Key: metrics_space."time"
                     ->  Sort (actual rows=336.00 loops=1)
                           Sort Key: _hyper_2_10_chunk."time"
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     ->  Sort (actual rows=1008.00 loops=1)
                           Sort Key: _hyper_2_11_chunk."time"
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk (actual rows=336.00 loops=1)

-- test CTE join
:PREFIX WITH q1 AS (
    SELECT time,
        v1
    FROM :TEST_TABLE
    WHERE device_id = 1
    ORDER BY time
),
q2 AS (
    SELECT time,
        v2
    FROM :TEST_TABLE
    WHERE device_id = 2
    ORDER BY time
)
SELECT *
FROM q1
    INNER JOIN q2 ON q1.time = q2.time
ORDER BY q1.time;
--- QUERY PLAN ---
 Merge Join (actual rows=1728.00 loops=1)
   Merge Cond: (metrics_space."time" = metrics_space_1."time")
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=1728.00 loops=1)
         Order: metrics_space."time"
         ->  Sort (actual rows=720.00 loops=1)
               Sort Key: _hyper_2_5_chunk."time"
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 2)
                           Rows Removed by Filter: 2
         ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk (actual rows=672.00 loops=1)
               Index Cond: (device_id = 2)
         ->  Sort (actual rows=336.00 loops=1)
               Sort Key: _hyper_2_11_chunk."time"
               Sort Method: quicksort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=336.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 2)
                           Rows Removed by Filter: 2
   ->  Materialize (actual rows=1728.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space metrics_space_1 (actual rows=1728.00 loops=1)
               Order: metrics_space_1."time"
               ->  Sort (actual rows=720.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = 1)
               ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (actual rows=672.00 loops=1)
                     Filter: (device_id = 1)
               ->  Sort (actual rows=336.00 loops=1)
                     Sort Key: _hyper_2_10_chunk."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = 1)

:PREFIX WITH q1 AS (
    SELECT time,
        v1
    FROM :TEST_TABLE
    WHERE device_id = 1
    ORDER BY time
	LIMIT 5
),
q2 AS (
    SELECT time,
        v2
    FROM :TEST_TABLE
    WHERE device_id = 2
    ORDER BY time
	LIMIT 5
)
SELECT *
FROM q1, q2;
--- QUERY PLAN ---
 Nested Loop (actual rows=25.00 loops=1)
   ->  Limit (actual rows=5.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=5.00 loops=1)
               Order: metrics_space."time"
               ->  Sort (actual rows=5.00 loops=1)
                     Sort Key: _hyper_2_4_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = 1)
               ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed)
                     Filter: (device_id = 1)
               ->  Sort (never executed)
                     Sort Key: _hyper_2_10_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (never executed)
                           ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 Filter: (device_id = 1)
   ->  Materialize (actual rows=5.00 loops=5)
         ->  Limit (actual rows=5.00 loops=1)
               ->  Custom Scan (ChunkAppend) on metrics_space metrics_space_1 (actual rows=5.00 loops=1)
                     Order: metrics_space_1."time"
                     ->  Sort (actual rows=5.00 loops=1)
                           Sort Key: _hyper_2_5_chunk."time"
                           Sort Method: top-N heapsort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=1.00 loops=1)
                                       Filter: (device_id = 2)
                                       Rows Removed by Filter: 2
                     ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk (never executed)
                           Index Cond: (device_id = 2)
                     ->  Sort (never executed)
                           Sort Key: _hyper_2_11_chunk."time"
                           ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (never executed)
                                 ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                       Filter: (device_id = 2)

-- test prepared statement
PREPARE prep AS
SELECT count(time)
FROM :TEST_TABLE
WHERE device_id = 1;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Finalize Aggregate (actual rows=1.00 loops=1)
   ->  Append (actual rows=3.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)
         ->  Partial Aggregate (actual rows=1.00 loops=1)
               ->  Seq Scan on _hyper_2_7_chunk (actual rows=672.00 loops=1)
                     Filter: (device_id = 1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)

EXECUTE prep;
 count 
-------
  1728

EXECUTE prep;
 count 
-------
  1728

EXECUTE prep;
 count 
-------
  1728

EXECUTE prep;
 count 
-------
  1728

EXECUTE prep;
 count 
-------
  1728

EXECUTE prep;
 count 
-------
  1728

DEALLOCATE prep;
--
-- test indexes
--
SET enable_seqscan TO FALSE;
-- IndexScans should work
:PREFIX_VERBOSE
SELECT time,
    device_id
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY device_id,
    time;
--- QUERY PLAN ---
 Merge Append (actual rows=1728.00 loops=1)
   Sort Key: metrics_space."time"
   ->  Sort (actual rows=720.00 loops=1)
         Output: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
         Sort Key: _hyper_2_4_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=720.00 loops=1)
               Output: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_6_17_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
                     Index Cond: (compress_hyper_6_17_chunk.device_id = 1)
   ->  Index Only Scan Backward using _hyper_2_7_chunk_metrics_space_device_id_time_idx on _timescaledb_internal._hyper_2_7_chunk (actual rows=672.00 loops=1)
         Output: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id
         Index Cond: (_hyper_2_7_chunk.device_id = 1)
   ->  Sort (actual rows=336.00 loops=1)
         Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
         Sort Key: _hyper_2_10_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Index Cond: (compress_hyper_6_20_chunk.device_id = 1)

-- globs should not plan IndexOnlyScans
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY device_id,
    time;
--- QUERY PLAN ---
 Merge Append (actual rows=1728.00 loops=1)
   Sort Key: metrics_space."time"
   ->  Sort (actual rows=720.00 loops=1)
         Output: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id, _hyper_2_4_chunk.device_id_peer, _hyper_2_4_chunk.v0, _hyper_2_4_chunk.v1, _hyper_2_4_chunk.v2, _hyper_2_4_chunk.v3
         Sort Key: _hyper_2_4_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=720.00 loops=1)
               Output: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id, _hyper_2_4_chunk.device_id_peer, _hyper_2_4_chunk.v0, _hyper_2_4_chunk.v1, _hyper_2_4_chunk.v2, _hyper_2_4_chunk.v3
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_6_17_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
                     Index Cond: (compress_hyper_6_17_chunk.device_id = 1)
   ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _timescaledb_internal._hyper_2_7_chunk (actual rows=672.00 loops=1)
         Output: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1, _hyper_2_7_chunk.v2, _hyper_2_7_chunk.v3
         Filter: (_hyper_2_7_chunk.device_id = 1)
   ->  Sort (actual rows=336.00 loops=1)
         Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
         Sort Key: _hyper_2_10_chunk."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Index Cond: (compress_hyper_6_20_chunk.device_id = 1)

-- whole row reference should work
:PREFIX_VERBOSE
SELECT test_table
FROM :TEST_TABLE AS test_table
WHERE device_id = 1
ORDER BY device_id,
    time;
--- QUERY PLAN ---
 Merge Append (actual rows=1728.00 loops=1)
   Sort Key: test_table."time"
   ->  Sort (actual rows=720.00 loops=1)
         Output: ((test_table_1.*)::metrics_space), test_table_1.device_id, test_table_1."time"
         Sort Key: test_table_1."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk test_table_1 (actual rows=720.00 loops=1)
               Output: test_table_1.*, test_table_1.device_id, test_table_1."time"
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_6_17_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
                     Index Cond: (compress_hyper_6_17_chunk.device_id = 1)
   ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _timescaledb_internal._hyper_2_7_chunk test_table_2 (actual rows=672.00 loops=1)
         Output: test_table_2.*, test_table_2.device_id, test_table_2."time"
         Filter: (test_table_2.device_id = 1)
   ->  Sort (actual rows=336.00 loops=1)
         Output: ((test_table_3.*)::metrics_space), test_table_3.device_id, test_table_3."time"
         Sort Key: test_table_3."time"
         Sort Method: quicksort 
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk test_table_3 (actual rows=336.00 loops=1)
               Output: test_table_3.*, test_table_3.device_id, test_table_3."time"
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Index Cond: (compress_hyper_6_20_chunk.device_id = 1)

-- even when we select only a segmentby column, we still need count
:PREFIX_VERBOSE
SELECT device_id
FROM :TEST_TABLE
WHERE device_id = 1
ORDER BY device_id;
--- QUERY PLAN ---
 Append (actual rows=1728.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=720.00 loops=1)
         Output: _hyper_2_4_chunk.device_id
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_17_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
               Index Cond: (compress_hyper_6_17_chunk.device_id = 1)
   ->  Index Only Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_7_chunk (actual rows=672.00 loops=1)
         Output: _hyper_2_7_chunk.device_id
         Index Cond: (_hyper_2_7_chunk.device_id = 1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
         Output: _hyper_2_10_chunk.device_id
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
               Index Cond: (compress_hyper_6_20_chunk.device_id = 1)

:PREFIX_VERBOSE
SELECT count(*)
FROM :TEST_TABLE
WHERE device_id = 1;
--- QUERY PLAN ---
 Finalize Aggregate (actual rows=1.00 loops=1)
   Output: count(*)
   ->  Append (actual rows=3.00 loops=1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               Output: (PARTIAL count(*))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=720.00 loops=1)
                     Bulk Decompression: false
                     ->  Index Scan using compress_hyper_6_17_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                           Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
                           Index Cond: (compress_hyper_6_17_chunk.device_id = 1)
         ->  Partial Aggregate (actual rows=1.00 loops=1)
               Output: PARTIAL count(*)
               ->  Index Only Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_7_chunk (actual rows=672.00 loops=1)
                     Index Cond: (_hyper_2_7_chunk.device_id = 1)
         ->  Custom Scan (VectorAgg) (actual rows=1.00 loops=1)
               Output: (PARTIAL count(*))
               Grouping Policy: all compressed batches
               ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
                     Bulk Decompression: false
                     ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                           Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                           Index Cond: (compress_hyper_6_20_chunk.device_id = 1)

-- should be able to order using an index
CREATE INDEX tmp_idx ON :TEST_TABLE (device_id);
:PREFIX_VERBOSE
SELECT device_id
FROM :TEST_TABLE
ORDER BY device_id;
--- QUERY PLAN ---
 Merge Append (actual rows=8640.00 loops=1)
   Sort Key: metrics_space.device_id
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=720.00 loops=1)
         Output: _hyper_2_4_chunk.device_id
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_17_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_5_chunk (actual rows=2160.00 loops=1)
         Output: _hyper_2_5_chunk.device_id
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_18_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
               Output: compress_hyper_6_18_chunk._ts_meta_count, compress_hyper_6_18_chunk.device_id, compress_hyper_6_18_chunk.device_id_peer, compress_hyper_6_18_chunk._ts_meta_min_3, compress_hyper_6_18_chunk._ts_meta_max_3, compress_hyper_6_18_chunk."time", compress_hyper_6_18_chunk._ts_meta_min_1, compress_hyper_6_18_chunk._ts_meta_max_1, compress_hyper_6_18_chunk.v0, compress_hyper_6_18_chunk._ts_meta_min_2, compress_hyper_6_18_chunk._ts_meta_max_2, compress_hyper_6_18_chunk.v1, compress_hyper_6_18_chunk.v2, compress_hyper_6_18_chunk.v3
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_6_chunk (actual rows=720.00 loops=1)
         Output: _hyper_2_6_chunk.device_id
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_19_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_6_19_chunk._ts_meta_count, compress_hyper_6_19_chunk.device_id, compress_hyper_6_19_chunk.device_id_peer, compress_hyper_6_19_chunk._ts_meta_min_3, compress_hyper_6_19_chunk._ts_meta_max_3, compress_hyper_6_19_chunk."time", compress_hyper_6_19_chunk._ts_meta_min_1, compress_hyper_6_19_chunk._ts_meta_max_1, compress_hyper_6_19_chunk.v0, compress_hyper_6_19_chunk._ts_meta_min_2, compress_hyper_6_19_chunk._ts_meta_max_2, compress_hyper_6_19_chunk.v1, compress_hyper_6_19_chunk.v2, compress_hyper_6_19_chunk.v3
   ->  Index Only Scan using _hyper_2_7_chunk_tmp_idx on _timescaledb_internal._hyper_2_7_chunk (actual rows=672.00 loops=1)
         Output: _hyper_2_7_chunk.device_id
   ->  Index Only Scan using _hyper_2_8_chunk_tmp_idx on _timescaledb_internal._hyper_2_8_chunk (actual rows=2016.00 loops=1)
         Output: _hyper_2_8_chunk.device_id
   ->  Index Only Scan using _hyper_2_9_chunk_tmp_idx on _timescaledb_internal._hyper_2_9_chunk (actual rows=672.00 loops=1)
         Output: _hyper_2_9_chunk.device_id
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
         Output: _hyper_2_10_chunk.device_id
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1008.00 loops=1)
         Output: _hyper_2_11_chunk.device_id
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_21_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
               Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
   ->  Index Only Scan using _hyper_2_12_chunk_tmp_idx on _timescaledb_internal._hyper_2_12_chunk (actual rows=336.00 loops=1)
         Output: _hyper_2_12_chunk.device_id

DROP INDEX tmp_idx CASCADE;
-- These plans are flaky between MergeAppend and Sort over Append.
SET enable_sort TO OFF;
--use the peer index
:PREFIX_VERBOSE
SELECT *
FROM :TEST_TABLE
WHERE device_id_peer = 1
ORDER BY device_id_peer,
    time;
--- QUERY PLAN ---
 Sort (actual rows=0.00 loops=1)
   Output: metrics_space."time", metrics_space.device_id, metrics_space.device_id_peer, metrics_space.v0, metrics_space.v1, metrics_space.v2, metrics_space.v3
   Sort Key: metrics_space."time"
   Sort Method: quicksort 
   ->  Append (actual rows=0.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_4_chunk."time", _hyper_2_4_chunk.device_id, _hyper_2_4_chunk.device_id_peer, _hyper_2_4_chunk.v0, _hyper_2_4_chunk.v1, _hyper_2_4_chunk.v2, _hyper_2_4_chunk.v3
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_6_17_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=0.00 loops=1)
                     Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
                     Index Cond: (compress_hyper_6_17_chunk.device_id_peer = 1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_5_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id, _hyper_2_5_chunk.device_id_peer, _hyper_2_5_chunk.v0, _hyper_2_5_chunk.v1, _hyper_2_5_chunk.v2, _hyper_2_5_chunk.v3
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_6_18_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_18_chunk (actual rows=0.00 loops=1)
                     Output: compress_hyper_6_18_chunk._ts_meta_count, compress_hyper_6_18_chunk.device_id, compress_hyper_6_18_chunk.device_id_peer, compress_hyper_6_18_chunk._ts_meta_min_3, compress_hyper_6_18_chunk._ts_meta_max_3, compress_hyper_6_18_chunk."time", compress_hyper_6_18_chunk._ts_meta_min_1, compress_hyper_6_18_chunk._ts_meta_max_1, compress_hyper_6_18_chunk.v0, compress_hyper_6_18_chunk._ts_meta_min_2, compress_hyper_6_18_chunk._ts_meta_max_2, compress_hyper_6_18_chunk.v1, compress_hyper_6_18_chunk.v2, compress_hyper_6_18_chunk.v3
                     Index Cond: (compress_hyper_6_18_chunk.device_id_peer = 1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_6_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id, _hyper_2_6_chunk.device_id_peer, _hyper_2_6_chunk.v0, _hyper_2_6_chunk.v1, _hyper_2_6_chunk.v2, _hyper_2_6_chunk.v3
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_6_19_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_19_chunk (actual rows=0.00 loops=1)
                     Output: compress_hyper_6_19_chunk._ts_meta_count, compress_hyper_6_19_chunk.device_id, compress_hyper_6_19_chunk.device_id_peer, compress_hyper_6_19_chunk._ts_meta_min_3, compress_hyper_6_19_chunk._ts_meta_max_3, compress_hyper_6_19_chunk."time", compress_hyper_6_19_chunk._ts_meta_min_1, compress_hyper_6_19_chunk._ts_meta_max_1, compress_hyper_6_19_chunk.v0, compress_hyper_6_19_chunk._ts_meta_min_2, compress_hyper_6_19_chunk._ts_meta_max_2, compress_hyper_6_19_chunk.v1, compress_hyper_6_19_chunk.v2, compress_hyper_6_19_chunk.v3
                     Index Cond: (compress_hyper_6_19_chunk.device_id_peer = 1)
         ->  Index Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_7_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id, _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.v0, _hyper_2_7_chunk.v1, _hyper_2_7_chunk.v2, _hyper_2_7_chunk.v3
               Index Cond: (_hyper_2_7_chunk.device_id_peer = 1)
         ->  Index Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_8_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_8_chunk."time", _hyper_2_8_chunk.device_id, _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.v0, _hyper_2_8_chunk.v1, _hyper_2_8_chunk.v2, _hyper_2_8_chunk.v3
               Index Cond: (_hyper_2_8_chunk.device_id_peer = 1)
         ->  Index Scan using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_9_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_9_chunk."time", _hyper_2_9_chunk.device_id, _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.v0, _hyper_2_9_chunk.v1, _hyper_2_9_chunk.v2, _hyper_2_9_chunk.v3
               Index Cond: (_hyper_2_9_chunk.device_id_peer = 1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_10_chunk."time", _hyper_2_10_chunk.device_id, _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.v0, _hyper_2_10_chunk.v1, _hyper_2_10_chunk.v2, _hyper_2_10_chunk.v3
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=0.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
                     Index Cond: (compress_hyper_6_20_chunk.device_id_peer = 1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id, _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.v0, _hyper_2_11_chunk.v1, _hyper_2_11_chunk.v2, _hyper_2_11_chunk.v3
               Bulk Decompression: true
               ->  Index Scan using compress_hyper_6_21_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=0.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
                     Index Cond: (compress_hyper_6_21_chunk.device_id_peer = 1)
         ->  Index Scan using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v_2 on _timescaledb_internal._hyper_2_12_chunk (actual rows=0.00 loops=1)
               Output: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id, _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.v0, _hyper_2_12_chunk.v1, _hyper_2_12_chunk.v2, _hyper_2_12_chunk.v3
               Index Cond: (_hyper_2_12_chunk.device_id_peer = 1)

RESET enable_sort;
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id_peer = 1
ORDER BY device_id_peer;
--- QUERY PLAN ---
 Append (actual rows=0.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_4_chunk.device_id_peer
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_17_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
               Index Cond: (compress_hyper_6_17_chunk.device_id_peer = 1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_5_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_5_chunk.device_id_peer
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_18_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_18_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_6_18_chunk._ts_meta_count, compress_hyper_6_18_chunk.device_id, compress_hyper_6_18_chunk.device_id_peer, compress_hyper_6_18_chunk._ts_meta_min_3, compress_hyper_6_18_chunk._ts_meta_max_3, compress_hyper_6_18_chunk."time", compress_hyper_6_18_chunk._ts_meta_min_1, compress_hyper_6_18_chunk._ts_meta_max_1, compress_hyper_6_18_chunk.v0, compress_hyper_6_18_chunk._ts_meta_min_2, compress_hyper_6_18_chunk._ts_meta_max_2, compress_hyper_6_18_chunk.v1, compress_hyper_6_18_chunk.v2, compress_hyper_6_18_chunk.v3
               Index Cond: (compress_hyper_6_18_chunk.device_id_peer = 1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_6_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_6_chunk.device_id_peer
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_19_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_19_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_6_19_chunk._ts_meta_count, compress_hyper_6_19_chunk.device_id, compress_hyper_6_19_chunk.device_id_peer, compress_hyper_6_19_chunk._ts_meta_min_3, compress_hyper_6_19_chunk._ts_meta_max_3, compress_hyper_6_19_chunk."time", compress_hyper_6_19_chunk._ts_meta_min_1, compress_hyper_6_19_chunk._ts_meta_max_1, compress_hyper_6_19_chunk.v0, compress_hyper_6_19_chunk._ts_meta_min_2, compress_hyper_6_19_chunk._ts_meta_max_2, compress_hyper_6_19_chunk.v1, compress_hyper_6_19_chunk.v2, compress_hyper_6_19_chunk.v3
               Index Cond: (compress_hyper_6_19_chunk.device_id_peer = 1)
   ->  Index Only Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_7_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_7_chunk.device_id_peer
         Index Cond: (_hyper_2_7_chunk.device_id_peer = 1)
   ->  Index Only Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_8_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_8_chunk.device_id_peer
         Index Cond: (_hyper_2_8_chunk.device_id_peer = 1)
   ->  Index Only Scan using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_9_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_9_chunk.device_id_peer
         Index Cond: (_hyper_2_9_chunk.device_id_peer = 1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_10_chunk.device_id_peer
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
               Index Cond: (compress_hyper_6_20_chunk.device_id_peer = 1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_11_chunk.device_id_peer
         Bulk Decompression: false
         ->  Index Scan using compress_hyper_6_21_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
               Index Cond: (compress_hyper_6_21_chunk.device_id_peer = 1)
   ->  Index Only Scan using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v_2 on _timescaledb_internal._hyper_2_12_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_12_chunk.device_id_peer
         Index Cond: (_hyper_2_12_chunk.device_id_peer = 1)

--ensure that we can get a nested loop
SET enable_seqscan TO TRUE;
SET enable_hashjoin TO FALSE;
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id_peer IN (
        VALUES (1));
--- QUERY PLAN ---
 Append (actual rows=0.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_4_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
               Filter: (compress_hyper_6_17_chunk.device_id_peer = 1)
               Rows Removed by Filter: 1
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_5_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_5_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_6_18_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_6_18_chunk._ts_meta_count, compress_hyper_6_18_chunk.device_id, compress_hyper_6_18_chunk.device_id_peer, compress_hyper_6_18_chunk._ts_meta_min_3, compress_hyper_6_18_chunk._ts_meta_max_3, compress_hyper_6_18_chunk."time", compress_hyper_6_18_chunk._ts_meta_min_1, compress_hyper_6_18_chunk._ts_meta_max_1, compress_hyper_6_18_chunk.v0, compress_hyper_6_18_chunk._ts_meta_min_2, compress_hyper_6_18_chunk._ts_meta_max_2, compress_hyper_6_18_chunk.v1, compress_hyper_6_18_chunk.v2, compress_hyper_6_18_chunk.v3
               Filter: (compress_hyper_6_18_chunk.device_id_peer = 1)
               Rows Removed by Filter: 3
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_6_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_6_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_6_19_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_6_19_chunk._ts_meta_count, compress_hyper_6_19_chunk.device_id, compress_hyper_6_19_chunk.device_id_peer, compress_hyper_6_19_chunk._ts_meta_min_3, compress_hyper_6_19_chunk._ts_meta_max_3, compress_hyper_6_19_chunk."time", compress_hyper_6_19_chunk._ts_meta_min_1, compress_hyper_6_19_chunk._ts_meta_max_1, compress_hyper_6_19_chunk.v0, compress_hyper_6_19_chunk._ts_meta_min_2, compress_hyper_6_19_chunk._ts_meta_max_2, compress_hyper_6_19_chunk.v1, compress_hyper_6_19_chunk.v2, compress_hyper_6_19_chunk.v3
               Filter: (compress_hyper_6_19_chunk.device_id_peer = 1)
               Rows Removed by Filter: 1
   ->  Index Only Scan using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_7_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_7_chunk.device_id_peer
         Index Cond: (_hyper_2_7_chunk.device_id_peer = 1)
   ->  Index Only Scan using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_8_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_8_chunk.device_id_peer
         Index Cond: (_hyper_2_8_chunk.device_id_peer = 1)
   ->  Index Only Scan using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_9_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_9_chunk.device_id_peer
         Index Cond: (_hyper_2_9_chunk.device_id_peer = 1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_10_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
               Filter: (compress_hyper_6_20_chunk.device_id_peer = 1)
               Rows Removed by Filter: 1
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_11_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=0.00 loops=1)
               Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
               Filter: (compress_hyper_6_21_chunk.device_id_peer = 1)
               Rows Removed by Filter: 3
   ->  Seq Scan on _timescaledb_internal._hyper_2_12_chunk (actual rows=0.00 loops=1)
         Output: _hyper_2_12_chunk.device_id_peer
         Filter: (_hyper_2_12_chunk.device_id_peer = 1)
         Rows Removed by Filter: 336

--with multiple values can get a nested loop.
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id_peer IN (
        VALUES (1),
            (2));
--- QUERY PLAN ---
 Nested Loop Semi Join (actual rows=0.00 loops=1)
   Output: metrics_space.device_id_peer
   Join Filter: (metrics_space.device_id_peer = "*VALUES*".column1)
   Rows Removed by Join Filter: 17280
   ->  Append (actual rows=8640.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=720.00 loops=1)
               Output: _hyper_2_4_chunk.device_id_peer
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_5_chunk (actual rows=2160.00 loops=1)
               Output: _hyper_2_5_chunk.device_id_peer
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_18_chunk._ts_meta_count, compress_hyper_6_18_chunk.device_id, compress_hyper_6_18_chunk.device_id_peer, compress_hyper_6_18_chunk._ts_meta_min_3, compress_hyper_6_18_chunk._ts_meta_max_3, compress_hyper_6_18_chunk."time", compress_hyper_6_18_chunk._ts_meta_min_1, compress_hyper_6_18_chunk._ts_meta_max_1, compress_hyper_6_18_chunk.v0, compress_hyper_6_18_chunk._ts_meta_min_2, compress_hyper_6_18_chunk._ts_meta_max_2, compress_hyper_6_18_chunk.v1, compress_hyper_6_18_chunk.v2, compress_hyper_6_18_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_6_chunk (actual rows=720.00 loops=1)
               Output: _hyper_2_6_chunk.device_id_peer
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_19_chunk._ts_meta_count, compress_hyper_6_19_chunk.device_id, compress_hyper_6_19_chunk.device_id_peer, compress_hyper_6_19_chunk._ts_meta_min_3, compress_hyper_6_19_chunk._ts_meta_max_3, compress_hyper_6_19_chunk."time", compress_hyper_6_19_chunk._ts_meta_min_1, compress_hyper_6_19_chunk._ts_meta_max_1, compress_hyper_6_19_chunk.v0, compress_hyper_6_19_chunk._ts_meta_min_2, compress_hyper_6_19_chunk._ts_meta_max_2, compress_hyper_6_19_chunk.v1, compress_hyper_6_19_chunk.v2, compress_hyper_6_19_chunk.v3
         ->  Seq Scan on _timescaledb_internal._hyper_2_7_chunk (actual rows=672.00 loops=1)
               Output: _hyper_2_7_chunk.device_id_peer
         ->  Seq Scan on _timescaledb_internal._hyper_2_8_chunk (actual rows=2016.00 loops=1)
               Output: _hyper_2_8_chunk.device_id_peer
         ->  Seq Scan on _timescaledb_internal._hyper_2_9_chunk (actual rows=672.00 loops=1)
               Output: _hyper_2_9_chunk.device_id_peer
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_10_chunk.device_id_peer
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1008.00 loops=1)
               Output: _hyper_2_11_chunk.device_id_peer
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
         ->  Seq Scan on _timescaledb_internal._hyper_2_12_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_12_chunk.device_id_peer
   ->  Materialize (actual rows=2.00 loops=8640)
         Output: "*VALUES*".column1
         ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
               Output: "*VALUES*".column1

RESET enable_hashjoin;
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id IN (
        VALUES (1));
--- QUERY PLAN ---
 Append (actual rows=1728.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=720.00 loops=1)
         Output: _hyper_2_4_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
               Filter: (compress_hyper_6_17_chunk.device_id = 1)
   ->  Seq Scan on _timescaledb_internal._hyper_2_7_chunk (actual rows=672.00 loops=1)
         Output: _hyper_2_7_chunk.device_id_peer
         Filter: (_hyper_2_7_chunk.device_id = 1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
         Output: _hyper_2_10_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
               Filter: (compress_hyper_6_20_chunk.device_id = 1)

--with multiple values can get a semi-join or nested loop depending on seq_page_cost.
SET enable_hashjoin TO OFF;
SET enable_mergejoin TO OFF;
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id IN (
        VALUES (1),
            (2));
--- QUERY PLAN ---
 Nested Loop Semi Join (actual rows=3456.00 loops=1)
   Output: metrics_space.device_id_peer
   Join Filter: (metrics_space.device_id = "*VALUES*".column1)
   Rows Removed by Join Filter: 12096
   ->  Append (actual rows=8640.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=720.00 loops=1)
               Output: _hyper_2_4_chunk.device_id_peer, _hyper_2_4_chunk.device_id
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_5_chunk (actual rows=2160.00 loops=1)
               Output: _hyper_2_5_chunk.device_id_peer, _hyper_2_5_chunk.device_id
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_18_chunk._ts_meta_count, compress_hyper_6_18_chunk.device_id, compress_hyper_6_18_chunk.device_id_peer, compress_hyper_6_18_chunk._ts_meta_min_3, compress_hyper_6_18_chunk._ts_meta_max_3, compress_hyper_6_18_chunk."time", compress_hyper_6_18_chunk._ts_meta_min_1, compress_hyper_6_18_chunk._ts_meta_max_1, compress_hyper_6_18_chunk.v0, compress_hyper_6_18_chunk._ts_meta_min_2, compress_hyper_6_18_chunk._ts_meta_max_2, compress_hyper_6_18_chunk.v1, compress_hyper_6_18_chunk.v2, compress_hyper_6_18_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_6_chunk (actual rows=720.00 loops=1)
               Output: _hyper_2_6_chunk.device_id_peer, _hyper_2_6_chunk.device_id
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_19_chunk._ts_meta_count, compress_hyper_6_19_chunk.device_id, compress_hyper_6_19_chunk.device_id_peer, compress_hyper_6_19_chunk._ts_meta_min_3, compress_hyper_6_19_chunk._ts_meta_max_3, compress_hyper_6_19_chunk."time", compress_hyper_6_19_chunk._ts_meta_min_1, compress_hyper_6_19_chunk._ts_meta_max_1, compress_hyper_6_19_chunk.v0, compress_hyper_6_19_chunk._ts_meta_min_2, compress_hyper_6_19_chunk._ts_meta_max_2, compress_hyper_6_19_chunk.v1, compress_hyper_6_19_chunk.v2, compress_hyper_6_19_chunk.v3
         ->  Seq Scan on _timescaledb_internal._hyper_2_7_chunk (actual rows=672.00 loops=1)
               Output: _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.device_id
         ->  Seq Scan on _timescaledb_internal._hyper_2_8_chunk (actual rows=2016.00 loops=1)
               Output: _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.device_id
         ->  Seq Scan on _timescaledb_internal._hyper_2_9_chunk (actual rows=672.00 loops=1)
               Output: _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.device_id
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.device_id
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1008.00 loops=1)
               Output: _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.device_id
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
         ->  Seq Scan on _timescaledb_internal._hyper_2_12_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.device_id
   ->  Materialize (actual rows=2.00 loops=8640)
         Output: "*VALUES*".column1
         ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
               Output: "*VALUES*".column1

RESET enable_hashjoin;
RESET enable_mergejoin;
SET seq_page_cost = 100;
-- loop/row counts of this query is different on windows so we run it without analyze
:PREFIX_NO_ANALYZE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id IN (
        VALUES (1),
            (2));
--- QUERY PLAN ---
 Hash Semi Join
   Output: metrics_space.device_id_peer
   Hash Cond: (metrics_space.device_id = "*VALUES*".column1)
   ->  Append
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk
               Output: _hyper_2_4_chunk.device_id_peer, _hyper_2_4_chunk.device_id
               ->  Index Scan using compress_hyper_6_17_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_17_chunk
                     Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_5_chunk
               Output: _hyper_2_5_chunk.device_id_peer, _hyper_2_5_chunk.device_id
               ->  Index Scan using compress_hyper_6_18_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_18_chunk
                     Output: compress_hyper_6_18_chunk._ts_meta_count, compress_hyper_6_18_chunk.device_id, compress_hyper_6_18_chunk.device_id_peer, compress_hyper_6_18_chunk._ts_meta_min_3, compress_hyper_6_18_chunk._ts_meta_max_3, compress_hyper_6_18_chunk."time", compress_hyper_6_18_chunk._ts_meta_min_1, compress_hyper_6_18_chunk._ts_meta_max_1, compress_hyper_6_18_chunk.v0, compress_hyper_6_18_chunk._ts_meta_min_2, compress_hyper_6_18_chunk._ts_meta_max_2, compress_hyper_6_18_chunk.v1, compress_hyper_6_18_chunk.v2, compress_hyper_6_18_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_6_chunk
               Output: _hyper_2_6_chunk.device_id_peer, _hyper_2_6_chunk.device_id
               ->  Index Scan using compress_hyper_6_19_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_19_chunk
                     Output: compress_hyper_6_19_chunk._ts_meta_count, compress_hyper_6_19_chunk.device_id, compress_hyper_6_19_chunk.device_id_peer, compress_hyper_6_19_chunk._ts_meta_min_3, compress_hyper_6_19_chunk._ts_meta_max_3, compress_hyper_6_19_chunk."time", compress_hyper_6_19_chunk._ts_meta_min_1, compress_hyper_6_19_chunk._ts_meta_max_1, compress_hyper_6_19_chunk.v0, compress_hyper_6_19_chunk._ts_meta_min_2, compress_hyper_6_19_chunk._ts_meta_max_2, compress_hyper_6_19_chunk.v1, compress_hyper_6_19_chunk.v2, compress_hyper_6_19_chunk.v3
         ->  Index Only Scan Backward using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_7_chunk
               Output: _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.device_id
         ->  Index Only Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_8_chunk
               Output: _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.device_id
         ->  Index Only Scan Backward using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _timescaledb_internal._hyper_2_9_chunk
               Output: _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.device_id
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk
               Output: _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.device_id
               ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_20_chunk
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk
               Output: _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.device_id
               ->  Index Scan using compress_hyper_6_21_chunk_device_id_device_id_peer__ts_meta_idx on _timescaledb_internal.compress_hyper_6_21_chunk
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
         ->  Index Only Scan Backward using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v_2 on _timescaledb_internal._hyper_2_12_chunk
               Output: _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.device_id
   ->  Hash
         Output: "*VALUES*".column1
         ->  Values Scan on "*VALUES*"
               Output: "*VALUES*".column1

RESET seq_page_cost;
:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id IN (
        VALUES (1));
--- QUERY PLAN ---
 Append (actual rows=1728.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=720.00 loops=1)
         Output: _hyper_2_4_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
               Filter: (compress_hyper_6_17_chunk.device_id = 1)
   ->  Seq Scan on _timescaledb_internal._hyper_2_7_chunk (actual rows=672.00 loops=1)
         Output: _hyper_2_7_chunk.device_id_peer
         Filter: (_hyper_2_7_chunk.device_id = 1)
   ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
         Output: _hyper_2_10_chunk.device_id_peer
         Bulk Decompression: false
         ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
               Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
               Filter: (compress_hyper_6_20_chunk.device_id = 1)

:PREFIX_VERBOSE
SELECT device_id_peer
FROM :TEST_TABLE
WHERE device_id IN (
        VALUES (1),
            (2));
--- QUERY PLAN ---
 Hash Semi Join (actual rows=3456.00 loops=1)
   Output: metrics_space.device_id_peer
   Hash Cond: (metrics_space.device_id = "*VALUES*".column1)
   ->  Append (actual rows=8640.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_4_chunk (actual rows=720.00 loops=1)
               Output: _hyper_2_4_chunk.device_id_peer, _hyper_2_4_chunk.device_id
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_17_chunk._ts_meta_count, compress_hyper_6_17_chunk.device_id, compress_hyper_6_17_chunk.device_id_peer, compress_hyper_6_17_chunk._ts_meta_min_3, compress_hyper_6_17_chunk._ts_meta_max_3, compress_hyper_6_17_chunk."time", compress_hyper_6_17_chunk._ts_meta_min_1, compress_hyper_6_17_chunk._ts_meta_max_1, compress_hyper_6_17_chunk.v0, compress_hyper_6_17_chunk._ts_meta_min_2, compress_hyper_6_17_chunk._ts_meta_max_2, compress_hyper_6_17_chunk.v1, compress_hyper_6_17_chunk.v2, compress_hyper_6_17_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_5_chunk (actual rows=2160.00 loops=1)
               Output: _hyper_2_5_chunk.device_id_peer, _hyper_2_5_chunk.device_id
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_18_chunk._ts_meta_count, compress_hyper_6_18_chunk.device_id, compress_hyper_6_18_chunk.device_id_peer, compress_hyper_6_18_chunk._ts_meta_min_3, compress_hyper_6_18_chunk._ts_meta_max_3, compress_hyper_6_18_chunk."time", compress_hyper_6_18_chunk._ts_meta_min_1, compress_hyper_6_18_chunk._ts_meta_max_1, compress_hyper_6_18_chunk.v0, compress_hyper_6_18_chunk._ts_meta_min_2, compress_hyper_6_18_chunk._ts_meta_max_2, compress_hyper_6_18_chunk.v1, compress_hyper_6_18_chunk.v2, compress_hyper_6_18_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_6_chunk (actual rows=720.00 loops=1)
               Output: _hyper_2_6_chunk.device_id_peer, _hyper_2_6_chunk.device_id
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_19_chunk._ts_meta_count, compress_hyper_6_19_chunk.device_id, compress_hyper_6_19_chunk.device_id_peer, compress_hyper_6_19_chunk._ts_meta_min_3, compress_hyper_6_19_chunk._ts_meta_max_3, compress_hyper_6_19_chunk."time", compress_hyper_6_19_chunk._ts_meta_min_1, compress_hyper_6_19_chunk._ts_meta_max_1, compress_hyper_6_19_chunk.v0, compress_hyper_6_19_chunk._ts_meta_min_2, compress_hyper_6_19_chunk._ts_meta_max_2, compress_hyper_6_19_chunk.v1, compress_hyper_6_19_chunk.v2, compress_hyper_6_19_chunk.v3
         ->  Seq Scan on _timescaledb_internal._hyper_2_7_chunk (actual rows=672.00 loops=1)
               Output: _hyper_2_7_chunk.device_id_peer, _hyper_2_7_chunk.device_id
         ->  Seq Scan on _timescaledb_internal._hyper_2_8_chunk (actual rows=2016.00 loops=1)
               Output: _hyper_2_8_chunk.device_id_peer, _hyper_2_8_chunk.device_id
         ->  Seq Scan on _timescaledb_internal._hyper_2_9_chunk (actual rows=672.00 loops=1)
               Output: _hyper_2_9_chunk.device_id_peer, _hyper_2_9_chunk.device_id
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_10_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_10_chunk.device_id_peer, _hyper_2_10_chunk.device_id
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     Output: compress_hyper_6_20_chunk._ts_meta_count, compress_hyper_6_20_chunk.device_id, compress_hyper_6_20_chunk.device_id_peer, compress_hyper_6_20_chunk._ts_meta_min_3, compress_hyper_6_20_chunk._ts_meta_max_3, compress_hyper_6_20_chunk."time", compress_hyper_6_20_chunk._ts_meta_min_1, compress_hyper_6_20_chunk._ts_meta_max_1, compress_hyper_6_20_chunk.v0, compress_hyper_6_20_chunk._ts_meta_min_2, compress_hyper_6_20_chunk._ts_meta_max_2, compress_hyper_6_20_chunk.v1, compress_hyper_6_20_chunk.v2, compress_hyper_6_20_chunk.v3
         ->  Custom Scan (ColumnarScan) on _timescaledb_internal._hyper_2_11_chunk (actual rows=1008.00 loops=1)
               Output: _hyper_2_11_chunk.device_id_peer, _hyper_2_11_chunk.device_id
               Bulk Decompression: false
               ->  Seq Scan on _timescaledb_internal.compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     Output: compress_hyper_6_21_chunk._ts_meta_count, compress_hyper_6_21_chunk.device_id, compress_hyper_6_21_chunk.device_id_peer, compress_hyper_6_21_chunk._ts_meta_min_3, compress_hyper_6_21_chunk._ts_meta_max_3, compress_hyper_6_21_chunk."time", compress_hyper_6_21_chunk._ts_meta_min_1, compress_hyper_6_21_chunk._ts_meta_max_1, compress_hyper_6_21_chunk.v0, compress_hyper_6_21_chunk._ts_meta_min_2, compress_hyper_6_21_chunk._ts_meta_max_2, compress_hyper_6_21_chunk.v1, compress_hyper_6_21_chunk.v2, compress_hyper_6_21_chunk.v3
         ->  Seq Scan on _timescaledb_internal._hyper_2_12_chunk (actual rows=336.00 loops=1)
               Output: _hyper_2_12_chunk.device_id_peer, _hyper_2_12_chunk.device_id
   ->  Hash (actual rows=2.00 loops=1)
         Output: "*VALUES*".column1
         ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
               Output: "*VALUES*".column1

-- test view
CREATE OR REPLACE VIEW compressed_view AS
SELECT time,
    device_id,
    v1,
    v2
FROM :TEST_TABLE;
:PREFIX
SELECT *
FROM compressed_view
WHERE device_id = 1
ORDER BY time DESC
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=10.00 loops=1)
         Order: metrics_space."time" DESC
         ->  Sort (actual rows=10.00 loops=1)
               Sort Key: _hyper_2_10_chunk."time" DESC
               Sort Method: top-N heapsort 
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
                     ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                           Filter: (device_id = 1)
         ->  Index Scan using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk (never executed)
               Filter: (device_id = 1)
         ->  Sort (never executed)
               Sort Key: _hyper_2_4_chunk."time" DESC
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (never executed)
                     ->  Seq Scan on compress_hyper_6_17_chunk (never executed)
                           Filter: (device_id = 1)

DROP VIEW compressed_view;
-- test INNER JOIN
:PREFIX
SELECT *
FROM :TEST_TABLE m1
    INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time
        AND m1.device_id = m2.device_id
    ORDER BY m1.time,
        m1.device_id
    LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Merge Join (actual rows=10.00 loops=1)
         Merge Cond: ((m1."time" = m2."time") AND (m1.device_id = m2.device_id))
         ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=10.00 loops=1)
               Order: m1."time", m1.device_id
               ->  Merge Append (actual rows=10.00 loops=1)
                     Sort Key: m1."time", m1.device_id
                     ->  Sort (actual rows=3.00 loops=1)
                           Sort Key: m1_1."time", m1_1.device_id
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m1_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     ->  Sort (actual rows=6.00 loops=1)
                           Sort Key: m1_2."time", m1_2.device_id
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m1_2 (actual rows=2160.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                     ->  Sort (actual rows=3.00 loops=1)
                           Sort Key: m1_3."time", m1_3.device_id
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m1_3 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
               ->  Merge Append (never executed)
                     Sort Key: m1."time", m1.device_id
                     ->  Sort (never executed)
                           Sort Key: m1_4."time", m1_4.device_id
                           ->  Seq Scan on _hyper_2_7_chunk m1_4 (never executed)
                     ->  Sort (never executed)
                           Sort Key: m1_5."time", m1_5.device_id
                           ->  Seq Scan on _hyper_2_8_chunk m1_5 (never executed)
                     ->  Sort (never executed)
                           Sort Key: m1_6."time", m1_6.device_id
                           ->  Seq Scan on _hyper_2_9_chunk m1_6 (never executed)
               ->  Merge Append (never executed)
                     Sort Key: m1."time", m1.device_id
                     ->  Sort (never executed)
                           Sort Key: m1_7."time", m1_7.device_id
                           ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m1_7 (never executed)
                                 ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                     ->  Sort (never executed)
                           Sort Key: m1_8."time", m1_8.device_id
                           ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m1_8 (never executed)
                                 ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                     ->  Sort (never executed)
                           Sort Key: m1_9."time", m1_9.device_id
                           ->  Seq Scan on _hyper_2_12_chunk m1_9 (never executed)
         ->  Materialize (actual rows=10.00 loops=1)
               ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=10.00 loops=1)
                     Order: m2."time", m2.device_id
                     ->  Merge Append (actual rows=10.00 loops=1)
                           Sort Key: m2."time", m2.device_id
                           ->  Sort (actual rows=3.00 loops=1)
                                 Sort Key: m2_1."time", m2_1.device_id
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m2_1 (actual rows=720.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_17_chunk compress_hyper_6_17_chunk_1 (actual rows=1.00 loops=1)
                           ->  Sort (actual rows=6.00 loops=1)
                                 Sort Key: m2_2."time", m2_2.device_id
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m2_2 (actual rows=2160.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_18_chunk compress_hyper_6_18_chunk_1 (actual rows=3.00 loops=1)
                           ->  Sort (actual rows=3.00 loops=1)
                                 Sort Key: m2_3."time", m2_3.device_id
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m2_3 (actual rows=720.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_19_chunk compress_hyper_6_19_chunk_1 (actual rows=1.00 loops=1)
                     ->  Merge Append (never executed)
                           Sort Key: m2."time", m2.device_id
                           ->  Sort (never executed)
                                 Sort Key: m2_4."time", m2_4.device_id
                                 ->  Seq Scan on _hyper_2_7_chunk m2_4 (never executed)
                           ->  Sort (never executed)
                                 Sort Key: m2_5."time", m2_5.device_id
                                 ->  Seq Scan on _hyper_2_8_chunk m2_5 (never executed)
                           ->  Sort (never executed)
                                 Sort Key: m2_6."time", m2_6.device_id
                                 ->  Seq Scan on _hyper_2_9_chunk m2_6 (never executed)
                     ->  Merge Append (never executed)
                           Sort Key: m2."time", m2.device_id
                           ->  Sort (never executed)
                                 Sort Key: m2_7."time", m2_7.device_id
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m2_7 (never executed)
                                       ->  Seq Scan on compress_hyper_6_20_chunk compress_hyper_6_20_chunk_1 (never executed)
                           ->  Sort (never executed)
                                 Sort Key: m2_8."time", m2_8.device_id
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m2_8 (never executed)
                                       ->  Seq Scan on compress_hyper_6_21_chunk compress_hyper_6_21_chunk_1 (never executed)
                           ->  Sort (never executed)
                                 Sort Key: m2_9."time", m2_9.device_id
                                 ->  Seq Scan on _hyper_2_12_chunk m2_9 (never executed)

:PREFIX
SELECT *
FROM :TEST_TABLE m1
    INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time
    INNER JOIN :TEST_TABLE m3 ON m2.time = m3.time
        AND m1.device_id = m2.device_id
        AND m3.device_id = 3
    ORDER BY m1.time,
        m1.device_id
    LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Merge Join (actual rows=10.00 loops=1)
         Merge Cond: ((m2."time" = m1."time") AND (m2.device_id = m1.device_id))
         ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=10.00 loops=1)
               Order: m2."time", m2.device_id
               ->  Merge Append (actual rows=10.00 loops=1)
                     Sort Key: m2."time", m2.device_id
                     ->  Sort (actual rows=3.00 loops=1)
                           Sort Key: m2_1."time", m2_1.device_id
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m2_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_17_chunk compress_hyper_6_17_chunk_1 (actual rows=1.00 loops=1)
                     ->  Sort (actual rows=6.00 loops=1)
                           Sort Key: m2_2."time", m2_2.device_id
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m2_2 (actual rows=2160.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_18_chunk compress_hyper_6_18_chunk_1 (actual rows=3.00 loops=1)
                     ->  Sort (actual rows=3.00 loops=1)
                           Sort Key: m2_3."time", m2_3.device_id
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m2_3 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_19_chunk compress_hyper_6_19_chunk_1 (actual rows=1.00 loops=1)
               ->  Merge Append (never executed)
                     Sort Key: m2."time", m2.device_id
                     ->  Sort (never executed)
                           Sort Key: m2_4."time", m2_4.device_id
                           ->  Seq Scan on _hyper_2_7_chunk m2_4 (never executed)
                     ->  Sort (never executed)
                           Sort Key: m2_5."time", m2_5.device_id
                           ->  Seq Scan on _hyper_2_8_chunk m2_5 (never executed)
                     ->  Sort (never executed)
                           Sort Key: m2_6."time", m2_6.device_id
                           ->  Seq Scan on _hyper_2_9_chunk m2_6 (never executed)
               ->  Merge Append (never executed)
                     Sort Key: m2."time", m2.device_id
                     ->  Sort (never executed)
                           Sort Key: m2_7."time", m2_7.device_id
                           ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m2_7 (never executed)
                                 ->  Seq Scan on compress_hyper_6_20_chunk compress_hyper_6_20_chunk_1 (never executed)
                     ->  Sort (never executed)
                           Sort Key: m2_8."time", m2_8.device_id
                           ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m2_8 (never executed)
                                 ->  Seq Scan on compress_hyper_6_21_chunk compress_hyper_6_21_chunk_1 (never executed)
                     ->  Sort (never executed)
                           Sort Key: m2_9."time", m2_9.device_id
                           ->  Seq Scan on _hyper_2_12_chunk m2_9 (never executed)
         ->  Materialize (actual rows=10.00 loops=1)
               ->  Merge Join (actual rows=10.00 loops=1)
                     Merge Cond: (m1."time" = m3."time")
                     ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=10.00 loops=1)
                           Order: m1."time", m1.device_id
                           ->  Merge Append (actual rows=10.00 loops=1)
                                 Sort Key: m1."time", m1.device_id
                                 ->  Sort (actual rows=3.00 loops=1)
                                       Sort Key: m1_1."time", m1_1.device_id
                                       Sort Method: quicksort 
                                       ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m1_1 (actual rows=720.00 loops=1)
                                             ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                 ->  Sort (actual rows=6.00 loops=1)
                                       Sort Key: m1_2."time", m1_2.device_id
                                       Sort Method: quicksort 
                                       ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m1_2 (actual rows=2160.00 loops=1)
                                             ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                                 ->  Sort (actual rows=3.00 loops=1)
                                       Sort Key: m1_3."time", m1_3.device_id
                                       Sort Method: quicksort 
                                       ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m1_3 (actual rows=720.00 loops=1)
                                             ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                           ->  Merge Append (never executed)
                                 Sort Key: m1."time", m1.device_id
                                 ->  Sort (never executed)
                                       Sort Key: m1_4."time", m1_4.device_id
                                       ->  Seq Scan on _hyper_2_7_chunk m1_4 (never executed)
                                 ->  Sort (never executed)
                                       Sort Key: m1_5."time", m1_5.device_id
                                       ->  Seq Scan on _hyper_2_8_chunk m1_5 (never executed)
                                 ->  Sort (never executed)
                                       Sort Key: m1_6."time", m1_6.device_id
                                       ->  Seq Scan on _hyper_2_9_chunk m1_6 (never executed)
                           ->  Merge Append (never executed)
                                 Sort Key: m1."time", m1.device_id
                                 ->  Sort (never executed)
                                       Sort Key: m1_7."time", m1_7.device_id
                                       ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m1_7 (never executed)
                                             ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                 ->  Sort (never executed)
                                       Sort Key: m1_8."time", m1_8.device_id
                                       ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m1_8 (never executed)
                                             ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 ->  Sort (never executed)
                                       Sort Key: m1_9."time", m1_9.device_id
                                       ->  Seq Scan on _hyper_2_12_chunk m1_9 (never executed)
                     ->  Materialize (actual rows=10.00 loops=1)
                           ->  Custom Scan (ChunkAppend) on metrics_space m3 (actual rows=3.00 loops=1)
                                 Order: m3."time"
                                 ->  Sort (actual rows=3.00 loops=1)
                                       Sort Key: m3_1."time"
                                       Sort Method: quicksort 
                                       ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m3_1 (actual rows=720.00 loops=1)
                                             ->  Seq Scan on compress_hyper_6_19_chunk compress_hyper_6_19_chunk_2 (actual rows=1.00 loops=1)
                                                   Filter: (device_id = 3)
                                 ->  Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk m3_2 (never executed)
                                       Filter: (device_id = 3)
                                 ->  Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk m3_3 (never executed)
                                       Filter: (device_id = 3)

:PREFIX
SELECT *
FROM :TEST_TABLE m1
    INNER JOIN :TEST_TABLE m2 ON m1.time = m2.time
        AND m1.device_id = 1
        AND m2.device_id = 2
    ORDER BY m1.time,
        m1.device_id,
        m2.time,
        m2.device_id
    LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Merge Join (actual rows=100.00 loops=1)
         Merge Cond: (m2."time" = m1."time")
         ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=100.00 loops=1)
               Order: m2."time"
               ->  Sort (actual rows=100.00 loops=1)
                     Sort Key: m2_1."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m2_1 (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = 2)
                                 Rows Removed by Filter: 2
               ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk m2_2 (never executed)
                     Index Cond: (device_id = 2)
               ->  Sort (never executed)
                     Sort Key: m2_3."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m2_3 (never executed)
                           ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                 Filter: (device_id = 2)
         ->  Materialize (actual rows=100.00 loops=1)
               ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=100.00 loops=1)
                     Order: m1."time"
                     ->  Sort (actual rows=100.00 loops=1)
                           Sort Key: m1_1."time"
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m1_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                                       Filter: (device_id = 1)
                     ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk m1_2 (never executed)
                           Filter: (device_id = 1)
                     ->  Sort (never executed)
                           Sort Key: m1_3."time"
                           ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m1_3 (never executed)
                                 ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                                       Filter: (device_id = 1)

:PREFIX
SELECT *
FROM metrics m1
    INNER JOIN metrics_space m2 ON m1.time = m2.time
        AND m1.device_id = 1
        AND m2.device_id = 2
    ORDER BY m1.time,
        m1.device_id,
        m2.time,
        m2.device_id
    LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Merge Join (actual rows=100.00 loops=1)
         Merge Cond: (m1."time" = m2."time")
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Sort (actual rows=100.00 loops=1)
                     Sort Key: m1_1."time"
                     Sort Method: quicksort 
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = 1)
                                 Rows Removed by Filter: 4
               ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk m1_2 (never executed)
                     Filter: (device_id = 1)
               ->  Sort (never executed)
                     Sort Key: m1_3."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (never executed)
                           ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                                 Filter: (device_id = 1)
         ->  Materialize (actual rows=100.00 loops=1)
               ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=100.00 loops=1)
                     Order: m2."time"
                     ->  Sort (actual rows=100.00 loops=1)
                           Sort Key: m2_1."time"
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m2_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=1.00 loops=1)
                                       Filter: (device_id = 2)
                                       Rows Removed by Filter: 2
                     ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk m2_2 (never executed)
                           Index Cond: (device_id = 2)
                     ->  Sort (never executed)
                           Sort Key: m2_3."time"
                           ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m2_3 (never executed)
                                 ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                                       Filter: (device_id = 2)

-- test OUTER JOIN
:PREFIX
SELECT *
FROM :TEST_TABLE m1
    LEFT OUTER JOIN :TEST_TABLE m2 ON m1.time = m2.time
    AND m1.device_id = m2.device_id
ORDER BY m1.time,
    m1.device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Merge Left Join (actual rows=10.00 loops=1)
         Merge Cond: (m1."time" = m2."time")
         Join Filter: (m1.device_id = m2.device_id)
         Rows Removed by Join Filter: 39
         ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=10.00 loops=1)
               Order: m1."time", m1.device_id
               ->  Merge Append (actual rows=10.00 loops=1)
                     Sort Key: m1."time", m1.device_id
                     ->  Sort (actual rows=3.00 loops=1)
                           Sort Key: m1_1."time", m1_1.device_id
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m1_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     ->  Sort (actual rows=6.00 loops=1)
                           Sort Key: m1_2."time", m1_2.device_id
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m1_2 (actual rows=2160.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                     ->  Sort (actual rows=3.00 loops=1)
                           Sort Key: m1_3."time", m1_3.device_id
                           Sort Method: quicksort 
                           ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m1_3 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
               ->  Merge Append (never executed)
                     Sort Key: m1."time", m1.device_id
                     ->  Sort (never executed)
                           Sort Key: m1_4."time", m1_4.device_id
                           ->  Seq Scan on _hyper_2_7_chunk m1_4 (never executed)
                     ->  Sort (never executed)
                           Sort Key: m1_5."time", m1_5.device_id
                           ->  Seq Scan on _hyper_2_8_chunk m1_5 (never executed)
                     ->  Sort (never executed)
                           Sort Key: m1_6."time", m1_6.device_id
                           ->  Seq Scan on _hyper_2_9_chunk m1_6 (never executed)
               ->  Merge Append (never executed)
                     Sort Key: m1."time", m1.device_id
                     ->  Sort (never executed)
                           Sort Key: m1_7."time", m1_7.device_id
                           ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m1_7 (never executed)
                                 ->  Seq Scan on compress_hyper_6_20_chunk (never executed)
                     ->  Sort (never executed)
                           Sort Key: m1_8."time", m1_8.device_id
                           ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m1_8 (never executed)
                                 ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                     ->  Sort (never executed)
                           Sort Key: m1_9."time", m1_9.device_id
                           ->  Seq Scan on _hyper_2_12_chunk m1_9 (never executed)
         ->  Materialize (actual rows=49.00 loops=1)
               ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=11.00 loops=1)
                     Order: m2."time"
                     ->  Merge Append (actual rows=11.00 loops=1)
                           Sort Key: m2."time"
                           ->  Sort (actual rows=3.00 loops=1)
                                 Sort Key: m2_1."time"
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m2_1 (actual rows=720.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_17_chunk compress_hyper_6_17_chunk_1 (actual rows=1.00 loops=1)
                           ->  Sort (actual rows=7.00 loops=1)
                                 Sort Key: m2_2."time"
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m2_2 (actual rows=2160.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_18_chunk compress_hyper_6_18_chunk_1 (actual rows=3.00 loops=1)
                           ->  Sort (actual rows=3.00 loops=1)
                                 Sort Key: m2_3."time"
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m2_3 (actual rows=720.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_19_chunk compress_hyper_6_19_chunk_1 (actual rows=1.00 loops=1)
                     ->  Merge Append (never executed)
                           Sort Key: m2."time"
                           ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk m2_4 (never executed)
                           ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk m2_5 (never executed)
                           ->  Index Scan Backward using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk m2_6 (never executed)
                     ->  Merge Append (never executed)
                           Sort Key: m2."time"
                           ->  Sort (never executed)
                                 Sort Key: m2_7."time"
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m2_7 (never executed)
                                       ->  Seq Scan on compress_hyper_6_20_chunk compress_hyper_6_20_chunk_1 (never executed)
                           ->  Sort (never executed)
                                 Sort Key: m2_8."time"
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m2_8 (never executed)
                                       ->  Seq Scan on compress_hyper_6_21_chunk compress_hyper_6_21_chunk_1 (never executed)
                           ->  Index Scan Backward using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk m2_9 (never executed)

:PREFIX
SELECT *
FROM :TEST_TABLE m1
    LEFT OUTER JOIN :TEST_TABLE m2 ON m1.time = m2.time
    AND m1.device_id = 1
    AND m2.device_id = 2
ORDER BY m1.time,
    m1.device_id,
    m2.time,
    m2.device_id
LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Sort (actual rows=100.00 loops=1)
         Sort Key: m1."time", m1.device_id, m2."time", m2.device_id
         Sort Method: top-N heapsort 
         ->  Hash Left Join (actual rows=8640.00 loops=1)
               Hash Cond: (m1."time" = m2."time")
               Join Filter: (m1.device_id = 1)
               Rows Removed by Join Filter: 6912
               ->  Append (actual rows=8640.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m1_1 (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m1_2 (actual rows=2160.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m1_3 (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                     ->  Seq Scan on _hyper_2_7_chunk m1_4 (actual rows=672.00 loops=1)
                     ->  Seq Scan on _hyper_2_8_chunk m1_5 (actual rows=2016.00 loops=1)
                     ->  Seq Scan on _hyper_2_9_chunk m1_6 (actual rows=672.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m1_7 (actual rows=336.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m1_8 (actual rows=1008.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     ->  Seq Scan on _hyper_2_12_chunk m1_9 (actual rows=336.00 loops=1)
               ->  Hash (actual rows=1728.00 loops=1)
                     ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=1728.00 loops=1)
                           Order: m2."time"
                           ->  Sort (actual rows=720.00 loops=1)
                                 Sort Key: m2_1."time"
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m2_1 (actual rows=720.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_18_chunk compress_hyper_6_18_chunk_1 (actual rows=1.00 loops=1)
                                             Filter: (device_id = 2)
                                             Rows Removed by Filter: 2
                           ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk m2_2 (actual rows=672.00 loops=1)
                                 Index Cond: (device_id = 2)
                           ->  Sort (actual rows=336.00 loops=1)
                                 Sort Key: m2_3."time"
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m2_3 (actual rows=336.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_21_chunk compress_hyper_6_21_chunk_1 (actual rows=1.00 loops=1)
                                             Filter: (device_id = 2)
                                             Rows Removed by Filter: 2

:PREFIX
SELECT *
FROM metrics m1
    LEFT OUTER JOIN metrics_space m2 ON m1.time = m2.time
    AND m1.device_id = 1
    AND m2.device_id = 2
ORDER BY m1.time,
    m1.device_id,
    m2.time,
    m2.device_id
LIMIT 100;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Sort (actual rows=100.00 loops=1)
         Sort Key: m1."time", m1.device_id, m2."time", m2.device_id
         Sort Method: top-N heapsort 
         ->  Hash Left Join (actual rows=8640.00 loops=1)
               Hash Cond: (m1."time" = m2."time")
               Join Filter: (m1.device_id = 1)
               Rows Removed by Join Filter: 6912
               ->  Append (actual rows=8640.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk m1_1 (actual rows=3600.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
                     ->  Seq Scan on _hyper_1_2_chunk m1_2 (actual rows=3360.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk m1_3 (actual rows=1680.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)
               ->  Hash (actual rows=1728.00 loops=1)
                     ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=1728.00 loops=1)
                           Order: m2."time"
                           ->  Sort (actual rows=720.00 loops=1)
                                 Sort Key: m2_1."time"
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m2_1 (actual rows=720.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=1.00 loops=1)
                                             Filter: (device_id = 2)
                                             Rows Removed by Filter: 2
                           ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk m2_2 (actual rows=672.00 loops=1)
                                 Index Cond: (device_id = 2)
                           ->  Sort (actual rows=336.00 loops=1)
                                 Sort Key: m2_3."time"
                                 Sort Method: quicksort 
                                 ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m2_3 (actual rows=336.00 loops=1)
                                       ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=1.00 loops=1)
                                             Filter: (device_id = 2)
                                             Rows Removed by Filter: 2

-- test implicit self-join
:PREFIX
SELECT *
FROM :TEST_TABLE m1,
    :TEST_TABLE m2
WHERE m1.time = m2.time
ORDER BY m1.time,
    m1.device_id,
    m2.time,
    m2.device_id
LIMIT 20;
--- QUERY PLAN ---
 Limit (actual rows=20.00 loops=1)
   ->  Sort (actual rows=20.00 loops=1)
         Sort Key: m1."time", m1.device_id, m2.device_id
         Sort Method: top-N heapsort 
         ->  Hash Join (actual rows=43200.00 loops=1)
               Hash Cond: (m1."time" = m2."time")
               ->  Append (actual rows=8640.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m1_1 (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m1_2 (actual rows=2160.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m1_3 (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                     ->  Seq Scan on _hyper_2_7_chunk m1_4 (actual rows=672.00 loops=1)
                     ->  Seq Scan on _hyper_2_8_chunk m1_5 (actual rows=2016.00 loops=1)
                     ->  Seq Scan on _hyper_2_9_chunk m1_6 (actual rows=672.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m1_7 (actual rows=336.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m1_8 (actual rows=1008.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     ->  Seq Scan on _hyper_2_12_chunk m1_9 (actual rows=336.00 loops=1)
               ->  Hash (actual rows=8640.00 loops=1)
                     ->  Append (actual rows=8640.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m2_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_17_chunk compress_hyper_6_17_chunk_1 (actual rows=1.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m2_2 (actual rows=2160.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_18_chunk compress_hyper_6_18_chunk_1 (actual rows=3.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m2_3 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_19_chunk compress_hyper_6_19_chunk_1 (actual rows=1.00 loops=1)
                           ->  Seq Scan on _hyper_2_7_chunk m2_4 (actual rows=672.00 loops=1)
                           ->  Seq Scan on _hyper_2_8_chunk m2_5 (actual rows=2016.00 loops=1)
                           ->  Seq Scan on _hyper_2_9_chunk m2_6 (actual rows=672.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m2_7 (actual rows=336.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_20_chunk compress_hyper_6_20_chunk_1 (actual rows=1.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m2_8 (actual rows=1008.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_21_chunk compress_hyper_6_21_chunk_1 (actual rows=3.00 loops=1)
                           ->  Seq Scan on _hyper_2_12_chunk m2_9 (actual rows=336.00 loops=1)

-- test self-join with sub-query
:PREFIX
SELECT *
FROM (
    SELECT *
    FROM :TEST_TABLE m1) m1
    INNER JOIN (
        SELECT *
        FROM :TEST_TABLE m2) m2 ON m1.time = m2.time
ORDER BY m1.time,
    m1.device_id,
    m2.device_id
LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Sort (actual rows=10.00 loops=1)
         Sort Key: m1."time", m1.device_id, m2.device_id
         Sort Method: top-N heapsort 
         ->  Hash Join (actual rows=43200.00 loops=1)
               Hash Cond: (m1."time" = m2."time")
               ->  Append (actual rows=8640.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m1_1 (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m1_2 (actual rows=2160.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m1_3 (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
                     ->  Seq Scan on _hyper_2_7_chunk m1_4 (actual rows=672.00 loops=1)
                     ->  Seq Scan on _hyper_2_8_chunk m1_5 (actual rows=2016.00 loops=1)
                     ->  Seq Scan on _hyper_2_9_chunk m1_6 (actual rows=672.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m1_7 (actual rows=336.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m1_8 (actual rows=1008.00 loops=1)
                           ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
                     ->  Seq Scan on _hyper_2_12_chunk m1_9 (actual rows=336.00 loops=1)
               ->  Hash (actual rows=8640.00 loops=1)
                     ->  Append (actual rows=8640.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m2_1 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_17_chunk compress_hyper_6_17_chunk_1 (actual rows=1.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m2_2 (actual rows=2160.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_18_chunk compress_hyper_6_18_chunk_1 (actual rows=3.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m2_3 (actual rows=720.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_19_chunk compress_hyper_6_19_chunk_1 (actual rows=1.00 loops=1)
                           ->  Seq Scan on _hyper_2_7_chunk m2_4 (actual rows=672.00 loops=1)
                           ->  Seq Scan on _hyper_2_8_chunk m2_5 (actual rows=2016.00 loops=1)
                           ->  Seq Scan on _hyper_2_9_chunk m2_6 (actual rows=672.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m2_7 (actual rows=336.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_20_chunk compress_hyper_6_20_chunk_1 (actual rows=1.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m2_8 (actual rows=1008.00 loops=1)
                                 ->  Seq Scan on compress_hyper_6_21_chunk compress_hyper_6_21_chunk_1 (actual rows=3.00 loops=1)
                           ->  Seq Scan on _hyper_2_12_chunk m2_9 (actual rows=336.00 loops=1)

:PREFIX
SELECT *
FROM generate_series('2000-01-01'::timestamptz, '2000-02-01'::timestamptz, '1d'::interval) g (time)
        INNER JOIN LATERAL (
            SELECT time
            FROM :TEST_TABLE m1
            WHERE m1.time = g.time
            LIMIT 1) m1 ON TRUE;
--- QUERY PLAN ---
 Nested Loop (actual rows=19.00 loops=1)
   ->  Function Scan on generate_series g (actual rows=32.00 loops=1)
   ->  Limit (actual rows=1.00 loops=32)
         ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=1.00 loops=32)
               Chunks excluded during runtime: 7
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m1_1 (actual rows=1.00 loops=5)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 336
                     ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=5)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time"))
               ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m1_2 (never executed)
                     Filter: ("time" = g."time")
                     ->  Seq Scan on compress_hyper_6_18_chunk (never executed)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time"))
               ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk m1_3 (never executed)
                     Filter: ("time" = g."time")
                     ->  Seq Scan on compress_hyper_6_19_chunk (never executed)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time"))
               ->  Index Only Scan using _hyper_2_7_chunk_metrics_space_time_idx on _hyper_2_7_chunk m1_4 (actual rows=1.00 loops=7)
                     Index Cond: ("time" = g."time")
               ->  Index Only Scan using _hyper_2_8_chunk_metrics_space_time_idx on _hyper_2_8_chunk m1_5 (never executed)
                     Index Cond: ("time" = g."time")
               ->  Index Only Scan using _hyper_2_9_chunk_metrics_space_time_idx on _hyper_2_9_chunk m1_6 (never executed)
                     Index Cond: ("time" = g."time")
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m1_7 (actual rows=1.00 loops=7)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 160
                     ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=7)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time"))
               ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m1_8 (never executed)
                     Filter: ("time" = g."time")
                     ->  Seq Scan on compress_hyper_6_21_chunk (never executed)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time"))
               ->  Index Only Scan using _hyper_2_12_chunk_metrics_space_time_idx on _hyper_2_12_chunk m1_9 (never executed)
                     Index Cond: ("time" = g."time")

-- test prepared statement with params pushdown
PREPARE param_prep (int) AS
SELECT *
FROM generate_series('2000-01-01'::timestamptz, '2000-02-01'::timestamptz, '1d'::interval) g (time)
        INNER JOIN LATERAL (
            SELECT time
            FROM :TEST_TABLE m1
            WHERE m1.time = g.time
                AND device_id = $1
            LIMIT 1) m1 ON TRUE;
:PREFIX EXECUTE param_prep (1);
--- QUERY PLAN ---
 Nested Loop (actual rows=19.00 loops=1)
   ->  Function Scan on generate_series g (actual rows=32.00 loops=1)
   ->  Limit (actual rows=1.00 loops=32)
         ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=1.00 loops=32)
               Chunks excluded during runtime: 2
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk m1_1 (actual rows=1.00 loops=5)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 336
                     ->  Seq Scan on compress_hyper_6_17_chunk (actual rows=1.00 loops=5)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time") AND (device_id = 1))
               ->  Index Only Scan using _hyper_2_7_chunk_metrics_space_device_id_time_idx on _hyper_2_7_chunk m1_2 (actual rows=1.00 loops=7)
                     Index Cond: ((device_id = 1) AND ("time" = g."time"))
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk m1_3 (actual rows=1.00 loops=7)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 160
                     ->  Seq Scan on compress_hyper_6_20_chunk (actual rows=1.00 loops=7)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time") AND (device_id = 1))

:PREFIX EXECUTE param_prep (2);
--- QUERY PLAN ---
 Nested Loop (actual rows=19.00 loops=1)
   ->  Function Scan on generate_series g (actual rows=32.00 loops=1)
   ->  Limit (actual rows=1.00 loops=32)
         ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=1.00 loops=32)
               Chunks excluded during runtime: 2
               ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk m1_1 (actual rows=1.00 loops=5)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 336
                     ->  Seq Scan on compress_hyper_6_18_chunk (actual rows=1.00 loops=5)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time") AND (device_id = 2))
               ->  Index Only Scan using _hyper_2_8_chunk_metrics_space_device_id_time_idx on _hyper_2_8_chunk m1_2 (actual rows=1.00 loops=7)
                     Index Cond: ((device_id = 2) AND ("time" = g."time"))
               ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk m1_3 (actual rows=1.00 loops=7)
                     Filter: ("time" = g."time")
                     Rows Removed by Filter: 160
                     ->  Seq Scan on compress_hyper_6_21_chunk (actual rows=1.00 loops=7)
                           Filter: ((_ts_meta_min_3 <= g."time") AND (_ts_meta_max_3 >= g."time") AND (device_id = 2))

EXECUTE param_prep (1);
             time             |             time             
------------------------------+------------------------------
 Sat Jan 01 00:00:00 2000 PST | Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST | Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST | Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST | Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST | Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST | Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST | Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST | Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST | Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST | Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST | Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST | Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST | Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST | Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST | Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST | Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST | Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST | Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST | Wed Jan 19 00:00:00 2000 PST

EXECUTE param_prep (2);
             time             |             time             
------------------------------+------------------------------
 Sat Jan 01 00:00:00 2000 PST | Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST | Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST | Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST | Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST | Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST | Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST | Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST | Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST | Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST | Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST | Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST | Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST | Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST | Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST | Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST | Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST | Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST | Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST | Wed Jan 19 00:00:00 2000 PST

EXECUTE param_prep (1);
             time             |             time             
------------------------------+------------------------------
 Sat Jan 01 00:00:00 2000 PST | Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST | Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST | Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST | Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST | Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST | Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST | Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST | Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST | Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST | Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST | Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST | Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST | Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST | Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST | Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST | Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST | Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST | Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST | Wed Jan 19 00:00:00 2000 PST

EXECUTE param_prep (2);
             time             |             time             
------------------------------+------------------------------
 Sat Jan 01 00:00:00 2000 PST | Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST | Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST | Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST | Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST | Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST | Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST | Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST | Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST | Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST | Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST | Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST | Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST | Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST | Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST | Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST | Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST | Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST | Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST | Wed Jan 19 00:00:00 2000 PST

EXECUTE param_prep (1);
             time             |             time             
------------------------------+------------------------------
 Sat Jan 01 00:00:00 2000 PST | Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST | Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST | Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST | Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST | Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST | Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST | Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST | Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST | Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST | Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST | Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST | Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST | Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST | Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST | Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST | Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST | Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST | Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST | Wed Jan 19 00:00:00 2000 PST

DEALLOCATE param_prep;
-- test continuous aggs
SET client_min_messages TO error;
CREATE MATERIALIZED VIEW cagg_test WITH (timescaledb.continuous, timescaledb.materialized_only = TRUE) AS
SELECT time_bucket ('1d', time) AS time,
    device_id,
    avg(v1)
FROM :TEST_TABLE
WHERE device_id = 1
GROUP BY 1,
    2 WITH DATA;
SELECT time
FROM cagg_test
ORDER BY time
LIMIT 1;
             time             
------------------------------
 Fri Dec 31 16:00:00 1999 PST

DROP MATERIALIZED VIEW cagg_test;
RESET client_min_messages;
--github issue 1558. nested loop with index scan needed
--disables parallel scan
SET enable_seqscan = FALSE;
SET enable_bitmapscan = FALSE;
SET max_parallel_workers_per_gather = 0;
SET enable_hashjoin = FALSE;
SET enable_mergejoin = FALSE;
:PREFIX
SELECT *
FROM metrics,
    metrics_space
WHERE metrics.time > metrics_space.time
    AND metrics.device_id = metrics_space.device_id
    AND metrics.time < metrics_space.time;
--- QUERY PLAN ---
 Nested Loop (actual rows=0.00 loops=1)
   ->  Append (actual rows=8640.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk (actual rows=720.00 loops=1)
               ->  Index Scan using compress_hyper_6_17_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_17_chunk (actual rows=1.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk (actual rows=2160.00 loops=1)
               ->  Index Scan using compress_hyper_6_18_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_18_chunk (actual rows=3.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk (actual rows=720.00 loops=1)
               ->  Index Scan using compress_hyper_6_19_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_19_chunk (actual rows=1.00 loops=1)
         ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_7_chunk (actual rows=672.00 loops=1)
         ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_8_chunk (actual rows=2016.00 loops=1)
         ->  Index Scan Backward using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_9_chunk (actual rows=672.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk (actual rows=336.00 loops=1)
               ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_20_chunk (actual rows=1.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk (actual rows=1008.00 loops=1)
               ->  Index Scan using compress_hyper_6_21_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_21_chunk (actual rows=3.00 loops=1)
         ->  Index Scan Backward using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v_2 on _hyper_2_12_chunk (actual rows=336.00 loops=1)
   ->  Append (actual rows=0.00 loops=8640)
         ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=0.00 loops=8640)
               Filter: (("time" > metrics_space."time") AND ("time" < metrics_space."time"))
               Rows Removed by Filter: 720
               ->  Index Scan using compress_hyper_5_15_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_5_15_chunk (actual rows=1.00 loops=8640)
                     Index Cond: (device_id = metrics_space.device_id)
         ->  Index Scan using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (actual rows=0.00 loops=8640)
               Index Cond: (("time" > metrics_space."time") AND ("time" < metrics_space."time"))
               Filter: (metrics_space.device_id = device_id)
         ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=0.00 loops=8640)
               Filter: (("time" > metrics_space."time") AND ("time" < metrics_space."time"))
               Rows Removed by Filter: 336
               ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_5_16_chunk (actual rows=1.00 loops=8640)
                     Index Cond: (device_id = metrics_space.device_id)

SET enable_seqscan = TRUE;
SET enable_bitmapscan = TRUE;
SET max_parallel_workers_per_gather = 0;
SET enable_hashjoin = TRUE;
SET enable_mergejoin = TRUE;
---end github issue 1558
\ir include/transparent_decompression_ordered.sql
-- 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 work_mem TO '50MB';
-- for ordered append tests on compressed chunks we need a hypertable with time as compress_orderby column
CREATE TABLE metrics_ordered(time timestamptz NOT NULL, device_id int, device_id_peer int, v0 int, v1 int, v2 float, v3 float);
SELECT create_hypertable('metrics_ordered','time');
       create_hypertable       
-------------------------------
 (11,public,metrics_ordered,t)

ALTER TABLE metrics_ordered SET (timescaledb.compress, timescaledb.compress_orderby='time DESC',timescaledb.compress_segmentby='device_id,device_id_peer');
INSERT INTO metrics_ordered SELECT * FROM metrics;
CREATE INDEX ON metrics_ordered(device_id,device_id_peer,time);
CREATE INDEX ON metrics_ordered(device_id,time);
CREATE INDEX ON metrics_ordered(device_id_peer,time);
-- compress all chunks
SELECT count(compress_chunk(ch)) FROM show_chunks('metrics_ordered') ch;
 count 
-------
     3

VACUUM ANALYZE metrics_ordered;
-- should not have ordered DecompressChunk path because segmentby columns are not part of pathkeys
:PREFIX SELECT * FROM metrics_ordered ORDER BY time DESC LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=10.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_ordered (actual rows=10.00 loops=1)
         Order: metrics_ordered."time" DESC
         ->  Custom Scan (ColumnarScan) on _hyper_11_28_chunk (actual rows=10.00 loops=1)
               ->  Sort (actual rows=5.00 loops=1)
                     Sort Key: compress_hyper_12_31_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_12_31_chunk (actual rows=5.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_11_27_chunk (never executed)
               ->  Sort (never executed)
                     Sort Key: compress_hyper_12_30_chunk._ts_meta_max_1 DESC
                     ->  Seq Scan on compress_hyper_12_30_chunk (never executed)
         ->  Custom Scan (ColumnarScan) on _hyper_11_26_chunk (never executed)
               ->  Sort (never executed)
                     Sort Key: compress_hyper_12_29_chunk._ts_meta_max_1 DESC
                     ->  Seq Scan on compress_hyper_12_29_chunk (never executed)

-- should have ordered DecompressChunk path because segmentby columns have equality constraints
:PREFIX SELECT * FROM metrics_ordered WHERE device_id = 1 AND device_id_peer = 3 ORDER BY time DESC LIMIT 10;
--- QUERY PLAN ---
 Limit (actual rows=0.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_ordered (actual rows=0.00 loops=1)
         Order: metrics_ordered."time" DESC
         ->  Custom Scan (ColumnarScan) on _hyper_11_28_chunk (actual rows=0.00 loops=1)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: compress_hyper_12_31_chunk._ts_meta_min_1 DESC, compress_hyper_12_31_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_12_31_chunk (actual rows=0.00 loops=1)
                           Filter: ((device_id = 1) AND (device_id_peer = 3))
                           Rows Removed by Filter: 5
         ->  Custom Scan (ColumnarScan) on _hyper_11_27_chunk (actual rows=0.00 loops=1)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: compress_hyper_12_30_chunk._ts_meta_min_1 DESC, compress_hyper_12_30_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_12_30_chunk (actual rows=0.00 loops=1)
                           Filter: ((device_id = 1) AND (device_id_peer = 3))
                           Rows Removed by Filter: 5
         ->  Custom Scan (ColumnarScan) on _hyper_11_26_chunk (actual rows=0.00 loops=1)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: compress_hyper_12_29_chunk._ts_meta_min_1 DESC, compress_hyper_12_29_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_12_29_chunk (actual rows=0.00 loops=1)
                           Filter: ((device_id = 1) AND (device_id_peer = 3))
                           Rows Removed by Filter: 5

:PREFIX SELECT DISTINCT ON (d.device_id) * FROM metrics_ordered d INNER JOIN LATERAL (SELECT * FROM metrics_ordered m WHERE m.device_id=d.device_id AND m.device_id_peer = 3 ORDER BY time DESC LIMIT 1 ) m ON true;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Nested Loop (actual rows=0.00 loops=1)
         ->  Merge Append (actual rows=8640.00 loops=1)
               Sort Key: d.device_id
               ->  Custom Scan (ColumnarScan) on _hyper_11_26_chunk d_1 (actual rows=3600.00 loops=1)
                     ->  Index Scan using compress_hyper_12_29_chunk_device_id_device_id_peer__ts_met_idx on compress_hyper_12_29_chunk (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_11_27_chunk d_2 (actual rows=3360.00 loops=1)
                     ->  Index Scan using compress_hyper_12_30_chunk_device_id_device_id_peer__ts_met_idx on compress_hyper_12_30_chunk (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_11_28_chunk d_3 (actual rows=1680.00 loops=1)
                     ->  Index Scan using compress_hyper_12_31_chunk_device_id_device_id_peer__ts_met_idx on compress_hyper_12_31_chunk (actual rows=5.00 loops=1)
         ->  Limit (actual rows=0.00 loops=8640)
               ->  Custom Scan (ChunkAppend) on metrics_ordered m (actual rows=0.00 loops=8640)
                     Order: m."time" DESC
                     Hypertables excluded during runtime: 0
                     ->  Custom Scan (ColumnarScan) on _hyper_11_28_chunk m_1 (actual rows=0.00 loops=8640)
                           ->  Sort (actual rows=0.00 loops=8640)
                                 Sort Key: compress_hyper_12_31_chunk_1._ts_meta_min_1 DESC, compress_hyper_12_31_chunk_1._ts_meta_max_1 DESC
                                 Sort Method: quicksort 
                                 ->  Seq Scan on compress_hyper_12_31_chunk compress_hyper_12_31_chunk_1 (actual rows=0.00 loops=8640)
                                       Filter: ((device_id = d.device_id) AND (device_id_peer = 3))
                                       Rows Removed by Filter: 5
                     ->  Custom Scan (ColumnarScan) on _hyper_11_27_chunk m_2 (actual rows=0.00 loops=8640)
                           ->  Sort (actual rows=0.00 loops=8640)
                                 Sort Key: compress_hyper_12_30_chunk_1._ts_meta_min_1 DESC, compress_hyper_12_30_chunk_1._ts_meta_max_1 DESC
                                 Sort Method: quicksort 
                                 ->  Seq Scan on compress_hyper_12_30_chunk compress_hyper_12_30_chunk_1 (actual rows=0.00 loops=8640)
                                       Filter: ((device_id = d.device_id) AND (device_id_peer = 3))
                                       Rows Removed by Filter: 5
                     ->  Custom Scan (ColumnarScan) on _hyper_11_26_chunk m_3 (actual rows=0.00 loops=8640)
                           ->  Sort (actual rows=0.00 loops=8640)
                                 Sort Key: compress_hyper_12_29_chunk_1._ts_meta_min_1 DESC, compress_hyper_12_29_chunk_1._ts_meta_max_1 DESC
                                 Sort Method: quicksort 
                                 ->  Seq Scan on compress_hyper_12_29_chunk compress_hyper_12_29_chunk_1 (actual rows=0.00 loops=8640)
                                       Filter: ((device_id = d.device_id) AND (device_id_peer = 3))
                                       Rows Removed by Filter: 5

\ir include/transparent_decompression_systemcolumns.sql
-- 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 TEST_TABLE 'metrics'
-- test system columns
-- all system columns except for tableoid should error
\set ON_ERROR_STOP 0
SELECT xmin FROM :TEST_TABLE ORDER BY time;
psql:include/transparent_decompression_systemcolumns.sql:10: ERROR:  transparent decompression only supports tableoid system column
SELECT cmin FROM :TEST_TABLE ORDER BY time;
psql:include/transparent_decompression_systemcolumns.sql:11: ERROR:  transparent decompression only supports tableoid system column
SELECT xmax FROM :TEST_TABLE ORDER BY time;
psql:include/transparent_decompression_systemcolumns.sql:12: ERROR:  transparent decompression only supports tableoid system column
SELECT cmax FROM :TEST_TABLE ORDER BY time;
psql:include/transparent_decompression_systemcolumns.sql:13: ERROR:  transparent decompression only supports tableoid system column
SELECT ctid FROM :TEST_TABLE ORDER BY time;
psql:include/transparent_decompression_systemcolumns.sql:14: ERROR:  transparent decompression only supports tableoid system column
-- test system columns in WHERE and ORDER BY clause
SELECT tableoid, xmin FROM :TEST_TABLE ORDER BY time;
psql:include/transparent_decompression_systemcolumns.sql:17: ERROR:  transparent decompression only supports tableoid system column
SELECT FROM :TEST_TABLE ORDER BY cmin::text;
psql:include/transparent_decompression_systemcolumns.sql:18: ERROR:  transparent decompression only supports tableoid system column
SELECT FROM :TEST_TABLE WHERE cmin IS NOT NULL;
psql:include/transparent_decompression_systemcolumns.sql:19: ERROR:  transparent decompression only supports tableoid system column
\set ON_ERROR_STOP 1
-- test tableoid in different parts of query
SELECT pg_typeof(tableoid) FROM :TEST_TABLE ORDER BY time LIMIT 1;
 pg_typeof 
-----------
 oid

SELECT FROM :TEST_TABLE ORDER BY tableoid LIMIT 1;
--

SELECT FROM :TEST_TABLE WHERE tableoid::int > 0 LIMIT 1;
--

SELECT tableoid::regclass FROM :TEST_TABLE GROUP BY tableoid ORDER BY 1;
                tableoid                
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk
 _timescaledb_internal._hyper_1_2_chunk
 _timescaledb_internal._hyper_1_3_chunk

SELECT count(distinct tableoid) FROM :TEST_TABLE WHERE device_id=1 AND time < now();
 count 
-------
     3

-- test prepared statement
PREPARE tableoid_prep AS SELECT tableoid::regclass FROM :TEST_TABLE WHERE device_id = 1 ORDER BY time LIMIT 1;
:PREFIX EXECUTE tableoid_prep;
--- QUERY PLAN ---
 Limit (actual rows=1.00 loops=1)
   ->  Result (actual rows=1.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics (actual rows=1.00 loops=1)
               Order: metrics."time"
               ->  Sort (actual rows=1.00 loops=1)
                     Sort Key: _hyper_1_1_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=720.00 loops=1)
                           ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=1.00 loops=1)
                                 Filter: (device_id = 1)
                                 Rows Removed by Filter: 4
               ->  Index Scan Backward using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk (never executed)
                     Filter: (device_id = 1)
               ->  Sort (never executed)
                     Sort Key: _hyper_1_3_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (never executed)
                           ->  Seq Scan on compress_hyper_5_16_chunk (never executed)
                                 Filter: (device_id = 1)

EXECUTE tableoid_prep;
                tableoid                
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk

EXECUTE tableoid_prep;
                tableoid                
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk

EXECUTE tableoid_prep;
                tableoid                
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk

EXECUTE tableoid_prep;
                tableoid                
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk

EXECUTE tableoid_prep;
                tableoid                
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk

DEALLOCATE tableoid_prep;
\ir include/transparent_decompression_undiffed.sql
-- 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.
-- test planning regression with many chunks
CREATE TABLE tags(id SERIAL PRIMARY KEY, name TEXT, fleet TEXT);
INSERT INTO tags (name, fleet) VALUES('n1', 'f1');
CREATE TABLE readings (time timestamptz, tags_id integer, fuel_consumption DOUBLE PRECISION);
CREATE INDEX ON readings(tags_id, "time" DESC);
CREATE INDEX ON readings("time" DESC);
SELECT create_hypertable('readings', 'time', partitioning_column => 'tags_id', number_partitions => 1, chunk_time_interval => 43200000000, create_default_indexes=>false);
   create_hypertable    
------------------------
 (13,public,readings,t)

ALTER TABLE readings SET (timescaledb.compress, timescaledb.compress_segmentby = 'tags_id', timescaledb.compress_orderby = 'time desc');
INSERT into readings select g, 1, 1.3 from generate_series('2001-03-01 01:01:01', '2003-02-01 01:01:01', '1 day'::interval) g;
SELECT count(compress_chunk(ch)) FROM show_chunks('readings') ch;
 count 
-------
   703

VACUUM ANALYZE readings;
EXPLAIN (buffers off, costs off) SELECT t.fleet as fleet, min(r.fuel_consumption) AS avg_fuel_consumption
FROM tags t
INNER JOIN LATERAL(SELECT tags_id, fuel_consumption FROM readings r WHERE r.tags_id = t.id ) r ON true
GROUP BY fleet;
--- QUERY PLAN ---
 HashAggregate
   Group Key: t.fleet
   ->  Hash Join
         Hash Cond: (r.tags_id = t.id)
         ->  Append
               ->  Custom Scan (ColumnarScan) on _hyper_13_32_chunk r_1
                     ->  Seq Scan on compress_hyper_14_735_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_33_chunk r_2
                     ->  Seq Scan on compress_hyper_14_736_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_34_chunk r_3
                     ->  Seq Scan on compress_hyper_14_737_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_35_chunk r_4
                     ->  Seq Scan on compress_hyper_14_738_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_36_chunk r_5
                     ->  Seq Scan on compress_hyper_14_739_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_37_chunk r_6
                     ->  Seq Scan on compress_hyper_14_740_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_38_chunk r_7
                     ->  Seq Scan on compress_hyper_14_741_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_39_chunk r_8
                     ->  Seq Scan on compress_hyper_14_742_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_40_chunk r_9
                     ->  Seq Scan on compress_hyper_14_743_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_41_chunk r_10
                     ->  Seq Scan on compress_hyper_14_744_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_42_chunk r_11
                     ->  Seq Scan on compress_hyper_14_745_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_43_chunk r_12
                     ->  Seq Scan on compress_hyper_14_746_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_44_chunk r_13
                     ->  Seq Scan on compress_hyper_14_747_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_45_chunk r_14
                     ->  Seq Scan on compress_hyper_14_748_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_46_chunk r_15
                     ->  Seq Scan on compress_hyper_14_749_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_47_chunk r_16
                     ->  Seq Scan on compress_hyper_14_750_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_48_chunk r_17
                     ->  Seq Scan on compress_hyper_14_751_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_49_chunk r_18
                     ->  Seq Scan on compress_hyper_14_752_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_50_chunk r_19
                     ->  Seq Scan on compress_hyper_14_753_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_51_chunk r_20
                     ->  Seq Scan on compress_hyper_14_754_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_52_chunk r_21
                     ->  Seq Scan on compress_hyper_14_755_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_53_chunk r_22
                     ->  Seq Scan on compress_hyper_14_756_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_54_chunk r_23
                     ->  Seq Scan on compress_hyper_14_757_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_55_chunk r_24
                     ->  Seq Scan on compress_hyper_14_758_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_56_chunk r_25
                     ->  Seq Scan on compress_hyper_14_759_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_57_chunk r_26
                     ->  Seq Scan on compress_hyper_14_760_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_58_chunk r_27
                     ->  Seq Scan on compress_hyper_14_761_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_59_chunk r_28
                     ->  Seq Scan on compress_hyper_14_762_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_60_chunk r_29
                     ->  Seq Scan on compress_hyper_14_763_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_61_chunk r_30
                     ->  Seq Scan on compress_hyper_14_764_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_62_chunk r_31
                     ->  Seq Scan on compress_hyper_14_765_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_63_chunk r_32
                     ->  Seq Scan on compress_hyper_14_766_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_64_chunk r_33
                     ->  Seq Scan on compress_hyper_14_767_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_65_chunk r_34
                     ->  Seq Scan on compress_hyper_14_768_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_66_chunk r_35
                     ->  Seq Scan on compress_hyper_14_769_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_67_chunk r_36
                     ->  Seq Scan on compress_hyper_14_770_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_68_chunk r_37
                     ->  Seq Scan on compress_hyper_14_771_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_69_chunk r_38
                     ->  Seq Scan on compress_hyper_14_772_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_70_chunk r_39
                     ->  Seq Scan on compress_hyper_14_773_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_71_chunk r_40
                     ->  Seq Scan on compress_hyper_14_774_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_72_chunk r_41
                     ->  Seq Scan on compress_hyper_14_775_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_73_chunk r_42
                     ->  Seq Scan on compress_hyper_14_776_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_74_chunk r_43
                     ->  Seq Scan on compress_hyper_14_777_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_75_chunk r_44
                     ->  Seq Scan on compress_hyper_14_778_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_76_chunk r_45
                     ->  Seq Scan on compress_hyper_14_779_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_77_chunk r_46
                     ->  Seq Scan on compress_hyper_14_780_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_78_chunk r_47
                     ->  Seq Scan on compress_hyper_14_781_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_79_chunk r_48
                     ->  Seq Scan on compress_hyper_14_782_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_80_chunk r_49
                     ->  Seq Scan on compress_hyper_14_783_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_81_chunk r_50
                     ->  Seq Scan on compress_hyper_14_784_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_82_chunk r_51
                     ->  Seq Scan on compress_hyper_14_785_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_83_chunk r_52
                     ->  Seq Scan on compress_hyper_14_786_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_84_chunk r_53
                     ->  Seq Scan on compress_hyper_14_787_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_85_chunk r_54
                     ->  Seq Scan on compress_hyper_14_788_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_86_chunk r_55
                     ->  Seq Scan on compress_hyper_14_789_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_87_chunk r_56
                     ->  Seq Scan on compress_hyper_14_790_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_88_chunk r_57
                     ->  Seq Scan on compress_hyper_14_791_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_89_chunk r_58
                     ->  Seq Scan on compress_hyper_14_792_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_90_chunk r_59
                     ->  Seq Scan on compress_hyper_14_793_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_91_chunk r_60
                     ->  Seq Scan on compress_hyper_14_794_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_92_chunk r_61
                     ->  Seq Scan on compress_hyper_14_795_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_93_chunk r_62
                     ->  Seq Scan on compress_hyper_14_796_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_94_chunk r_63
                     ->  Seq Scan on compress_hyper_14_797_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_95_chunk r_64
                     ->  Seq Scan on compress_hyper_14_798_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_96_chunk r_65
                     ->  Seq Scan on compress_hyper_14_799_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_97_chunk r_66
                     ->  Seq Scan on compress_hyper_14_800_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_98_chunk r_67
                     ->  Seq Scan on compress_hyper_14_801_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_99_chunk r_68
                     ->  Seq Scan on compress_hyper_14_802_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_100_chunk r_69
                     ->  Seq Scan on compress_hyper_14_803_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_101_chunk r_70
                     ->  Seq Scan on compress_hyper_14_804_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_102_chunk r_71
                     ->  Seq Scan on compress_hyper_14_805_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_103_chunk r_72
                     ->  Seq Scan on compress_hyper_14_806_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_104_chunk r_73
                     ->  Seq Scan on compress_hyper_14_807_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_105_chunk r_74
                     ->  Seq Scan on compress_hyper_14_808_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_106_chunk r_75
                     ->  Seq Scan on compress_hyper_14_809_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_107_chunk r_76
                     ->  Seq Scan on compress_hyper_14_810_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_108_chunk r_77
                     ->  Seq Scan on compress_hyper_14_811_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_109_chunk r_78
                     ->  Seq Scan on compress_hyper_14_812_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_110_chunk r_79
                     ->  Seq Scan on compress_hyper_14_813_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_111_chunk r_80
                     ->  Seq Scan on compress_hyper_14_814_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_112_chunk r_81
                     ->  Seq Scan on compress_hyper_14_815_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_113_chunk r_82
                     ->  Seq Scan on compress_hyper_14_816_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_114_chunk r_83
                     ->  Seq Scan on compress_hyper_14_817_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_115_chunk r_84
                     ->  Seq Scan on compress_hyper_14_818_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_116_chunk r_85
                     ->  Seq Scan on compress_hyper_14_819_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_117_chunk r_86
                     ->  Seq Scan on compress_hyper_14_820_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_118_chunk r_87
                     ->  Seq Scan on compress_hyper_14_821_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_119_chunk r_88
                     ->  Seq Scan on compress_hyper_14_822_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_120_chunk r_89
                     ->  Seq Scan on compress_hyper_14_823_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_121_chunk r_90
                     ->  Seq Scan on compress_hyper_14_824_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_122_chunk r_91
                     ->  Seq Scan on compress_hyper_14_825_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_123_chunk r_92
                     ->  Seq Scan on compress_hyper_14_826_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_124_chunk r_93
                     ->  Seq Scan on compress_hyper_14_827_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_125_chunk r_94
                     ->  Seq Scan on compress_hyper_14_828_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_126_chunk r_95
                     ->  Seq Scan on compress_hyper_14_829_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_127_chunk r_96
                     ->  Seq Scan on compress_hyper_14_830_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_128_chunk r_97
                     ->  Seq Scan on compress_hyper_14_831_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_129_chunk r_98
                     ->  Seq Scan on compress_hyper_14_832_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_130_chunk r_99
                     ->  Seq Scan on compress_hyper_14_833_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_131_chunk r_100
                     ->  Seq Scan on compress_hyper_14_834_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_132_chunk r_101
                     ->  Seq Scan on compress_hyper_14_835_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_133_chunk r_102
                     ->  Seq Scan on compress_hyper_14_836_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_134_chunk r_103
                     ->  Seq Scan on compress_hyper_14_837_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_135_chunk r_104
                     ->  Seq Scan on compress_hyper_14_838_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_136_chunk r_105
                     ->  Seq Scan on compress_hyper_14_839_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_137_chunk r_106
                     ->  Seq Scan on compress_hyper_14_840_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_138_chunk r_107
                     ->  Seq Scan on compress_hyper_14_841_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_139_chunk r_108
                     ->  Seq Scan on compress_hyper_14_842_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_140_chunk r_109
                     ->  Seq Scan on compress_hyper_14_843_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_141_chunk r_110
                     ->  Seq Scan on compress_hyper_14_844_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_142_chunk r_111
                     ->  Seq Scan on compress_hyper_14_845_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_143_chunk r_112
                     ->  Seq Scan on compress_hyper_14_846_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_144_chunk r_113
                     ->  Seq Scan on compress_hyper_14_847_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_145_chunk r_114
                     ->  Seq Scan on compress_hyper_14_848_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_146_chunk r_115
                     ->  Seq Scan on compress_hyper_14_849_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_147_chunk r_116
                     ->  Seq Scan on compress_hyper_14_850_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_148_chunk r_117
                     ->  Seq Scan on compress_hyper_14_851_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_149_chunk r_118
                     ->  Seq Scan on compress_hyper_14_852_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_150_chunk r_119
                     ->  Seq Scan on compress_hyper_14_853_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_151_chunk r_120
                     ->  Seq Scan on compress_hyper_14_854_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_152_chunk r_121
                     ->  Seq Scan on compress_hyper_14_855_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_153_chunk r_122
                     ->  Seq Scan on compress_hyper_14_856_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_154_chunk r_123
                     ->  Seq Scan on compress_hyper_14_857_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_155_chunk r_124
                     ->  Seq Scan on compress_hyper_14_858_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_156_chunk r_125
                     ->  Seq Scan on compress_hyper_14_859_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_157_chunk r_126
                     ->  Seq Scan on compress_hyper_14_860_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_158_chunk r_127
                     ->  Seq Scan on compress_hyper_14_861_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_159_chunk r_128
                     ->  Seq Scan on compress_hyper_14_862_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_160_chunk r_129
                     ->  Seq Scan on compress_hyper_14_863_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_161_chunk r_130
                     ->  Seq Scan on compress_hyper_14_864_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_162_chunk r_131
                     ->  Seq Scan on compress_hyper_14_865_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_163_chunk r_132
                     ->  Seq Scan on compress_hyper_14_866_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_164_chunk r_133
                     ->  Seq Scan on compress_hyper_14_867_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_165_chunk r_134
                     ->  Seq Scan on compress_hyper_14_868_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_166_chunk r_135
                     ->  Seq Scan on compress_hyper_14_869_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_167_chunk r_136
                     ->  Seq Scan on compress_hyper_14_870_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_168_chunk r_137
                     ->  Seq Scan on compress_hyper_14_871_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_169_chunk r_138
                     ->  Seq Scan on compress_hyper_14_872_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_170_chunk r_139
                     ->  Seq Scan on compress_hyper_14_873_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_171_chunk r_140
                     ->  Seq Scan on compress_hyper_14_874_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_172_chunk r_141
                     ->  Seq Scan on compress_hyper_14_875_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_173_chunk r_142
                     ->  Seq Scan on compress_hyper_14_876_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_174_chunk r_143
                     ->  Seq Scan on compress_hyper_14_877_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_175_chunk r_144
                     ->  Seq Scan on compress_hyper_14_878_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_176_chunk r_145
                     ->  Seq Scan on compress_hyper_14_879_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_177_chunk r_146
                     ->  Seq Scan on compress_hyper_14_880_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_178_chunk r_147
                     ->  Seq Scan on compress_hyper_14_881_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_179_chunk r_148
                     ->  Seq Scan on compress_hyper_14_882_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_180_chunk r_149
                     ->  Seq Scan on compress_hyper_14_883_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_181_chunk r_150
                     ->  Seq Scan on compress_hyper_14_884_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_182_chunk r_151
                     ->  Seq Scan on compress_hyper_14_885_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_183_chunk r_152
                     ->  Seq Scan on compress_hyper_14_886_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_184_chunk r_153
                     ->  Seq Scan on compress_hyper_14_887_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_185_chunk r_154
                     ->  Seq Scan on compress_hyper_14_888_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_186_chunk r_155
                     ->  Seq Scan on compress_hyper_14_889_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_187_chunk r_156
                     ->  Seq Scan on compress_hyper_14_890_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_188_chunk r_157
                     ->  Seq Scan on compress_hyper_14_891_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_189_chunk r_158
                     ->  Seq Scan on compress_hyper_14_892_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_190_chunk r_159
                     ->  Seq Scan on compress_hyper_14_893_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_191_chunk r_160
                     ->  Seq Scan on compress_hyper_14_894_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_192_chunk r_161
                     ->  Seq Scan on compress_hyper_14_895_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_193_chunk r_162
                     ->  Seq Scan on compress_hyper_14_896_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_194_chunk r_163
                     ->  Seq Scan on compress_hyper_14_897_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_195_chunk r_164
                     ->  Seq Scan on compress_hyper_14_898_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_196_chunk r_165
                     ->  Seq Scan on compress_hyper_14_899_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_197_chunk r_166
                     ->  Seq Scan on compress_hyper_14_900_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_198_chunk r_167
                     ->  Seq Scan on compress_hyper_14_901_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_199_chunk r_168
                     ->  Seq Scan on compress_hyper_14_902_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_200_chunk r_169
                     ->  Seq Scan on compress_hyper_14_903_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_201_chunk r_170
                     ->  Seq Scan on compress_hyper_14_904_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_202_chunk r_171
                     ->  Seq Scan on compress_hyper_14_905_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_203_chunk r_172
                     ->  Seq Scan on compress_hyper_14_906_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_204_chunk r_173
                     ->  Seq Scan on compress_hyper_14_907_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_205_chunk r_174
                     ->  Seq Scan on compress_hyper_14_908_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_206_chunk r_175
                     ->  Seq Scan on compress_hyper_14_909_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_207_chunk r_176
                     ->  Seq Scan on compress_hyper_14_910_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_208_chunk r_177
                     ->  Seq Scan on compress_hyper_14_911_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_209_chunk r_178
                     ->  Seq Scan on compress_hyper_14_912_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_210_chunk r_179
                     ->  Seq Scan on compress_hyper_14_913_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_211_chunk r_180
                     ->  Seq Scan on compress_hyper_14_914_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_212_chunk r_181
                     ->  Seq Scan on compress_hyper_14_915_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_213_chunk r_182
                     ->  Seq Scan on compress_hyper_14_916_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_214_chunk r_183
                     ->  Seq Scan on compress_hyper_14_917_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_215_chunk r_184
                     ->  Seq Scan on compress_hyper_14_918_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_216_chunk r_185
                     ->  Seq Scan on compress_hyper_14_919_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_217_chunk r_186
                     ->  Seq Scan on compress_hyper_14_920_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_218_chunk r_187
                     ->  Seq Scan on compress_hyper_14_921_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_219_chunk r_188
                     ->  Seq Scan on compress_hyper_14_922_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_220_chunk r_189
                     ->  Seq Scan on compress_hyper_14_923_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_221_chunk r_190
                     ->  Seq Scan on compress_hyper_14_924_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_222_chunk r_191
                     ->  Seq Scan on compress_hyper_14_925_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_223_chunk r_192
                     ->  Seq Scan on compress_hyper_14_926_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_224_chunk r_193
                     ->  Seq Scan on compress_hyper_14_927_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_225_chunk r_194
                     ->  Seq Scan on compress_hyper_14_928_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_226_chunk r_195
                     ->  Seq Scan on compress_hyper_14_929_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_227_chunk r_196
                     ->  Seq Scan on compress_hyper_14_930_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_228_chunk r_197
                     ->  Seq Scan on compress_hyper_14_931_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_229_chunk r_198
                     ->  Seq Scan on compress_hyper_14_932_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_230_chunk r_199
                     ->  Seq Scan on compress_hyper_14_933_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_231_chunk r_200
                     ->  Seq Scan on compress_hyper_14_934_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_232_chunk r_201
                     ->  Seq Scan on compress_hyper_14_935_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_233_chunk r_202
                     ->  Seq Scan on compress_hyper_14_936_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_234_chunk r_203
                     ->  Seq Scan on compress_hyper_14_937_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_235_chunk r_204
                     ->  Seq Scan on compress_hyper_14_938_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_236_chunk r_205
                     ->  Seq Scan on compress_hyper_14_939_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_237_chunk r_206
                     ->  Seq Scan on compress_hyper_14_940_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_238_chunk r_207
                     ->  Seq Scan on compress_hyper_14_941_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_239_chunk r_208
                     ->  Seq Scan on compress_hyper_14_942_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_240_chunk r_209
                     ->  Seq Scan on compress_hyper_14_943_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_241_chunk r_210
                     ->  Seq Scan on compress_hyper_14_944_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_242_chunk r_211
                     ->  Seq Scan on compress_hyper_14_945_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_243_chunk r_212
                     ->  Seq Scan on compress_hyper_14_946_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_244_chunk r_213
                     ->  Seq Scan on compress_hyper_14_947_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_245_chunk r_214
                     ->  Seq Scan on compress_hyper_14_948_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_246_chunk r_215
                     ->  Seq Scan on compress_hyper_14_949_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_247_chunk r_216
                     ->  Seq Scan on compress_hyper_14_950_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_248_chunk r_217
                     ->  Seq Scan on compress_hyper_14_951_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_249_chunk r_218
                     ->  Seq Scan on compress_hyper_14_952_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_250_chunk r_219
                     ->  Seq Scan on compress_hyper_14_953_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_251_chunk r_220
                     ->  Seq Scan on compress_hyper_14_954_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_252_chunk r_221
                     ->  Seq Scan on compress_hyper_14_955_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_253_chunk r_222
                     ->  Seq Scan on compress_hyper_14_956_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_254_chunk r_223
                     ->  Seq Scan on compress_hyper_14_957_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_255_chunk r_224
                     ->  Seq Scan on compress_hyper_14_958_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_256_chunk r_225
                     ->  Seq Scan on compress_hyper_14_959_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_257_chunk r_226
                     ->  Seq Scan on compress_hyper_14_960_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_258_chunk r_227
                     ->  Seq Scan on compress_hyper_14_961_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_259_chunk r_228
                     ->  Seq Scan on compress_hyper_14_962_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_260_chunk r_229
                     ->  Seq Scan on compress_hyper_14_963_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_261_chunk r_230
                     ->  Seq Scan on compress_hyper_14_964_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_262_chunk r_231
                     ->  Seq Scan on compress_hyper_14_965_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_263_chunk r_232
                     ->  Seq Scan on compress_hyper_14_966_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_264_chunk r_233
                     ->  Seq Scan on compress_hyper_14_967_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_265_chunk r_234
                     ->  Seq Scan on compress_hyper_14_968_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_266_chunk r_235
                     ->  Seq Scan on compress_hyper_14_969_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_267_chunk r_236
                     ->  Seq Scan on compress_hyper_14_970_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_268_chunk r_237
                     ->  Seq Scan on compress_hyper_14_971_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_269_chunk r_238
                     ->  Seq Scan on compress_hyper_14_972_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_270_chunk r_239
                     ->  Seq Scan on compress_hyper_14_973_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_271_chunk r_240
                     ->  Seq Scan on compress_hyper_14_974_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_272_chunk r_241
                     ->  Seq Scan on compress_hyper_14_975_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_273_chunk r_242
                     ->  Seq Scan on compress_hyper_14_976_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_274_chunk r_243
                     ->  Seq Scan on compress_hyper_14_977_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_275_chunk r_244
                     ->  Seq Scan on compress_hyper_14_978_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_276_chunk r_245
                     ->  Seq Scan on compress_hyper_14_979_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_277_chunk r_246
                     ->  Seq Scan on compress_hyper_14_980_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_278_chunk r_247
                     ->  Seq Scan on compress_hyper_14_981_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_279_chunk r_248
                     ->  Seq Scan on compress_hyper_14_982_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_280_chunk r_249
                     ->  Seq Scan on compress_hyper_14_983_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_281_chunk r_250
                     ->  Seq Scan on compress_hyper_14_984_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_282_chunk r_251
                     ->  Seq Scan on compress_hyper_14_985_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_283_chunk r_252
                     ->  Seq Scan on compress_hyper_14_986_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_284_chunk r_253
                     ->  Seq Scan on compress_hyper_14_987_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_285_chunk r_254
                     ->  Seq Scan on compress_hyper_14_988_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_286_chunk r_255
                     ->  Seq Scan on compress_hyper_14_989_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_287_chunk r_256
                     ->  Seq Scan on compress_hyper_14_990_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_288_chunk r_257
                     ->  Seq Scan on compress_hyper_14_991_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_289_chunk r_258
                     ->  Seq Scan on compress_hyper_14_992_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_290_chunk r_259
                     ->  Seq Scan on compress_hyper_14_993_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_291_chunk r_260
                     ->  Seq Scan on compress_hyper_14_994_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_292_chunk r_261
                     ->  Seq Scan on compress_hyper_14_995_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_293_chunk r_262
                     ->  Seq Scan on compress_hyper_14_996_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_294_chunk r_263
                     ->  Seq Scan on compress_hyper_14_997_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_295_chunk r_264
                     ->  Seq Scan on compress_hyper_14_998_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_296_chunk r_265
                     ->  Seq Scan on compress_hyper_14_999_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_297_chunk r_266
                     ->  Seq Scan on compress_hyper_14_1000_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_298_chunk r_267
                     ->  Seq Scan on compress_hyper_14_1001_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_299_chunk r_268
                     ->  Seq Scan on compress_hyper_14_1002_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_300_chunk r_269
                     ->  Seq Scan on compress_hyper_14_1003_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_301_chunk r_270
                     ->  Seq Scan on compress_hyper_14_1004_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_302_chunk r_271
                     ->  Seq Scan on compress_hyper_14_1005_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_303_chunk r_272
                     ->  Seq Scan on compress_hyper_14_1006_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_304_chunk r_273
                     ->  Seq Scan on compress_hyper_14_1007_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_305_chunk r_274
                     ->  Seq Scan on compress_hyper_14_1008_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_306_chunk r_275
                     ->  Seq Scan on compress_hyper_14_1009_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_307_chunk r_276
                     ->  Seq Scan on compress_hyper_14_1010_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_308_chunk r_277
                     ->  Seq Scan on compress_hyper_14_1011_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_309_chunk r_278
                     ->  Seq Scan on compress_hyper_14_1012_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_310_chunk r_279
                     ->  Seq Scan on compress_hyper_14_1013_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_311_chunk r_280
                     ->  Seq Scan on compress_hyper_14_1014_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_312_chunk r_281
                     ->  Seq Scan on compress_hyper_14_1015_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_313_chunk r_282
                     ->  Seq Scan on compress_hyper_14_1016_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_314_chunk r_283
                     ->  Seq Scan on compress_hyper_14_1017_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_315_chunk r_284
                     ->  Seq Scan on compress_hyper_14_1018_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_316_chunk r_285
                     ->  Seq Scan on compress_hyper_14_1019_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_317_chunk r_286
                     ->  Seq Scan on compress_hyper_14_1020_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_318_chunk r_287
                     ->  Seq Scan on compress_hyper_14_1021_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_319_chunk r_288
                     ->  Seq Scan on compress_hyper_14_1022_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_320_chunk r_289
                     ->  Seq Scan on compress_hyper_14_1023_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_321_chunk r_290
                     ->  Seq Scan on compress_hyper_14_1024_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_322_chunk r_291
                     ->  Seq Scan on compress_hyper_14_1025_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_323_chunk r_292
                     ->  Seq Scan on compress_hyper_14_1026_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_324_chunk r_293
                     ->  Seq Scan on compress_hyper_14_1027_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_325_chunk r_294
                     ->  Seq Scan on compress_hyper_14_1028_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_326_chunk r_295
                     ->  Seq Scan on compress_hyper_14_1029_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_327_chunk r_296
                     ->  Seq Scan on compress_hyper_14_1030_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_328_chunk r_297
                     ->  Seq Scan on compress_hyper_14_1031_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_329_chunk r_298
                     ->  Seq Scan on compress_hyper_14_1032_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_330_chunk r_299
                     ->  Seq Scan on compress_hyper_14_1033_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_331_chunk r_300
                     ->  Seq Scan on compress_hyper_14_1034_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_332_chunk r_301
                     ->  Seq Scan on compress_hyper_14_1035_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_333_chunk r_302
                     ->  Seq Scan on compress_hyper_14_1036_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_334_chunk r_303
                     ->  Seq Scan on compress_hyper_14_1037_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_335_chunk r_304
                     ->  Seq Scan on compress_hyper_14_1038_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_336_chunk r_305
                     ->  Seq Scan on compress_hyper_14_1039_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_337_chunk r_306
                     ->  Seq Scan on compress_hyper_14_1040_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_338_chunk r_307
                     ->  Seq Scan on compress_hyper_14_1041_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_339_chunk r_308
                     ->  Seq Scan on compress_hyper_14_1042_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_340_chunk r_309
                     ->  Seq Scan on compress_hyper_14_1043_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_341_chunk r_310
                     ->  Seq Scan on compress_hyper_14_1044_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_342_chunk r_311
                     ->  Seq Scan on compress_hyper_14_1045_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_343_chunk r_312
                     ->  Seq Scan on compress_hyper_14_1046_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_344_chunk r_313
                     ->  Seq Scan on compress_hyper_14_1047_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_345_chunk r_314
                     ->  Seq Scan on compress_hyper_14_1048_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_346_chunk r_315
                     ->  Seq Scan on compress_hyper_14_1049_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_347_chunk r_316
                     ->  Seq Scan on compress_hyper_14_1050_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_348_chunk r_317
                     ->  Seq Scan on compress_hyper_14_1051_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_349_chunk r_318
                     ->  Seq Scan on compress_hyper_14_1052_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_350_chunk r_319
                     ->  Seq Scan on compress_hyper_14_1053_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_351_chunk r_320
                     ->  Seq Scan on compress_hyper_14_1054_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_352_chunk r_321
                     ->  Seq Scan on compress_hyper_14_1055_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_353_chunk r_322
                     ->  Seq Scan on compress_hyper_14_1056_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_354_chunk r_323
                     ->  Seq Scan on compress_hyper_14_1057_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_355_chunk r_324
                     ->  Seq Scan on compress_hyper_14_1058_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_356_chunk r_325
                     ->  Seq Scan on compress_hyper_14_1059_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_357_chunk r_326
                     ->  Seq Scan on compress_hyper_14_1060_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_358_chunk r_327
                     ->  Seq Scan on compress_hyper_14_1061_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_359_chunk r_328
                     ->  Seq Scan on compress_hyper_14_1062_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_360_chunk r_329
                     ->  Seq Scan on compress_hyper_14_1063_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_361_chunk r_330
                     ->  Seq Scan on compress_hyper_14_1064_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_362_chunk r_331
                     ->  Seq Scan on compress_hyper_14_1065_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_363_chunk r_332
                     ->  Seq Scan on compress_hyper_14_1066_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_364_chunk r_333
                     ->  Seq Scan on compress_hyper_14_1067_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_365_chunk r_334
                     ->  Seq Scan on compress_hyper_14_1068_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_366_chunk r_335
                     ->  Seq Scan on compress_hyper_14_1069_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_367_chunk r_336
                     ->  Seq Scan on compress_hyper_14_1070_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_368_chunk r_337
                     ->  Seq Scan on compress_hyper_14_1071_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_369_chunk r_338
                     ->  Seq Scan on compress_hyper_14_1072_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_370_chunk r_339
                     ->  Seq Scan on compress_hyper_14_1073_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_371_chunk r_340
                     ->  Seq Scan on compress_hyper_14_1074_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_372_chunk r_341
                     ->  Seq Scan on compress_hyper_14_1075_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_373_chunk r_342
                     ->  Seq Scan on compress_hyper_14_1076_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_374_chunk r_343
                     ->  Seq Scan on compress_hyper_14_1077_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_375_chunk r_344
                     ->  Seq Scan on compress_hyper_14_1078_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_376_chunk r_345
                     ->  Seq Scan on compress_hyper_14_1079_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_377_chunk r_346
                     ->  Seq Scan on compress_hyper_14_1080_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_378_chunk r_347
                     ->  Seq Scan on compress_hyper_14_1081_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_379_chunk r_348
                     ->  Seq Scan on compress_hyper_14_1082_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_380_chunk r_349
                     ->  Seq Scan on compress_hyper_14_1083_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_381_chunk r_350
                     ->  Seq Scan on compress_hyper_14_1084_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_382_chunk r_351
                     ->  Seq Scan on compress_hyper_14_1085_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_383_chunk r_352
                     ->  Seq Scan on compress_hyper_14_1086_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_384_chunk r_353
                     ->  Seq Scan on compress_hyper_14_1087_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_385_chunk r_354
                     ->  Seq Scan on compress_hyper_14_1088_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_386_chunk r_355
                     ->  Seq Scan on compress_hyper_14_1089_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_387_chunk r_356
                     ->  Seq Scan on compress_hyper_14_1090_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_388_chunk r_357
                     ->  Seq Scan on compress_hyper_14_1091_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_389_chunk r_358
                     ->  Seq Scan on compress_hyper_14_1092_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_390_chunk r_359
                     ->  Seq Scan on compress_hyper_14_1093_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_391_chunk r_360
                     ->  Seq Scan on compress_hyper_14_1094_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_392_chunk r_361
                     ->  Seq Scan on compress_hyper_14_1095_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_393_chunk r_362
                     ->  Seq Scan on compress_hyper_14_1096_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_394_chunk r_363
                     ->  Seq Scan on compress_hyper_14_1097_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_395_chunk r_364
                     ->  Seq Scan on compress_hyper_14_1098_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_396_chunk r_365
                     ->  Seq Scan on compress_hyper_14_1099_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_397_chunk r_366
                     ->  Seq Scan on compress_hyper_14_1100_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_398_chunk r_367
                     ->  Seq Scan on compress_hyper_14_1101_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_399_chunk r_368
                     ->  Seq Scan on compress_hyper_14_1102_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_400_chunk r_369
                     ->  Seq Scan on compress_hyper_14_1103_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_401_chunk r_370
                     ->  Seq Scan on compress_hyper_14_1104_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_402_chunk r_371
                     ->  Seq Scan on compress_hyper_14_1105_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_403_chunk r_372
                     ->  Seq Scan on compress_hyper_14_1106_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_404_chunk r_373
                     ->  Seq Scan on compress_hyper_14_1107_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_405_chunk r_374
                     ->  Seq Scan on compress_hyper_14_1108_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_406_chunk r_375
                     ->  Seq Scan on compress_hyper_14_1109_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_407_chunk r_376
                     ->  Seq Scan on compress_hyper_14_1110_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_408_chunk r_377
                     ->  Seq Scan on compress_hyper_14_1111_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_409_chunk r_378
                     ->  Seq Scan on compress_hyper_14_1112_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_410_chunk r_379
                     ->  Seq Scan on compress_hyper_14_1113_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_411_chunk r_380
                     ->  Seq Scan on compress_hyper_14_1114_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_412_chunk r_381
                     ->  Seq Scan on compress_hyper_14_1115_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_413_chunk r_382
                     ->  Seq Scan on compress_hyper_14_1116_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_414_chunk r_383
                     ->  Seq Scan on compress_hyper_14_1117_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_415_chunk r_384
                     ->  Seq Scan on compress_hyper_14_1118_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_416_chunk r_385
                     ->  Seq Scan on compress_hyper_14_1119_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_417_chunk r_386
                     ->  Seq Scan on compress_hyper_14_1120_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_418_chunk r_387
                     ->  Seq Scan on compress_hyper_14_1121_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_419_chunk r_388
                     ->  Seq Scan on compress_hyper_14_1122_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_420_chunk r_389
                     ->  Seq Scan on compress_hyper_14_1123_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_421_chunk r_390
                     ->  Seq Scan on compress_hyper_14_1124_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_422_chunk r_391
                     ->  Seq Scan on compress_hyper_14_1125_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_423_chunk r_392
                     ->  Seq Scan on compress_hyper_14_1126_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_424_chunk r_393
                     ->  Seq Scan on compress_hyper_14_1127_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_425_chunk r_394
                     ->  Seq Scan on compress_hyper_14_1128_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_426_chunk r_395
                     ->  Seq Scan on compress_hyper_14_1129_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_427_chunk r_396
                     ->  Seq Scan on compress_hyper_14_1130_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_428_chunk r_397
                     ->  Seq Scan on compress_hyper_14_1131_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_429_chunk r_398
                     ->  Seq Scan on compress_hyper_14_1132_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_430_chunk r_399
                     ->  Seq Scan on compress_hyper_14_1133_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_431_chunk r_400
                     ->  Seq Scan on compress_hyper_14_1134_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_432_chunk r_401
                     ->  Seq Scan on compress_hyper_14_1135_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_433_chunk r_402
                     ->  Seq Scan on compress_hyper_14_1136_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_434_chunk r_403
                     ->  Seq Scan on compress_hyper_14_1137_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_435_chunk r_404
                     ->  Seq Scan on compress_hyper_14_1138_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_436_chunk r_405
                     ->  Seq Scan on compress_hyper_14_1139_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_437_chunk r_406
                     ->  Seq Scan on compress_hyper_14_1140_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_438_chunk r_407
                     ->  Seq Scan on compress_hyper_14_1141_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_439_chunk r_408
                     ->  Seq Scan on compress_hyper_14_1142_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_440_chunk r_409
                     ->  Seq Scan on compress_hyper_14_1143_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_441_chunk r_410
                     ->  Seq Scan on compress_hyper_14_1144_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_442_chunk r_411
                     ->  Seq Scan on compress_hyper_14_1145_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_443_chunk r_412
                     ->  Seq Scan on compress_hyper_14_1146_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_444_chunk r_413
                     ->  Seq Scan on compress_hyper_14_1147_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_445_chunk r_414
                     ->  Seq Scan on compress_hyper_14_1148_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_446_chunk r_415
                     ->  Seq Scan on compress_hyper_14_1149_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_447_chunk r_416
                     ->  Seq Scan on compress_hyper_14_1150_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_448_chunk r_417
                     ->  Seq Scan on compress_hyper_14_1151_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_449_chunk r_418
                     ->  Seq Scan on compress_hyper_14_1152_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_450_chunk r_419
                     ->  Seq Scan on compress_hyper_14_1153_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_451_chunk r_420
                     ->  Seq Scan on compress_hyper_14_1154_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_452_chunk r_421
                     ->  Seq Scan on compress_hyper_14_1155_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_453_chunk r_422
                     ->  Seq Scan on compress_hyper_14_1156_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_454_chunk r_423
                     ->  Seq Scan on compress_hyper_14_1157_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_455_chunk r_424
                     ->  Seq Scan on compress_hyper_14_1158_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_456_chunk r_425
                     ->  Seq Scan on compress_hyper_14_1159_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_457_chunk r_426
                     ->  Seq Scan on compress_hyper_14_1160_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_458_chunk r_427
                     ->  Seq Scan on compress_hyper_14_1161_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_459_chunk r_428
                     ->  Seq Scan on compress_hyper_14_1162_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_460_chunk r_429
                     ->  Seq Scan on compress_hyper_14_1163_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_461_chunk r_430
                     ->  Seq Scan on compress_hyper_14_1164_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_462_chunk r_431
                     ->  Seq Scan on compress_hyper_14_1165_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_463_chunk r_432
                     ->  Seq Scan on compress_hyper_14_1166_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_464_chunk r_433
                     ->  Seq Scan on compress_hyper_14_1167_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_465_chunk r_434
                     ->  Seq Scan on compress_hyper_14_1168_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_466_chunk r_435
                     ->  Seq Scan on compress_hyper_14_1169_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_467_chunk r_436
                     ->  Seq Scan on compress_hyper_14_1170_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_468_chunk r_437
                     ->  Seq Scan on compress_hyper_14_1171_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_469_chunk r_438
                     ->  Seq Scan on compress_hyper_14_1172_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_470_chunk r_439
                     ->  Seq Scan on compress_hyper_14_1173_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_471_chunk r_440
                     ->  Seq Scan on compress_hyper_14_1174_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_472_chunk r_441
                     ->  Seq Scan on compress_hyper_14_1175_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_473_chunk r_442
                     ->  Seq Scan on compress_hyper_14_1176_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_474_chunk r_443
                     ->  Seq Scan on compress_hyper_14_1177_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_475_chunk r_444
                     ->  Seq Scan on compress_hyper_14_1178_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_476_chunk r_445
                     ->  Seq Scan on compress_hyper_14_1179_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_477_chunk r_446
                     ->  Seq Scan on compress_hyper_14_1180_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_478_chunk r_447
                     ->  Seq Scan on compress_hyper_14_1181_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_479_chunk r_448
                     ->  Seq Scan on compress_hyper_14_1182_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_480_chunk r_449
                     ->  Seq Scan on compress_hyper_14_1183_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_481_chunk r_450
                     ->  Seq Scan on compress_hyper_14_1184_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_482_chunk r_451
                     ->  Seq Scan on compress_hyper_14_1185_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_483_chunk r_452
                     ->  Seq Scan on compress_hyper_14_1186_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_484_chunk r_453
                     ->  Seq Scan on compress_hyper_14_1187_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_485_chunk r_454
                     ->  Seq Scan on compress_hyper_14_1188_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_486_chunk r_455
                     ->  Seq Scan on compress_hyper_14_1189_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_487_chunk r_456
                     ->  Seq Scan on compress_hyper_14_1190_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_488_chunk r_457
                     ->  Seq Scan on compress_hyper_14_1191_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_489_chunk r_458
                     ->  Seq Scan on compress_hyper_14_1192_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_490_chunk r_459
                     ->  Seq Scan on compress_hyper_14_1193_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_491_chunk r_460
                     ->  Seq Scan on compress_hyper_14_1194_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_492_chunk r_461
                     ->  Seq Scan on compress_hyper_14_1195_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_493_chunk r_462
                     ->  Seq Scan on compress_hyper_14_1196_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_494_chunk r_463
                     ->  Seq Scan on compress_hyper_14_1197_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_495_chunk r_464
                     ->  Seq Scan on compress_hyper_14_1198_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_496_chunk r_465
                     ->  Seq Scan on compress_hyper_14_1199_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_497_chunk r_466
                     ->  Seq Scan on compress_hyper_14_1200_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_498_chunk r_467
                     ->  Seq Scan on compress_hyper_14_1201_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_499_chunk r_468
                     ->  Seq Scan on compress_hyper_14_1202_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_500_chunk r_469
                     ->  Seq Scan on compress_hyper_14_1203_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_501_chunk r_470
                     ->  Seq Scan on compress_hyper_14_1204_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_502_chunk r_471
                     ->  Seq Scan on compress_hyper_14_1205_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_503_chunk r_472
                     ->  Seq Scan on compress_hyper_14_1206_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_504_chunk r_473
                     ->  Seq Scan on compress_hyper_14_1207_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_505_chunk r_474
                     ->  Seq Scan on compress_hyper_14_1208_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_506_chunk r_475
                     ->  Seq Scan on compress_hyper_14_1209_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_507_chunk r_476
                     ->  Seq Scan on compress_hyper_14_1210_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_508_chunk r_477
                     ->  Seq Scan on compress_hyper_14_1211_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_509_chunk r_478
                     ->  Seq Scan on compress_hyper_14_1212_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_510_chunk r_479
                     ->  Seq Scan on compress_hyper_14_1213_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_511_chunk r_480
                     ->  Seq Scan on compress_hyper_14_1214_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_512_chunk r_481
                     ->  Seq Scan on compress_hyper_14_1215_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_513_chunk r_482
                     ->  Seq Scan on compress_hyper_14_1216_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_514_chunk r_483
                     ->  Seq Scan on compress_hyper_14_1217_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_515_chunk r_484
                     ->  Seq Scan on compress_hyper_14_1218_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_516_chunk r_485
                     ->  Seq Scan on compress_hyper_14_1219_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_517_chunk r_486
                     ->  Seq Scan on compress_hyper_14_1220_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_518_chunk r_487
                     ->  Seq Scan on compress_hyper_14_1221_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_519_chunk r_488
                     ->  Seq Scan on compress_hyper_14_1222_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_520_chunk r_489
                     ->  Seq Scan on compress_hyper_14_1223_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_521_chunk r_490
                     ->  Seq Scan on compress_hyper_14_1224_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_522_chunk r_491
                     ->  Seq Scan on compress_hyper_14_1225_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_523_chunk r_492
                     ->  Seq Scan on compress_hyper_14_1226_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_524_chunk r_493
                     ->  Seq Scan on compress_hyper_14_1227_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_525_chunk r_494
                     ->  Seq Scan on compress_hyper_14_1228_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_526_chunk r_495
                     ->  Seq Scan on compress_hyper_14_1229_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_527_chunk r_496
                     ->  Seq Scan on compress_hyper_14_1230_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_528_chunk r_497
                     ->  Seq Scan on compress_hyper_14_1231_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_529_chunk r_498
                     ->  Seq Scan on compress_hyper_14_1232_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_530_chunk r_499
                     ->  Seq Scan on compress_hyper_14_1233_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_531_chunk r_500
                     ->  Seq Scan on compress_hyper_14_1234_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_532_chunk r_501
                     ->  Seq Scan on compress_hyper_14_1235_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_533_chunk r_502
                     ->  Seq Scan on compress_hyper_14_1236_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_534_chunk r_503
                     ->  Seq Scan on compress_hyper_14_1237_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_535_chunk r_504
                     ->  Seq Scan on compress_hyper_14_1238_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_536_chunk r_505
                     ->  Seq Scan on compress_hyper_14_1239_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_537_chunk r_506
                     ->  Seq Scan on compress_hyper_14_1240_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_538_chunk r_507
                     ->  Seq Scan on compress_hyper_14_1241_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_539_chunk r_508
                     ->  Seq Scan on compress_hyper_14_1242_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_540_chunk r_509
                     ->  Seq Scan on compress_hyper_14_1243_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_541_chunk r_510
                     ->  Seq Scan on compress_hyper_14_1244_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_542_chunk r_511
                     ->  Seq Scan on compress_hyper_14_1245_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_543_chunk r_512
                     ->  Seq Scan on compress_hyper_14_1246_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_544_chunk r_513
                     ->  Seq Scan on compress_hyper_14_1247_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_545_chunk r_514
                     ->  Seq Scan on compress_hyper_14_1248_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_546_chunk r_515
                     ->  Seq Scan on compress_hyper_14_1249_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_547_chunk r_516
                     ->  Seq Scan on compress_hyper_14_1250_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_548_chunk r_517
                     ->  Seq Scan on compress_hyper_14_1251_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_549_chunk r_518
                     ->  Seq Scan on compress_hyper_14_1252_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_550_chunk r_519
                     ->  Seq Scan on compress_hyper_14_1253_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_551_chunk r_520
                     ->  Seq Scan on compress_hyper_14_1254_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_552_chunk r_521
                     ->  Seq Scan on compress_hyper_14_1255_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_553_chunk r_522
                     ->  Seq Scan on compress_hyper_14_1256_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_554_chunk r_523
                     ->  Seq Scan on compress_hyper_14_1257_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_555_chunk r_524
                     ->  Seq Scan on compress_hyper_14_1258_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_556_chunk r_525
                     ->  Seq Scan on compress_hyper_14_1259_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_557_chunk r_526
                     ->  Seq Scan on compress_hyper_14_1260_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_558_chunk r_527
                     ->  Seq Scan on compress_hyper_14_1261_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_559_chunk r_528
                     ->  Seq Scan on compress_hyper_14_1262_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_560_chunk r_529
                     ->  Seq Scan on compress_hyper_14_1263_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_561_chunk r_530
                     ->  Seq Scan on compress_hyper_14_1264_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_562_chunk r_531
                     ->  Seq Scan on compress_hyper_14_1265_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_563_chunk r_532
                     ->  Seq Scan on compress_hyper_14_1266_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_564_chunk r_533
                     ->  Seq Scan on compress_hyper_14_1267_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_565_chunk r_534
                     ->  Seq Scan on compress_hyper_14_1268_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_566_chunk r_535
                     ->  Seq Scan on compress_hyper_14_1269_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_567_chunk r_536
                     ->  Seq Scan on compress_hyper_14_1270_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_568_chunk r_537
                     ->  Seq Scan on compress_hyper_14_1271_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_569_chunk r_538
                     ->  Seq Scan on compress_hyper_14_1272_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_570_chunk r_539
                     ->  Seq Scan on compress_hyper_14_1273_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_571_chunk r_540
                     ->  Seq Scan on compress_hyper_14_1274_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_572_chunk r_541
                     ->  Seq Scan on compress_hyper_14_1275_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_573_chunk r_542
                     ->  Seq Scan on compress_hyper_14_1276_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_574_chunk r_543
                     ->  Seq Scan on compress_hyper_14_1277_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_575_chunk r_544
                     ->  Seq Scan on compress_hyper_14_1278_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_576_chunk r_545
                     ->  Seq Scan on compress_hyper_14_1279_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_577_chunk r_546
                     ->  Seq Scan on compress_hyper_14_1280_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_578_chunk r_547
                     ->  Seq Scan on compress_hyper_14_1281_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_579_chunk r_548
                     ->  Seq Scan on compress_hyper_14_1282_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_580_chunk r_549
                     ->  Seq Scan on compress_hyper_14_1283_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_581_chunk r_550
                     ->  Seq Scan on compress_hyper_14_1284_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_582_chunk r_551
                     ->  Seq Scan on compress_hyper_14_1285_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_583_chunk r_552
                     ->  Seq Scan on compress_hyper_14_1286_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_584_chunk r_553
                     ->  Seq Scan on compress_hyper_14_1287_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_585_chunk r_554
                     ->  Seq Scan on compress_hyper_14_1288_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_586_chunk r_555
                     ->  Seq Scan on compress_hyper_14_1289_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_587_chunk r_556
                     ->  Seq Scan on compress_hyper_14_1290_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_588_chunk r_557
                     ->  Seq Scan on compress_hyper_14_1291_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_589_chunk r_558
                     ->  Seq Scan on compress_hyper_14_1292_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_590_chunk r_559
                     ->  Seq Scan on compress_hyper_14_1293_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_591_chunk r_560
                     ->  Seq Scan on compress_hyper_14_1294_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_592_chunk r_561
                     ->  Seq Scan on compress_hyper_14_1295_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_593_chunk r_562
                     ->  Seq Scan on compress_hyper_14_1296_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_594_chunk r_563
                     ->  Seq Scan on compress_hyper_14_1297_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_595_chunk r_564
                     ->  Seq Scan on compress_hyper_14_1298_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_596_chunk r_565
                     ->  Seq Scan on compress_hyper_14_1299_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_597_chunk r_566
                     ->  Seq Scan on compress_hyper_14_1300_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_598_chunk r_567
                     ->  Seq Scan on compress_hyper_14_1301_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_599_chunk r_568
                     ->  Seq Scan on compress_hyper_14_1302_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_600_chunk r_569
                     ->  Seq Scan on compress_hyper_14_1303_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_601_chunk r_570
                     ->  Seq Scan on compress_hyper_14_1304_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_602_chunk r_571
                     ->  Seq Scan on compress_hyper_14_1305_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_603_chunk r_572
                     ->  Seq Scan on compress_hyper_14_1306_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_604_chunk r_573
                     ->  Seq Scan on compress_hyper_14_1307_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_605_chunk r_574
                     ->  Seq Scan on compress_hyper_14_1308_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_606_chunk r_575
                     ->  Seq Scan on compress_hyper_14_1309_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_607_chunk r_576
                     ->  Seq Scan on compress_hyper_14_1310_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_608_chunk r_577
                     ->  Seq Scan on compress_hyper_14_1311_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_609_chunk r_578
                     ->  Seq Scan on compress_hyper_14_1312_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_610_chunk r_579
                     ->  Seq Scan on compress_hyper_14_1313_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_611_chunk r_580
                     ->  Seq Scan on compress_hyper_14_1314_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_612_chunk r_581
                     ->  Seq Scan on compress_hyper_14_1315_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_613_chunk r_582
                     ->  Seq Scan on compress_hyper_14_1316_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_614_chunk r_583
                     ->  Seq Scan on compress_hyper_14_1317_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_615_chunk r_584
                     ->  Seq Scan on compress_hyper_14_1318_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_616_chunk r_585
                     ->  Seq Scan on compress_hyper_14_1319_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_617_chunk r_586
                     ->  Seq Scan on compress_hyper_14_1320_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_618_chunk r_587
                     ->  Seq Scan on compress_hyper_14_1321_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_619_chunk r_588
                     ->  Seq Scan on compress_hyper_14_1322_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_620_chunk r_589
                     ->  Seq Scan on compress_hyper_14_1323_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_621_chunk r_590
                     ->  Seq Scan on compress_hyper_14_1324_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_622_chunk r_591
                     ->  Seq Scan on compress_hyper_14_1325_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_623_chunk r_592
                     ->  Seq Scan on compress_hyper_14_1326_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_624_chunk r_593
                     ->  Seq Scan on compress_hyper_14_1327_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_625_chunk r_594
                     ->  Seq Scan on compress_hyper_14_1328_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_626_chunk r_595
                     ->  Seq Scan on compress_hyper_14_1329_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_627_chunk r_596
                     ->  Seq Scan on compress_hyper_14_1330_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_628_chunk r_597
                     ->  Seq Scan on compress_hyper_14_1331_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_629_chunk r_598
                     ->  Seq Scan on compress_hyper_14_1332_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_630_chunk r_599
                     ->  Seq Scan on compress_hyper_14_1333_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_631_chunk r_600
                     ->  Seq Scan on compress_hyper_14_1334_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_632_chunk r_601
                     ->  Seq Scan on compress_hyper_14_1335_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_633_chunk r_602
                     ->  Seq Scan on compress_hyper_14_1336_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_634_chunk r_603
                     ->  Seq Scan on compress_hyper_14_1337_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_635_chunk r_604
                     ->  Seq Scan on compress_hyper_14_1338_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_636_chunk r_605
                     ->  Seq Scan on compress_hyper_14_1339_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_637_chunk r_606
                     ->  Seq Scan on compress_hyper_14_1340_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_638_chunk r_607
                     ->  Seq Scan on compress_hyper_14_1341_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_639_chunk r_608
                     ->  Seq Scan on compress_hyper_14_1342_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_640_chunk r_609
                     ->  Seq Scan on compress_hyper_14_1343_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_641_chunk r_610
                     ->  Seq Scan on compress_hyper_14_1344_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_642_chunk r_611
                     ->  Seq Scan on compress_hyper_14_1345_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_643_chunk r_612
                     ->  Seq Scan on compress_hyper_14_1346_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_644_chunk r_613
                     ->  Seq Scan on compress_hyper_14_1347_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_645_chunk r_614
                     ->  Seq Scan on compress_hyper_14_1348_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_646_chunk r_615
                     ->  Seq Scan on compress_hyper_14_1349_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_647_chunk r_616
                     ->  Seq Scan on compress_hyper_14_1350_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_648_chunk r_617
                     ->  Seq Scan on compress_hyper_14_1351_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_649_chunk r_618
                     ->  Seq Scan on compress_hyper_14_1352_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_650_chunk r_619
                     ->  Seq Scan on compress_hyper_14_1353_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_651_chunk r_620
                     ->  Seq Scan on compress_hyper_14_1354_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_652_chunk r_621
                     ->  Seq Scan on compress_hyper_14_1355_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_653_chunk r_622
                     ->  Seq Scan on compress_hyper_14_1356_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_654_chunk r_623
                     ->  Seq Scan on compress_hyper_14_1357_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_655_chunk r_624
                     ->  Seq Scan on compress_hyper_14_1358_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_656_chunk r_625
                     ->  Seq Scan on compress_hyper_14_1359_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_657_chunk r_626
                     ->  Seq Scan on compress_hyper_14_1360_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_658_chunk r_627
                     ->  Seq Scan on compress_hyper_14_1361_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_659_chunk r_628
                     ->  Seq Scan on compress_hyper_14_1362_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_660_chunk r_629
                     ->  Seq Scan on compress_hyper_14_1363_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_661_chunk r_630
                     ->  Seq Scan on compress_hyper_14_1364_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_662_chunk r_631
                     ->  Seq Scan on compress_hyper_14_1365_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_663_chunk r_632
                     ->  Seq Scan on compress_hyper_14_1366_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_664_chunk r_633
                     ->  Seq Scan on compress_hyper_14_1367_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_665_chunk r_634
                     ->  Seq Scan on compress_hyper_14_1368_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_666_chunk r_635
                     ->  Seq Scan on compress_hyper_14_1369_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_667_chunk r_636
                     ->  Seq Scan on compress_hyper_14_1370_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_668_chunk r_637
                     ->  Seq Scan on compress_hyper_14_1371_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_669_chunk r_638
                     ->  Seq Scan on compress_hyper_14_1372_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_670_chunk r_639
                     ->  Seq Scan on compress_hyper_14_1373_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_671_chunk r_640
                     ->  Seq Scan on compress_hyper_14_1374_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_672_chunk r_641
                     ->  Seq Scan on compress_hyper_14_1375_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_673_chunk r_642
                     ->  Seq Scan on compress_hyper_14_1376_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_674_chunk r_643
                     ->  Seq Scan on compress_hyper_14_1377_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_675_chunk r_644
                     ->  Seq Scan on compress_hyper_14_1378_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_676_chunk r_645
                     ->  Seq Scan on compress_hyper_14_1379_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_677_chunk r_646
                     ->  Seq Scan on compress_hyper_14_1380_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_678_chunk r_647
                     ->  Seq Scan on compress_hyper_14_1381_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_679_chunk r_648
                     ->  Seq Scan on compress_hyper_14_1382_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_680_chunk r_649
                     ->  Seq Scan on compress_hyper_14_1383_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_681_chunk r_650
                     ->  Seq Scan on compress_hyper_14_1384_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_682_chunk r_651
                     ->  Seq Scan on compress_hyper_14_1385_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_683_chunk r_652
                     ->  Seq Scan on compress_hyper_14_1386_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_684_chunk r_653
                     ->  Seq Scan on compress_hyper_14_1387_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_685_chunk r_654
                     ->  Seq Scan on compress_hyper_14_1388_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_686_chunk r_655
                     ->  Seq Scan on compress_hyper_14_1389_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_687_chunk r_656
                     ->  Seq Scan on compress_hyper_14_1390_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_688_chunk r_657
                     ->  Seq Scan on compress_hyper_14_1391_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_689_chunk r_658
                     ->  Seq Scan on compress_hyper_14_1392_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_690_chunk r_659
                     ->  Seq Scan on compress_hyper_14_1393_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_691_chunk r_660
                     ->  Seq Scan on compress_hyper_14_1394_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_692_chunk r_661
                     ->  Seq Scan on compress_hyper_14_1395_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_693_chunk r_662
                     ->  Seq Scan on compress_hyper_14_1396_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_694_chunk r_663
                     ->  Seq Scan on compress_hyper_14_1397_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_695_chunk r_664
                     ->  Seq Scan on compress_hyper_14_1398_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_696_chunk r_665
                     ->  Seq Scan on compress_hyper_14_1399_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_697_chunk r_666
                     ->  Seq Scan on compress_hyper_14_1400_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_698_chunk r_667
                     ->  Seq Scan on compress_hyper_14_1401_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_699_chunk r_668
                     ->  Seq Scan on compress_hyper_14_1402_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_700_chunk r_669
                     ->  Seq Scan on compress_hyper_14_1403_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_701_chunk r_670
                     ->  Seq Scan on compress_hyper_14_1404_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_702_chunk r_671
                     ->  Seq Scan on compress_hyper_14_1405_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_703_chunk r_672
                     ->  Seq Scan on compress_hyper_14_1406_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_704_chunk r_673
                     ->  Seq Scan on compress_hyper_14_1407_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_705_chunk r_674
                     ->  Seq Scan on compress_hyper_14_1408_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_706_chunk r_675
                     ->  Seq Scan on compress_hyper_14_1409_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_707_chunk r_676
                     ->  Seq Scan on compress_hyper_14_1410_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_708_chunk r_677
                     ->  Seq Scan on compress_hyper_14_1411_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_709_chunk r_678
                     ->  Seq Scan on compress_hyper_14_1412_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_710_chunk r_679
                     ->  Seq Scan on compress_hyper_14_1413_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_711_chunk r_680
                     ->  Seq Scan on compress_hyper_14_1414_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_712_chunk r_681
                     ->  Seq Scan on compress_hyper_14_1415_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_713_chunk r_682
                     ->  Seq Scan on compress_hyper_14_1416_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_714_chunk r_683
                     ->  Seq Scan on compress_hyper_14_1417_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_715_chunk r_684
                     ->  Seq Scan on compress_hyper_14_1418_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_716_chunk r_685
                     ->  Seq Scan on compress_hyper_14_1419_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_717_chunk r_686
                     ->  Seq Scan on compress_hyper_14_1420_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_718_chunk r_687
                     ->  Seq Scan on compress_hyper_14_1421_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_719_chunk r_688
                     ->  Seq Scan on compress_hyper_14_1422_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_720_chunk r_689
                     ->  Seq Scan on compress_hyper_14_1423_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_721_chunk r_690
                     ->  Seq Scan on compress_hyper_14_1424_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_722_chunk r_691
                     ->  Seq Scan on compress_hyper_14_1425_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_723_chunk r_692
                     ->  Seq Scan on compress_hyper_14_1426_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_724_chunk r_693
                     ->  Seq Scan on compress_hyper_14_1427_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_725_chunk r_694
                     ->  Seq Scan on compress_hyper_14_1428_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_726_chunk r_695
                     ->  Seq Scan on compress_hyper_14_1429_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_727_chunk r_696
                     ->  Seq Scan on compress_hyper_14_1430_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_728_chunk r_697
                     ->  Seq Scan on compress_hyper_14_1431_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_729_chunk r_698
                     ->  Seq Scan on compress_hyper_14_1432_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_730_chunk r_699
                     ->  Seq Scan on compress_hyper_14_1433_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_731_chunk r_700
                     ->  Seq Scan on compress_hyper_14_1434_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_732_chunk r_701
                     ->  Seq Scan on compress_hyper_14_1435_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_733_chunk r_702
                     ->  Seq Scan on compress_hyper_14_1436_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_13_734_chunk r_703
                     ->  Seq Scan on compress_hyper_14_1437_chunk
         ->  Hash
               ->  Seq Scan on tags t

-- run query with parallel enabled to ensure nothing is preventing parallel execution
-- this is just a sanity check, the result queries dont run with parallel disabled
SET max_parallel_workers_per_gather TO 4;
SET parallel_setup_cost = 0;
SET parallel_tuple_cost = 0;
SET min_parallel_table_scan_size TO '0';
EXPLAIN (buffers off, costs off) SELECT * FROM metrics ORDER BY time, device_id;
--- QUERY PLAN ---
 Gather Merge
   Workers Planned: 3
   ->  Sort
         Sort Key: metrics."time", metrics.device_id
         ->  Parallel Append
               ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk
                     ->  Parallel Seq Scan on compress_hyper_5_15_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk
                     ->  Parallel Seq Scan on compress_hyper_5_16_chunk
               ->  Parallel Seq Scan on _hyper_1_2_chunk

EXPLAIN (buffers off, costs off) SELECT time_bucket('10 minutes', time) bucket, avg(v0) avg_v0 FROM metrics GROUP BY bucket;
--- QUERY PLAN ---
 Finalize HashAggregate
   Group Key: (time_bucket('@ 10 mins'::interval, metrics."time"))
   ->  Gather
         Workers Planned: 3
         ->  Parallel Append
               ->  Partial HashAggregate
                     Group Key: time_bucket('@ 10 mins'::interval, _hyper_1_1_chunk."time")
                     ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk
                           ->  Parallel Seq Scan on compress_hyper_5_15_chunk
               ->  Partial HashAggregate
                     Group Key: time_bucket('@ 10 mins'::interval, _hyper_1_3_chunk."time")
                     ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk
                           ->  Parallel Seq Scan on compress_hyper_5_16_chunk
               ->  Partial HashAggregate
                     Group Key: time_bucket('@ 10 mins'::interval, _hyper_1_2_chunk."time")
                     ->  Parallel Seq Scan on _hyper_1_2_chunk

EXPLAIN (buffers off, costs off) SELECT * FROM metrics_space ORDER BY time, device_id;
--- QUERY PLAN ---
 Gather Merge
   Workers Planned: 4
   ->  Sort
         Sort Key: metrics_space."time", metrics_space.device_id
         ->  Parallel Append
               ->  Custom Scan (ColumnarScan) on _hyper_2_4_chunk
                     ->  Parallel Seq Scan on compress_hyper_6_17_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_2_6_chunk
                     ->  Parallel Seq Scan on compress_hyper_6_19_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk
                     ->  Parallel Seq Scan on compress_hyper_6_20_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_2_5_chunk
                     ->  Parallel Seq Scan on compress_hyper_6_18_chunk
               ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk
                     ->  Parallel Seq Scan on compress_hyper_6_21_chunk
               ->  Parallel Seq Scan on _hyper_2_8_chunk
               ->  Parallel Seq Scan on _hyper_2_7_chunk
               ->  Parallel Seq Scan on _hyper_2_9_chunk
               ->  Parallel Seq Scan on _hyper_2_12_chunk

RESET min_parallel_table_scan_size;
RESET parallel_setup_cost;
RESET parallel_tuple_cost;
SET enable_seqscan TO false;
-- should order compressed chunks using index
-- (we only EXPLAIN here b/c the resulting order is too inconsistent)
EXPLAIN (buffers off, costs off) SELECT * FROM metrics WHERE time > '2000-01-08' ORDER BY device_id;
--- QUERY PLAN ---
 Merge Append
   Sort Key: metrics.device_id
   ->  Sort
         Sort Key: _hyper_1_2_chunk.device_id
         ->  Index Scan using _hyper_1_2_chunk_metrics_time_idx on _hyper_1_2_chunk
               Index Cond: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk
         ->  Index Scan using compress_hyper_5_16_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_5_16_chunk

EXPLAIN (buffers off, costs off) SELECT * FROM metrics_space WHERE time > '2000-01-08' ORDER BY device_id;
--- QUERY PLAN ---
 Merge Append
   Sort Key: metrics_space.device_id
   ->  Index Scan Backward using _hyper_2_7_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_7_chunk
         Index Cond: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_2_8_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_8_chunk
         Index Cond: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_2_9_chunk_metrics_space_device_id_device_id_peer_v0_v1_2 on _hyper_2_9_chunk
         Index Cond: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Custom Scan (ColumnarScan) on _hyper_2_10_chunk
         Vectorized Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Index Scan using compress_hyper_6_20_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_20_chunk
               Index Cond: (_ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Custom Scan (ColumnarScan) on _hyper_2_11_chunk
         Vectorized Filter: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
         ->  Index Scan using compress_hyper_6_21_chunk_device_id_device_id_peer__ts_meta_idx on compress_hyper_6_21_chunk
               Index Cond: (_ts_meta_max_3 > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_2_12_chunk_metrics_space_device_id_device_id_peer_v0_v_2 on _hyper_2_12_chunk
         Index Cond: ("time" > 'Sat Jan 08 00:00:00 2000 PST'::timestamp with time zone)

SET enable_seqscan TO true;
-- diff compressed and uncompressed results
:DIFF_CMD
-- check hypertable detection in views
CREATE VIEW ht_view AS
SELECT *,
  0 AS res
FROM metrics
UNION ALL
SELECT *,
  1 AS res
FROM metrics;
CREATE FUNCTION ht_func() RETURNS SETOF metrics LANGUAGE SQL STABLE AS
$sql$
  SELECT time,
    device_id,
    device_id_peer,
    v0, v1, v2, v3
  FROM ht_view
  WHERE res = 0;
$sql$;
-- should have decompresschunk node
:PREFIX SELECT * FROM ht_func();
--- QUERY PLAN ---
 Append (actual rows=8640.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
         ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
   ->  Seq Scan on _hyper_1_2_chunk (actual rows=3360.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
         ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)

\c
SET enable_incremental_sort TO off;
-- plan should be identical to previous plan in fresh session
:PREFIX SELECT * FROM ht_func();
--- QUERY PLAN ---
 Append (actual rows=8640.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=3600.00 loops=1)
         ->  Seq Scan on compress_hyper_5_15_chunk (actual rows=5.00 loops=1)
   ->  Seq Scan on _hyper_1_2_chunk (actual rows=3360.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_1_3_chunk (actual rows=1680.00 loops=1)
         ->  Seq Scan on compress_hyper_5_16_chunk (actual rows=5.00 loops=1)

-- repro for core dump related to total_table_pages setting that get
-- adjusted during decompress path.
CREATE SEQUENCE vessel_id_seq
    INCREMENT 1
    START 1    MINVALUE 1
    MAXVALUE 9223372036854775807
    CACHE 1;
CREATE TABLE motion_table(
  id bigint NOT NULL DEFAULT nextval('vessel_id_seq'::regclass) ,
 datalogger_id     bigint                   ,
 vessel_id         bigint                   ,
 bus_id            smallint                 ,
 src_id            smallint                 ,
 dataloggertime    timestamp with time zone ,
 interval_s        real                     );
CREATE INDEX
motion_table_t2_datalogger_id_idx on motion_table (datalogger_id);
CREATE INDEX motion_table_t2_dataloggertime_idx on motion_table(dataloggertime DESC);
CREATE INDEX motion_table_t2_vessel_id_idx on motion_table(vessel_id);
SELECT create_hypertable( 'motion_table', 'dataloggertime', chunk_time_interval=> '7 days'::interval);
     create_hypertable      
----------------------------
 (15,public,motion_table,t)

--- do not modify the data. We need atleast this volume to reproduce issues with pages/tuple counts etc. ---
INSERT into motion_table(datalogger_id, vessel_id, bus_id, src_id,
   dataloggertime, interval_s)
SELECT 1, random(), random() , random() ,
       generate_series( '2020-01-02 10:00'::timestamp, '2020-01-10 10::00'::timestamp, '1 min'::interval), 1.1;
INSERT into motion_table(datalogger_id, vessel_id, bus_id, src_id,
   dataloggertime, interval_s)
SELECT 1, random(), 2, 3,
       generate_series( '2020-01-10 8:00'::timestamp, '2020-01-10 10::00'::timestamp, '1 min'::interval), 1.1;
ALTER TABLE motion_table SET ( timescaledb.compress,
        timescaledb.compress_segmentby = 'vessel_id, datalogger_id, bus_id, src_id' , timescaledb.compress_orderby = 'dataloggertime' );
--have 2 chunks --
SELECT COUNT(*)
FROM timescaledb_information.chunks
WHERE hypertable_name = 'motion_table';
 count 
-------
     2

-- compress only the first one ---
SELECT compress_chunk( chunk_table)
FROM ( SELECT chunk_schema || '.' || chunk_name as chunk_table
       FROM timescaledb_information.chunks
       WHERE hypertable_name = 'motion_table' ORDER BY range_start limit 1 ) q;
               compress_chunk               
--------------------------------------------
 _timescaledb_internal._hyper_15_1438_chunk

--call to decompress chunk on 1 of the chunks
SELECT count(*) from motion_table;
 count 
-------
 11642

--END of test for page settings
CREATE TABLE repro(time timestamptz NOT NULL, device_id text, room_id text NOT NULL, score_type int NOT NULL, algorithm_version text NOT NULL, adjusted_score float NOT NULL);
SELECT create_hypertable('repro','time');
  create_hypertable  
---------------------
 (17,public,repro,t)

ALTER TABLE repro SET (
  timescaledb.compress,
  timescaledb.compress_segmentby = 'device_id, room_id, score_type, algorithm_version',
  timescaledb.compress_orderby='"time" DESC'
);
SELECT _timescaledb_functions.create_chunk('repro','{"time": [1717632000000000,1718236800000000]}');
                                                create_chunk                                                 
-------------------------------------------------------------------------------------------------------------
 (1441,17,_timescaledb_internal,_hyper_17_1441_chunk,r,"{""time"": [1717632000000000, 1718236800000000]}",t)

select compress_chunk(show_chunks('repro'));
               compress_chunk               
--------------------------------------------
 _timescaledb_internal._hyper_17_1441_chunk

select from repro where room_id = 'foo' order by device_id, algorithm_version, score_type, time desc;
--

