-- 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.
SELECT
       format('include/%s_query.sql', :'TEST_BASE_NAME') as "TEST_QUERY_NAME",
       format('%s/shared/results/%s_results_unoptimized.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNOPTIMIZED",
       format('%s/shared/results/%s_results_uncompressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNCOMPRESSED",
       format('%s/shared/results/%s_results_compressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED"
\gset
SELECT format('\! diff -u --label "Uncompressed results" --label "Compressed results" %s %s', :'TEST_RESULTS_UNCOMPRESSED', :'TEST_RESULTS_COMPRESSED') as "DIFF_CMD"
\gset
-- get EXPLAIN output for all variations
\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 work_mem TO '64MB';
-- In the following test cases, we test that certain indexes are used. By using the
-- timescaledb.enable_decompression_sorted_merge optimization, we are pushing a sort node
-- below the DecompressChunk node, which operates on the batches. This could lead to flaky
-- tests because the input data is small and PostgreSQL switches from IndexScans to
-- SequentialScans. Disable the optimization for the following tests to ensure we have
-- stable query plans in all CI environments.
SET timescaledb.enable_decompression_sorted_merge TO 'off';
SET max_parallel_workers_per_gather TO '0';
-- disable incremental sort to avoid flaky results
SET enable_incremental_sort TO 'off';
-- disable memoize node to avoid flaky results
SET enable_memoize TO 'off';
\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.
-- test prepared statements
-- executor startup exclusion with no chunks excluded
PREPARE prep AS
SELECT time
FROM :TEST_TABLE
WHERE time < now()
  AND device_id = 1
ORDER BY time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 0
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 0
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 0
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 0
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 0
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < now()))

DEALLOCATE prep;
-- executor startup exclusion with chunks excluded
PREPARE prep AS
SELECT time
FROM :TEST_TABLE
WHERE time < '2000-01-10'::text::timestamptz
  AND device_id = 1
ORDER BY time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 1
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 1
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 1
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 1
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 1
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))

DEALLOCATE prep;
-- runtime exclusion with LATERAL and 2 hypertables
SET enable_seqscan TO false;
PREPARE prep AS
SELECT m1.time,
  m2.time
FROM :TEST_TABLE m1
  LEFT JOIN LATERAL (
    SELECT time
    FROM :TEST_TABLE m2
    WHERE m1.time = m2.time
    LIMIT 1) m2 ON TRUE
WHERE device_id = 2
ORDER BY m1.time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_2 (never executed)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_3 (never executed)
                     Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 2
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_3 (never executed)
                           Index Cond: ("time" = m1."time")

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_2 (never executed)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_3 (never executed)
                     Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 2
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_3 (never executed)
                           Index Cond: ("time" = m1."time")

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_2 (never executed)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_3 (never executed)
                     Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 2
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_3 (never executed)
                           Index Cond: ("time" = m1."time")

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_2 (never executed)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_3 (never executed)
                     Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 2
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_3 (never executed)
                           Index Cond: ("time" = m1."time")

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_2 (never executed)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_device_id_time_idx on _hyper_X_X_chunk m1_3 (never executed)
                     Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 2
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_2 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk m2_3 (never executed)
                           Index Cond: ("time" = m1."time")

DEALLOCATE prep;
RESET enable_seqscan;
-- executor startup exclusion with subquery
PREPARE prep AS
SELECT time
FROM (
  SELECT time
  FROM :TEST_TABLE
  WHERE time < '2000-01-10'::text::timestamptz
  ORDER BY time
  LIMIT 100) m;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 1
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 1
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 1
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 1
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=100.00 loops=1)
         Order: metrics."time"
         Chunks excluded during startup: 1
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Index Only Scan Backward using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

DEALLOCATE prep;
-- test constraint exclusion for subqueries with ConstraintAwareAppend
SET timescaledb.enable_chunk_append TO FALSE;
PREPARE prep AS
SELECT device_id,
  time
FROM (
  SELECT device_id,
    time
  FROM :TEST_TABLE
  WHERE time < '2000-01-10'::text::timestamptz
  ORDER BY device_id,
    time
  LIMIT 100) m;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Sort (actual rows=100.00 loops=1)
         Sort Key: metrics.device_id, metrics."time"
         Sort Method: top-N heapsort 
         ->  Custom Scan (ConstraintAwareAppend) (actual rows=33590.00 loops=1)
               Hypertable: metrics
               Chunks excluded during startup: 1
               ->  Append (actual rows=33590.00 loops=1)
                     ->  Seq Scan on _hyper_X_X_chunk (actual rows=17990.00 loops=1)
                           Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=15600.00 loops=1)
                           Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Sort (actual rows=100.00 loops=1)
         Sort Key: metrics.device_id, metrics."time"
         Sort Method: top-N heapsort 
         ->  Custom Scan (ConstraintAwareAppend) (actual rows=33590.00 loops=1)
               Hypertable: metrics
               Chunks excluded during startup: 1
               ->  Append (actual rows=33590.00 loops=1)
                     ->  Seq Scan on _hyper_X_X_chunk (actual rows=17990.00 loops=1)
                           Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=15600.00 loops=1)
                           Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Sort (actual rows=100.00 loops=1)
         Sort Key: metrics.device_id, metrics."time"
         Sort Method: top-N heapsort 
         ->  Custom Scan (ConstraintAwareAppend) (actual rows=33590.00 loops=1)
               Hypertable: metrics
               Chunks excluded during startup: 1
               ->  Append (actual rows=33590.00 loops=1)
                     ->  Seq Scan on _hyper_X_X_chunk (actual rows=17990.00 loops=1)
                           Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=15600.00 loops=1)
                           Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Sort (actual rows=100.00 loops=1)
         Sort Key: metrics.device_id, metrics."time"
         Sort Method: top-N heapsort 
         ->  Custom Scan (ConstraintAwareAppend) (actual rows=33590.00 loops=1)
               Hypertable: metrics
               Chunks excluded during startup: 1
               ->  Append (actual rows=33590.00 loops=1)
                     ->  Seq Scan on _hyper_X_X_chunk (actual rows=17990.00 loops=1)
                           Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=15600.00 loops=1)
                           Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Sort (actual rows=100.00 loops=1)
         Sort Key: metrics.device_id, metrics."time"
         Sort Method: top-N heapsort 
         ->  Custom Scan (ConstraintAwareAppend) (actual rows=33590.00 loops=1)
               Hypertable: metrics
               Chunks excluded during startup: 1
               ->  Append (actual rows=33590.00 loops=1)
                     ->  Seq Scan on _hyper_X_X_chunk (actual rows=17990.00 loops=1)
                           Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=15600.00 loops=1)
                           Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

DEALLOCATE prep;
RESET timescaledb.enable_chunk_append;
-- test prepared statement with params and generic plan
SET plan_cache_mode TO force_generic_plan;
PREPARE prep(timestamptz) AS SELECT device_id, time FROM :TEST_TABLE WHERE time = $1 ORDER BY device_id, time;
:PREFIX EXECUTE prep('2000-01-01 23:42');
--- QUERY PLAN ---
 Sort (actual rows=5.00 loops=1)
   Sort Key: metrics.device_id
   Sort Method: quicksort 
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=5.00 loops=1)
         Chunks excluded during startup: 2
         ->  Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=5.00 loops=1)
               Index Cond: ("time" = $1)

:PREFIX EXECUTE prep('2000-01-10 23:42');
--- QUERY PLAN ---
 Sort (actual rows=5.00 loops=1)
   Sort Key: metrics.device_id
   Sort Method: quicksort 
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=5.00 loops=1)
         Chunks excluded during startup: 2
         ->  Index Scan using _hyper_X_X_chunk_metrics_time_idx on _hyper_X_X_chunk (actual rows=5.00 loops=1)
               Index Cond: ("time" = $1)

:PREFIX EXECUTE prep(now());
--- QUERY PLAN ---
 Sort (actual rows=0.00 loops=1)
   Sort Key: metrics.device_id
   Sort Method: quicksort 
   ->  Custom Scan (ChunkAppend) on metrics (actual rows=0.00 loops=1)
         Chunks excluded during startup: 3

DEALLOCATE prep;
RESET plan_cache_mode;
\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.
-- test prepared statements
-- executor startup exclusion with no chunks excluded
PREPARE prep AS
SELECT time
FROM :TEST_TABLE
WHERE time < now()
  AND device_id = 1
ORDER BY time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         Chunks excluded during startup: 0
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         Chunks excluded during startup: 0
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         Chunks excluded during startup: 0
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         Chunks excluded during startup: 0
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         Chunks excluded during startup: 0
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < now())
               Filter: (device_id = 1)

DEALLOCATE prep;
-- executor startup exclusion with chunks excluded
PREPARE prep AS
SELECT time
FROM :TEST_TABLE
WHERE time < '2000-01-10'::text::timestamptz
  AND device_id = 1
ORDER BY time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         Chunks excluded during startup: 1
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               Filter: (device_id = 1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         Chunks excluded during startup: 1
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               Filter: (device_id = 1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         Chunks excluded during startup: 1
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               Filter: (device_id = 1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         Chunks excluded during startup: 1
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               Filter: (device_id = 1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         Chunks excluded during startup: 1
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               Filter: (device_id = 1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               Filter: (device_id = 1)

DEALLOCATE prep;
-- runtime exclusion with LATERAL and 2 hypertables
SET enable_seqscan TO false;
PREPARE prep AS
SELECT m1.time,
  m2.time
FROM :TEST_TABLE m1
  LEFT JOIN LATERAL (
    SELECT time
    FROM :TEST_TABLE m2
    WHERE m1.time = m2.time
    LIMIT 1) m2 ON TRUE
WHERE device_id = 2
ORDER BY m1.time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_2 (never executed)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_3 (never executed)
                     Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 6
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_2 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_3 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_4 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_5 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_6 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_7 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_8 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_9 (never executed)
                           Index Cond: ("time" = m1."time")

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_2 (never executed)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_3 (never executed)
                     Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 6
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_2 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_3 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_4 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_5 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_6 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_7 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_8 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_9 (never executed)
                           Index Cond: ("time" = m1."time")

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_2 (never executed)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_3 (never executed)
                     Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 6
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_2 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_3 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_4 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_5 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_6 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_7 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_8 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_9 (never executed)
                           Index Cond: ("time" = m1."time")

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_2 (never executed)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_3 (never executed)
                     Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 6
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_2 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_3 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_4 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_5 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_6 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_7 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_8 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_9 (never executed)
                           Index Cond: ("time" = m1."time")

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_2 (never executed)
                     Index Cond: (device_id = 2)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk m1_3 (never executed)
                     Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_space m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 6
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_2 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_3 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_4 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_5 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_6 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_7 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_8 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk m2_9 (never executed)
                           Index Cond: ("time" = m1."time")

DEALLOCATE prep;
RESET enable_seqscan;
-- executor startup exclusion with subquery
PREPARE prep AS
SELECT time
FROM (
  SELECT time
  FROM :TEST_TABLE
  WHERE time < '2000-01-10'::text::timestamptz
  ORDER BY time
  LIMIT 100) m;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=60.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=60.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=60.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=60.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=100.00 loops=1)
         Order: metrics_space."time"
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=60.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (never executed)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

DEALLOCATE prep;
-- test constraint exclusion for subqueries with ConstraintAwareAppend
SET timescaledb.enable_chunk_append TO FALSE;
PREPARE prep AS
SELECT device_id,
  time
FROM (
  SELECT device_id,
    time
  FROM :TEST_TABLE
  WHERE time < '2000-01-10'::text::timestamptz
  ORDER BY device_id,
    time
  LIMIT 100) m;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_space
         Chunks excluded during startup: 3
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space.device_id, metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_space
         Chunks excluded during startup: 3
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space.device_id, metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_space
         Chunks excluded during startup: 3
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space.device_id, metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_space
         Chunks excluded during startup: 3
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space.device_id, metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_space
         Chunks excluded during startup: 3
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space.device_id, metrics_space."time"
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_space_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

DEALLOCATE prep;
RESET timescaledb.enable_chunk_append;
-- test prepared statement with params and generic plan
SET plan_cache_mode TO force_generic_plan;
PREPARE prep(timestamptz) AS SELECT device_id, time FROM :TEST_TABLE WHERE time = $1 ORDER BY device_id, time;
:PREFIX EXECUTE prep('2000-01-01 23:42');
--- QUERY PLAN ---
 Sort (actual rows=5.00 loops=1)
   Sort Key: metrics_space.device_id
   Sort Method: quicksort 
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=5.00 loops=1)
         Chunks excluded during startup: 6
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
               Index Cond: ("time" = $1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=3.00 loops=1)
               Index Cond: ("time" = $1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
               Index Cond: ("time" = $1)

:PREFIX EXECUTE prep('2000-01-10 23:42');
--- QUERY PLAN ---
 Sort (actual rows=5.00 loops=1)
   Sort Key: metrics_space.device_id
   Sort Method: quicksort 
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=5.00 loops=1)
         Chunks excluded during startup: 6
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
               Index Cond: ("time" = $1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=3.00 loops=1)
               Index Cond: ("time" = $1)
         ->  Index Scan using _hyper_X_X_chunk_metrics_space_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
               Index Cond: ("time" = $1)

:PREFIX EXECUTE prep(now());
--- QUERY PLAN ---
 Sort (actual rows=0.00 loops=1)
   Sort Key: metrics_space.device_id
   Sort Method: quicksort 
   ->  Custom Scan (ChunkAppend) on metrics_space (actual rows=0.00 loops=1)
         Chunks excluded during startup: 9

DEALLOCATE prep;
RESET plan_cache_mode;
\set TEST_TABLE 'metrics_compressed'
\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.
-- test prepared statements
-- executor startup exclusion with no chunks excluded
PREPARE prep AS
SELECT time
FROM :TEST_TABLE
WHERE time < now()
  AND device_id = 1
ORDER BY time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Vectorized Filter: ("time" < now())
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=2.00 loops=1)
                                 Filter: ((device_id = 1) AND (_ts_meta_min_1 < now()))
                                 Rows Removed by Filter: 16
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Vectorized Filter: ("time" < now())
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=2.00 loops=1)
                                 Filter: ((device_id = 1) AND (_ts_meta_min_1 < now()))
                                 Rows Removed by Filter: 16
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Vectorized Filter: ("time" < now())
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=2.00 loops=1)
                                 Filter: ((device_id = 1) AND (_ts_meta_min_1 < now()))
                                 Rows Removed by Filter: 16
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Vectorized Filter: ("time" < now())
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=2.00 loops=1)
                                 Filter: ((device_id = 1) AND (_ts_meta_min_1 < now()))
                                 Rows Removed by Filter: 16
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Vectorized Filter: ("time" < now())
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=2.00 loops=1)
                                 Filter: ((device_id = 1) AND (_ts_meta_min_1 < now()))
                                 Rows Removed by Filter: 16
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ((device_id = 1) AND ("time" < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))

DEALLOCATE prep;
-- executor startup exclusion with chunks excluded
PREPARE prep AS
SELECT time
FROM :TEST_TABLE
WHERE time < '2000-01-10'::text::timestamptz
  AND device_id = 1
ORDER BY time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=2.00 loops=1)
                                 Filter: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))
                                 Rows Removed by Filter: 16
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=2.00 loops=1)
                                 Filter: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))
                                 Rows Removed by Filter: 16
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=2.00 loops=1)
                                 Filter: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))
                                 Rows Removed by Filter: 16
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=2.00 loops=1)
                                 Filter: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))
                                 Rows Removed by Filter: 16
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: (device_id = 1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=2.00 loops=1)
                                 Filter: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))
                                 Rows Removed by Filter: 16
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ((device_id = 1) AND ("time" < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))

DEALLOCATE prep;
-- runtime exclusion with LATERAL and 2 hypertables
SET enable_seqscan TO false;
PREPARE prep AS
SELECT m1.time,
  m2.time
FROM :TEST_TABLE m1
  LEFT JOIN LATERAL (
    SELECT time
    FROM :TEST_TABLE m2
    WHERE m1.time = m2.time
    LIMIT 1) m2 ON TRUE
WHERE device_id = 2
ORDER BY m1.time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_compressed m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Merge Append (actual rows=100.00 loops=1)
                     Sort Key: m1."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                           Filter: (device_id = 2)
                           ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                                 Index Cond: (device_id = 2)
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=0.00 loops=1)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_2 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_3 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_compressed m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 2
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Filter: (m1."time" = "time")
                           Rows Removed by Filter: 548
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (actual rows=1.00 loops=100)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_time_idx on _hyper_X_X_chunk m2_1 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_2 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_3 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_compressed m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Merge Append (actual rows=100.00 loops=1)
                     Sort Key: m1."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                           Filter: (device_id = 2)
                           ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                                 Index Cond: (device_id = 2)
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=0.00 loops=1)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_2 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_3 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_compressed m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 2
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Filter: (m1."time" = "time")
                           Rows Removed by Filter: 548
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (actual rows=1.00 loops=100)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_time_idx on _hyper_X_X_chunk m2_1 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_2 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_3 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_compressed m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Merge Append (actual rows=100.00 loops=1)
                     Sort Key: m1."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                           Filter: (device_id = 2)
                           ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                                 Index Cond: (device_id = 2)
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=0.00 loops=1)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_2 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_3 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_compressed m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 2
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Filter: (m1."time" = "time")
                           Rows Removed by Filter: 548
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (actual rows=1.00 loops=100)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_time_idx on _hyper_X_X_chunk m2_1 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_2 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_3 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_compressed m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Merge Append (actual rows=100.00 loops=1)
                     Sort Key: m1."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                           Filter: (device_id = 2)
                           ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                                 Index Cond: (device_id = 2)
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=0.00 loops=1)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_2 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_3 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_compressed m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 2
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Filter: (m1."time" = "time")
                           Rows Removed by Filter: 548
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (actual rows=1.00 loops=100)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_time_idx on _hyper_X_X_chunk m2_1 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_2 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_3 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_compressed m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Merge Append (actual rows=100.00 loops=1)
                     Sort Key: m1."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                           Filter: (device_id = 2)
                           ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                                 Index Cond: (device_id = 2)
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk m1_1 (actual rows=0.00 loops=1)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_2 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_3 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_compressed m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 2
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Filter: (m1."time" = "time")
                           Rows Removed by Filter: 548
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (actual rows=1.00 loops=100)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_time_idx on _hyper_X_X_chunk m2_1 (never executed)
                           Index Cond: ("time" = m1."time")
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_2 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_3 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))

DEALLOCATE prep;
RESET enable_seqscan;
-- executor startup exclusion with subquery
PREPARE prep AS
SELECT time
FROM (
  SELECT time
  FROM :TEST_TABLE
  WHERE time < '2000-01-10'::text::timestamptz
  ORDER BY time
  LIMIT 100) m;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Sort (actual rows=80.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=16392.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=18.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Sort (never executed)
               Sort Key: _hyper_X_X_chunk."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Seq Scan on compress_hyper_X_X_chunk (never executed)
                           Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Sort (actual rows=80.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=16392.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=18.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Sort (never executed)
               Sort Key: _hyper_X_X_chunk."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Seq Scan on compress_hyper_X_X_chunk (never executed)
                           Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Sort (actual rows=80.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=16392.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=18.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Sort (never executed)
               Sort Key: _hyper_X_X_chunk."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Seq Scan on compress_hyper_X_X_chunk (never executed)
                           Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Sort (actual rows=80.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=16392.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=18.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Sort (never executed)
               Sort Key: _hyper_X_X_chunk."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Seq Scan on compress_hyper_X_X_chunk (never executed)
                           Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_compressed (actual rows=100.00 loops=1)
         Order: metrics_compressed."time"
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed."time"
               ->  Sort (actual rows=80.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=16392.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=18.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_time_idx on _hyper_X_X_chunk (actual rows=21.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Sort (never executed)
               Sort Key: _hyper_X_X_chunk."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Seq Scan on compress_hyper_X_X_chunk (never executed)
                           Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

DEALLOCATE prep;
-- test constraint exclusion for subqueries with ConstraintAwareAppend
SET timescaledb.enable_chunk_append TO FALSE;
PREPARE prep AS
SELECT device_id,
  time
FROM (
  SELECT device_id,
    time
  FROM :TEST_TABLE
  WHERE time < '2000-01-10'::text::timestamptz
  ORDER BY device_id,
    time
  LIMIT 100) m;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_compressed
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed.device_id, metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=18.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=25.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
                                 Rows Removed by Filter: 5

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_compressed
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed.device_id, metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=18.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=25.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
                                 Rows Removed by Filter: 5

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_compressed
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed.device_id, metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=18.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=25.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
                                 Rows Removed by Filter: 5

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_compressed
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed.device_id, metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=18.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=25.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
                                 Rows Removed by Filter: 5

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_compressed
         Chunks excluded during startup: 1
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_compressed.device_id, metrics_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=18.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=25.00 loops=1)
                                 Filter: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
                                 Rows Removed by Filter: 5

DEALLOCATE prep;
RESET timescaledb.enable_chunk_append;
-- test prepared statement with params and generic plan
SET plan_cache_mode TO force_generic_plan;
PREPARE prep(timestamptz) AS SELECT device_id, time FROM :TEST_TABLE WHERE time = $1 ORDER BY device_id, time;
:PREFIX EXECUTE prep('2000-01-01 23:42');
--- QUERY PLAN ---
 Merge Append (actual rows=5.00 loops=1)
   Sort Key: metrics_compressed.device_id
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=4.00 loops=1)
         Vectorized Filter: ("time" = $1)
         Rows Removed by Filter: 3996
         ->  Sort (actual rows=4.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 14
   ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=1.00 loops=1)
         Index Cond: ("time" = $1)
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 30
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 30

:PREFIX EXECUTE prep('2000-01-10 23:42');
--- QUERY PLAN ---
 Merge Append (actual rows=5.00 loops=1)
   Sort Key: metrics_compressed.device_id
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 18
   ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Index Cond: ("time" = $1)
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=5.00 loops=1)
         Vectorized Filter: ("time" = $1)
         Rows Removed by Filter: 4995
         ->  Sort (actual rows=5.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=5.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 25
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 30

:PREFIX EXECUTE prep(now());
--- QUERY PLAN ---
 Merge Append (actual rows=0.00 loops=1)
   Sort Key: metrics_compressed.device_id
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 18
   ->  Index Only Scan using _hyper_X_X_chunk_metrics_compressed_device_id_time_idx on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Index Cond: ("time" = $1)
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 30
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 30

DEALLOCATE prep;
RESET plan_cache_mode;
\set TEST_TABLE 'metrics_space_compressed'
\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.
-- test prepared statements
-- executor startup exclusion with no chunks excluded
PREPARE prep AS
SELECT time
FROM :TEST_TABLE
WHERE time < now()
  AND device_id = 1
ORDER BY time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         Chunks excluded during startup: 0
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         Chunks excluded during startup: 0
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         Chunks excluded during startup: 0
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         Chunks excluded during startup: 0
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         Chunks excluded during startup: 0
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < now())
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < now()))

DEALLOCATE prep;
-- executor startup exclusion with chunks excluded
PREPARE prep AS
SELECT time
FROM :TEST_TABLE
WHERE time < '2000-01-10'::text::timestamptz
  AND device_id = 1
ORDER BY time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         Chunks excluded during startup: 1
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         Chunks excluded during startup: 1
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         Chunks excluded during startup: 1
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         Chunks excluded during startup: 1
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         Chunks excluded during startup: 1
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))
         ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
               Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                     Index Cond: ((device_id = 1) AND (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone))

DEALLOCATE prep;
-- runtime exclusion with LATERAL and 2 hypertables
SET enable_seqscan TO false;
PREPARE prep AS
SELECT m1.time,
  m2.time
FROM :TEST_TABLE m1
  LEFT JOIN LATERAL (
    SELECT time
    FROM :TEST_TABLE m2
    WHERE m1.time = m2.time
    LIMIT 1) m2 ON TRUE
WHERE device_id = 2
ORDER BY m1.time
LIMIT 100;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space_compressed m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_2 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_3 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_space_compressed m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 6
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Filter: (m1."time" = "time")
                           Rows Removed by Filter: 548
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=100)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_2 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_3 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_4 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_5 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_6 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_7 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_8 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_9 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space_compressed m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_2 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_3 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_space_compressed m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 6
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Filter: (m1."time" = "time")
                           Rows Removed by Filter: 548
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=100)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_2 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_3 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_4 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_5 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_6 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_7 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_8 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_9 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space_compressed m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_2 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_3 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_space_compressed m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 6
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Filter: (m1."time" = "time")
                           Rows Removed by Filter: 548
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=100)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_2 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_3 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_4 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_5 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_6 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_7 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_8 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_9 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space_compressed m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_2 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_3 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_space_compressed m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 6
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Filter: (m1."time" = "time")
                           Rows Removed by Filter: 548
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=100)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_2 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_3 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_4 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_5 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_6 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_7 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_8 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_9 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Nested Loop Left Join (actual rows=100.00 loops=1)
         ->  Custom Scan (ChunkAppend) on metrics_space_compressed m1 (actual rows=100.00 loops=1)
               Order: m1."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_1 (actual rows=100.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_2 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m1_3 (never executed)
                     ->  Index Scan Backward using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                           Index Cond: (device_id = 2)
         ->  Limit (actual rows=1.00 loops=100)
               ->  Custom Scan (ChunkAppend) on metrics_space_compressed m2 (actual rows=1.00 loops=100)
                     Chunks excluded during runtime: 6
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_1 (actual rows=1.00 loops=100)
                           Filter: (m1."time" = "time")
                           Rows Removed by Filter: 548
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=1.00 loops=100)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_2 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_3 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_4 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_5 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_6 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_7 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_8 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk compress_hyper_X_X_chunk_1 (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk m2_9 (never executed)
                           Filter: (m1."time" = "time")
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: ((_ts_meta_min_1 <= m1."time") AND (_ts_meta_max_1 >= m1."time"))

DEALLOCATE prep;
RESET enable_seqscan;
-- executor startup exclusion with subquery
PREPARE prep AS
SELECT time
FROM (
  SELECT time
  FROM :TEST_TABLE
  WHERE time < '2000-01-10'::text::timestamptz
  ORDER BY time
  LIMIT 100) m;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (actual rows=21.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3598.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (actual rows=60.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=10794.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=12.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (actual rows=21.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3598.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (actual rows=21.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3598.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (actual rows=60.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=10794.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=12.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (actual rows=21.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3598.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (actual rows=21.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3598.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (actual rows=60.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=10794.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=12.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (actual rows=21.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3598.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (actual rows=21.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3598.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (actual rows=60.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=10794.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=12.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (actual rows=21.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3598.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ChunkAppend) on metrics_space_compressed (actual rows=100.00 loops=1)
         Order: metrics_space_compressed."time"
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (actual rows=21.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3598.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (actual rows=60.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=10794.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=12.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (actual rows=21.00 loops=1)
                     Sort Key: _hyper_X_X_chunk."time"
                     Sort Method: top-N heapsort 
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3598.00 loops=1)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Merge Append (never executed)
               Sort Key: metrics_space_compressed."time"
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Sort (never executed)
                     Sort Key: _hyper_X_X_chunk."time"
                     ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (never executed)
                           Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (never executed)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

DEALLOCATE prep;
-- test constraint exclusion for subqueries with ConstraintAwareAppend
SET timescaledb.enable_chunk_append TO FALSE;
PREPARE prep AS
SELECT device_id,
  time
FROM (
  SELECT device_id,
    time
  FROM :TEST_TABLE
  WHERE time < '2000-01-10'::text::timestamptz
  ORDER BY device_id,
    time
  LIMIT 100) m;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_space_compressed
         Chunks excluded during startup: 3
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space_compressed.device_id, metrics_space_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=12.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=15.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_space_compressed
         Chunks excluded during startup: 3
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space_compressed.device_id, metrics_space_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=12.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=15.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_space_compressed
         Chunks excluded during startup: 3
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space_compressed.device_id, metrics_space_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=12.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=15.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_space_compressed
         Chunks excluded during startup: 3
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space_compressed.device_id, metrics_space_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=12.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=15.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Limit (actual rows=100.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=100.00 loops=1)
         Hypertable: metrics_space_compressed
         Chunks excluded during startup: 3
         ->  Merge Append (actual rows=100.00 loops=1)
               Sort Key: metrics_space_compressed.device_id, metrics_space_compressed."time"
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=100.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=12.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=4.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=15.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
                     ->  Sort (actual rows=1.00 loops=1)
                           Sort Key: compress_hyper_X_X_chunk.device_id, compress_hyper_X_X_chunk._ts_meta_min_1, compress_hyper_X_X_chunk._ts_meta_max_1
                           Sort Method: quicksort 
                           ->  Index Scan using compress_hyper_X_X_chunk_device_id__ts_meta_min_1__ts_meta_idx on compress_hyper_X_X_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (_ts_meta_min_1 < ('2000-01-10'::cstring)::timestamp with time zone)

DEALLOCATE prep;
RESET timescaledb.enable_chunk_append;
-- test prepared statement with params and generic plan
SET plan_cache_mode TO force_generic_plan;
PREPARE prep(timestamptz) AS SELECT device_id, time FROM :TEST_TABLE WHERE time = $1 ORDER BY device_id, time;
:PREFIX EXECUTE prep('2000-01-01 23:42');
--- QUERY PLAN ---
 Merge Append (actual rows=5.00 loops=1)
   Sort Key: metrics_space_compressed.device_id
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
         Vectorized Filter: ("time" = $1)
         Rows Removed by Filter: 999
         ->  Sort (actual rows=1.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 3
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3.00 loops=1)
         Vectorized Filter: ("time" = $1)
         Rows Removed by Filter: 2997
         ->  Sort (actual rows=3.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=3.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 9
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
         Vectorized Filter: ("time" = $1)
         Rows Removed by Filter: 999
         ->  Sort (actual rows=1.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 3
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 6
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 18
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 6
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 6
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 18
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 6

:PREFIX EXECUTE prep('2000-01-10 23:42');
--- QUERY PLAN ---
 Merge Append (actual rows=5.00 loops=1)
   Sort Key: metrics_space_compressed.device_id
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 4
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 12
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 4
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
         Vectorized Filter: ("time" = $1)
         Rows Removed by Filter: 999
         ->  Sort (actual rows=1.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 5
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=3.00 loops=1)
         Vectorized Filter: ("time" = $1)
         Rows Removed by Filter: 2997
         ->  Sort (actual rows=3.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=3.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 15
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=1.00 loops=1)
         Vectorized Filter: ("time" = $1)
         Rows Removed by Filter: 999
         ->  Sort (actual rows=1.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=1.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 5
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 6
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 18
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 6

:PREFIX EXECUTE prep(now());
--- QUERY PLAN ---
 Merge Append (actual rows=0.00 loops=1)
   Sort Key: metrics_space_compressed.device_id
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 4
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 12
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 4
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 6
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 18
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 6
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 6
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 18
   ->  Custom Scan (ColumnarScan) on _hyper_X_X_chunk (actual rows=0.00 loops=1)
         Vectorized Filter: ("time" = $1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: compress_hyper_X_X_chunk.device_id
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_X_X_chunk (actual rows=0.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= $1) AND (_ts_meta_max_1 >= $1))
                     Rows Removed by Filter: 6

DEALLOCATE prep;
RESET plan_cache_mode;
-- get results for all the queries
-- run queries on uncompressed hypertable and store result
\set PREFIX ''
\set PREFIX_VERBOSE ''
\set ECHO none
