-- 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.
-- need superuser to modify statistics
\c :TEST_DBNAME :ROLE_SUPERUSER
\ir include/skip_scan_load.sql
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
CREATE TABLE skip_scan(time int, dev int, dev_name text, val int);
INSERT INTO skip_scan SELECT t, d, 'device_' || d::text, t*d FROM generate_series(1, 1000) t, generate_series(1, 10) d;
INSERT INTO skip_scan VALUES (NULL, 0, -1, NULL), (0, NULL, -1, NULL);
INSERT INTO skip_scan(time,dev,dev_name,val) SELECT t, NULL, NULL, NULL FROM generate_series(0, 999, 50) t;
ANALYZE skip_scan;
CREATE TABLE skip_scan_nulls(time int);
CREATE INDEX ON skip_scan_nulls(time);
INSERT INTO skip_scan_nulls SELECT NULL FROM generate_series(1,100);
ANALYZE skip_scan_nulls;
-- create hypertable with different physical layouts in the chunks
CREATE TABLE skip_scan_ht(f1 int, f2 int, f3 int, time int NOT NULL, dev int, dev_name text, val int);
SELECT create_hypertable('skip_scan_ht', 'time', chunk_time_interval => 250, create_default_indexes => false);
     create_hypertable     
---------------------------
 (1,public,skip_scan_ht,t)

INSERT INTO skip_scan_ht(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(0, 249) t, generate_series(1, 10) d;
ALTER TABLE skip_scan_ht DROP COLUMN f1;
INSERT INTO skip_scan_ht(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(250, 499) t, generate_series(1, 10) d;
ALTER TABLE skip_scan_ht DROP COLUMN f2;
INSERT INTO skip_scan_ht(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(500, 749) t, generate_series(1, 10) d;
ALTER TABLE skip_scan_ht DROP COLUMN f3;
INSERT INTO skip_scan_ht(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(750, 999) t, generate_series(1, 10) d;
INSERT INTO skip_scan_ht(time,dev,dev_name,val) SELECT t, NULL, NULL, NULL FROM generate_series(0, 999, 50) t;
ANALYZE skip_scan_ht;
ALTER TABLE skip_scan_ht SET (timescaledb.compress,timescaledb.compress_orderby='time desc', timescaledb.compress_segmentby='dev');
-- create compressed hypertable with different physical layouts in the chunks
CREATE TABLE skip_scan_htc(f1 int, f2 int, f3 int, time int NOT NULL, dev int, dev_name text, val int);
SELECT create_hypertable('skip_scan_htc', 'time', chunk_time_interval => 250, create_default_indexes => false);
     create_hypertable      
----------------------------
 (3,public,skip_scan_htc,t)

ALTER TABLE skip_scan_htc SET (timescaledb.compress, timescaledb.compress_orderby='time desc', timescaledb.compress_segmentby='dev');
INSERT INTO skip_scan_htc(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(0, 249) t, generate_series(1, 10) d;
ALTER TABLE skip_scan_htc DROP COLUMN f1;
INSERT INTO skip_scan_htc(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(250, 499) t, generate_series(1, 10) d;
ALTER TABLE skip_scan_htc DROP COLUMN f2;
INSERT INTO skip_scan_htc(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(500, 749) t, generate_series(1, 10) d;
ALTER TABLE skip_scan_htc DROP COLUMN f3;
INSERT INTO skip_scan_htc(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(750, 999) t, generate_series(1, 10) d;
INSERT INTO skip_scan_htc(time,dev,dev_name,val) SELECT t, NULL, NULL, NULL FROM generate_series(0, 999, 50) t;
ANALYZE skip_scan_htc;
CREATE TABLE skip_scan_insert(time int, dev int, dev_name text, val int, query text);
CREATE OR REPLACE FUNCTION int_func_immutable() RETURNS int LANGUAGE SQL IMMUTABLE SECURITY DEFINER AS $$SELECT 1; $$;
CREATE OR REPLACE FUNCTION int_func_stable() RETURNS int LANGUAGE SQL STABLE SECURITY DEFINER AS $$ SELECT 2; $$;
CREATE OR REPLACE FUNCTION int_func_volatile() RETURNS int LANGUAGE SQL VOLATILE SECURITY DEFINER AS $$ SELECT 3; $$;
CREATE OR REPLACE FUNCTION inta_func_immutable() RETURNS int[] LANGUAGE SQL IMMUTABLE SECURITY DEFINER AS $$ SELECT ARRAY[1,2,3]; $$;
CREATE OR REPLACE FUNCTION inta_func_stable() RETURNS int[] LANGUAGE SQL STABLE SECURITY DEFINER AS $$ SELECT ARRAY[2,3,4]; $$;
CREATE OR REPLACE FUNCTION inta_func_volatile() RETURNS int[] LANGUAGE SQL VOLATILE SECURITY DEFINER AS $$ SELECT ARRAY[3,4,5]; $$;
-- adjust statistics so we get skipscan plans
UPDATE pg_statistic SET stadistinct=1, stanullfrac=0.5 WHERE starelid='skip_scan'::regclass;
UPDATE pg_statistic SET stadistinct=1, stanullfrac=0.5 WHERE starelid='skip_scan_nulls'::regclass;
UPDATE pg_statistic SET stadistinct=1, stanullfrac=0.5 WHERE starelid='skip_scan_ht'::regclass;
UPDATE pg_statistic SET stadistinct=1, stanullfrac=0.5 WHERE starelid IN (select inhrelid from pg_inherits where inhparent='skip_scan_ht'::regclass);
UPDATE pg_statistic SET stadistinct=1, stanullfrac=0.5 WHERE starelid='skip_scan_htc'::regclass;
UPDATE pg_statistic SET stadistinct=1, stanullfrac=0.5 WHERE starelid IN (select inhrelid from pg_inherits where inhparent='skip_scan_htc'::regclass);
-- Turn off autovacuum to not trigger new vacuums that restores the
-- adjusted statistics
alter table skip_scan set (autovacuum_enabled = off);
alter table skip_scan_nulls set (autovacuum_enabled = off);
alter table skip_scan_ht set (autovacuum_enabled = off);
alter table skip_scan_htc set (autovacuum_enabled = off);
-- create compressed hypertable with different physical layouts in the compressed chunks
CREATE TABLE skip_scan_htcl(f1 int, f2 int, f3 int, time int NOT NULL, dev int, dev_name text, val int);
SELECT create_hypertable('skip_scan_htcl', 'time', chunk_time_interval => 250, create_default_indexes => false);
      create_hypertable      
-----------------------------
 (5,public,skip_scan_htcl,t)

ALTER TABLE skip_scan_htcl SET (timescaledb.compress, timescaledb.compress_orderby='time desc', timescaledb.compress_segmentby='dev');
INSERT INTO skip_scan_htcl(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(0, 249) t, generate_series(1, 10) d;
-- Make sure 1st compressed chunk has columns which will be dropped later, it also doesn't have NULLs
SELECT compress_chunk(ch) FROM show_chunks('skip_scan_htcl') ch;
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_5_9_chunk

ALTER TABLE skip_scan_htcl DROP COLUMN f1;
INSERT INTO skip_scan_htcl(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(250, 499) t, generate_series(1, 10) d;
ALTER TABLE skip_scan_htcl DROP COLUMN f2;
INSERT INTO skip_scan_htcl(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(500, 749) t, generate_series(1, 10) d;
ALTER TABLE skip_scan_htcl DROP COLUMN f3;
INSERT INTO skip_scan_htcl(time,dev,dev_name,val) SELECT t, d, 'device_' || d::text, random() FROM generate_series(750, 999) t, generate_series(1, 10) d;
INSERT INTO skip_scan_htcl(time,dev,dev_name,val) SELECT t, NULL, NULL, NULL FROM generate_series(0, 999, 50) t;
-- The rest of the compressed chunks do not have dropped columns
-- compressed chunks #2 and #3 have attnos out of sync with uncompressed chunks
SELECT compress_chunk(ch) FROM show_chunks('skip_scan_htcl') ch order by 1 desc limit 3;
             compress_chunk              
-----------------------------------------
 _timescaledb_internal._hyper_5_13_chunk
 _timescaledb_internal._hyper_5_12_chunk
 _timescaledb_internal._hyper_5_11_chunk

ANALYZE skip_scan_htcl;
-- adjust statistics so we get skipscan plans
UPDATE pg_statistic SET stadistinct=1, stanullfrac=0.5 WHERE starelid='skip_scan_htcl'::regclass;
UPDATE pg_statistic SET stadistinct=1, stanullfrac=0.5 WHERE starelid IN (select inhrelid from pg_inherits where inhparent='skip_scan_htcl'::regclass);
-- Turn off autovacuum to not trigger new vacuums that restores the
-- adjusted statistics
alter table skip_scan_htcl set (autovacuum_enabled = off);
-- we want to run with analyze here so we can see counts in the nodes
\set PREFIX 'EXPLAIN (analyze, buffers off, costs off, timing off, summary off)'
\set TABLE skip_scan
\ir include/skip_scan_query.sql
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
-- canary for result diff
SELECT current_setting('timescaledb.enable_skipscan') AS enable_skipscan;
 enable_skipscan 
-----------------
 on

-- test different index configurations
-- no index so we cant do SkipScan
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=12.00 loops=1)
   Sort Key: dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=12.00 loops=1)
         Group Key: dev
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

-- NULLS LAST index on dev
CREATE INDEX skip_scan_idx_dev_nulls_last ON :TABLE(dev);
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_dev_nulls_last on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev DESC;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan Backward using skip_scan_idx_dev_nulls_last on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev < NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_dev_nulls_last on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev > NULL::integer)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE dev IS NOT NULL ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_dev_nulls_last on skip_scan (actual rows=11.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))

DROP INDEX skip_scan_idx_dev_nulls_last;
-- NULLS FIRST index on dev
CREATE INDEX skip_scan_idx_dev_nulls_first ON :TABLE(dev NULLS FIRST);
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev NULLS FIRST;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_dev_nulls_first on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev NULLS FIRST;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_dev_nulls_first on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev > NULL::integer)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE dev IS NOT NULL ORDER BY dev NULLS FIRST;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_dev_nulls_first on skip_scan (actual rows=11.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))

DROP INDEX skip_scan_idx_dev_nulls_first;
-- multicolumn index with dev as leading column
CREATE INDEX skip_scan_idx_dev_time_idx ON :TABLE(dev, time);
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_dev_time_idx on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_dev_time_idx on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev DESC, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan Backward using skip_scan_idx_dev_time_idx on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev < NULL::integer)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE dev IS NOT NULL ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_dev_time_idx on skip_scan (actual rows=11.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))

DROP INDEX skip_scan_idx_dev_time_idx;
-- multicolumn index with dev as non-leading column
CREATE INDEX skip_scan_idx_time_dev_idx ON :TABLE(time, dev);
:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE time = 100 ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_time_dev_idx on skip_scan (actual rows=11.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer))

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time = 100;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_time_dev_idx on skip_scan (actual rows=11.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer))

-- Test not-NULL mode
:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE time = 100 AND dev IS NOT NULL ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=10.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=10.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_time_dev_idx on skip_scan (actual rows=10.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer) AND (dev IS NOT NULL))

DROP INDEX skip_scan_idx_time_dev_idx;
-- hash index is not ordered so can't use skipscan
CREATE INDEX skip_scan_idx_hash ON :TABLE USING hash(dev_name);
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE dev_name IN ('device_1','device_2') ORDER BY dev_name;
--- QUERY PLAN ---
 Sort (actual rows=2.00 loops=1)
   Sort Key: dev_name
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=2.00 loops=1)
         Group Key: dev_name
         ->  Bitmap Heap Scan on skip_scan (actual rows=2000.00 loops=1)
               Recheck Cond: (dev_name = ANY ('{device_1,device_2}'::text[]))
               Heap Blocks: exact=13
               ->  Bitmap Index Scan on skip_scan_idx_hash (actual rows=2000.00 loops=1)
                     Index Cond: (dev_name = ANY ('{device_1,device_2}'::text[]))

DROP INDEX skip_scan_idx_hash;
-- expression indexes
-- currently not supported by skipscan
CREATE INDEX skip_scan_expr_idx ON :TABLE((dev % 3));
:PREFIX SELECT DISTINCT dev%3 FROM :TABLE ORDER BY dev%3;
--- QUERY PLAN ---
 Sort (actual rows=4.00 loops=1)
   Sort Key: ((dev % 3))
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=4.00 loops=1)
         Group Key: (dev % 3)
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev%3) dev FROM :TABLE ORDER BY dev%3;
--- QUERY PLAN ---
 Unique (actual rows=4.00 loops=1)
   ->  Index Scan using skip_scan_expr_idx on skip_scan (actual rows=10022.00 loops=1)

DROP INDEX skip_scan_expr_idx;
CREATE INDEX ON :TABLE(dev_name);
-- Tests for #8107: accounting for scanning most of the input due to non-index quals
-- Non-index qual, no tuples match: SeqScan preferred
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE val < 0 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Sort (actual rows=0.00 loops=1)
         Sort Key: dev_name
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=0.00 loops=1)
               Filter: (val < 0)
               Rows Removed by Filter: 10022

-- Highly selective non-index qual, have to scan many tuples to match: SeqScan preferred
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE time = 100 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Sort (actual rows=11.00 loops=1)
         Sort Key: dev_name
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=11.00 loops=1)
               Filter: ("time" = 100)
               Rows Removed by Filter: 10011

-- Same but a combo of non-index quals
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE time = 100 and dev = 1 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Sort (actual rows=1.00 loops=1)
         Sort Key: dev_name
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=1.00 loops=1)
               Filter: (("time" = 100) AND (dev = 1))
               Rows Removed by Filter: 10021

-- Highly selective index qual: less tuples to scan for low-selective non-index qual, can choose SkipScan
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE dev_name IS NULL and dev = 1 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=0.00 loops=1)
         ->  Index Scan using skip_scan_dev_name_idx on skip_scan (actual rows=0.00 loops=1)
               Index Cond: (dev_name IS NULL)
               Filter: (dev = 1)
               Rows Removed by Filter: 20

CREATE INDEX ON :TABLE(dev);
-- RowCompareExpr where some args are not in the index:
-- we extract lossy "dev >=5" index condition which is strict and doesn't allow NULLs
SET timescaledb.debug_skip_scan_info TO true;
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE (dev, time) > (5,100);
psql:include/skip_scan_query.sql:74: INFO:  SkipScan used on skip_scan_dev_idx(dev NOT NULL)
--- QUERY PLAN ---
 Unique (actual rows=6.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=6.00 loops=1)
         ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=6.00 loops=1)
               Index Cond: (dev >= 5)
               Filter: (ROW(dev, "time") > ROW(5, 100))
               Rows Removed by Filter: 100

RESET timescaledb.debug_skip_scan_info;
CREATE INDEX ON :TABLE(dev, time);
CREATE INDEX ON :TABLE(time,dev);
CREATE INDEX ON :TABLE(time,dev,val);
\qecho basic DISTINCT queries on :TABLE
basic DISTINCT queries on skip_scan
:PREFIX SELECT DISTINCT dev, 'q1_1' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT dev_name, 'q1_2' FROM :TABLE ORDER BY dev_name;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT dev, 'q1_3', NULL FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

\qecho stable expression in targetlist on :TABLE
stable expression in targetlist on skip_scan
:PREFIX SELECT DISTINCT dev, 'q1_4', length(md5(now()::text)) FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT dev_name, 'q1_5', length(md5(now()::text)) FROM :TABLE ORDER BY dev_name;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

-- volatile expression in targetlist
:PREFIX SELECT DISTINCT dev, 'q1_6', length(md5(random()::text)) FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Sort (actual rows=10022.00 loops=1)
         Sort Key: dev, (length(md5((random())::text)))
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT DISTINCT dev_name, 'q1_7', length(md5(random()::text)) FROM :TABLE ORDER BY dev_name;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Sort (actual rows=10022.00 loops=1)
         Sort Key: dev_name, (length(md5((random())::text)))
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

-- queries without skipscan because distinct is not limited to specific column
:PREFIX SELECT DISTINCT * FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=10022.00 loops=1)
   Sort Key: dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=10022.00 loops=1)
         Group Key: dev, "time", dev_name, val
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT DISTINCT *, 'q1_9' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=10022.00 loops=1)
   Sort Key: dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=10022.00 loops=1)
         Group Key: dev, "time", dev_name, val, 'q1_9'::text
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT DISTINCT dev, time, 'q1_10' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=10021.00 loops=1)
   Sort Key: dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=10021.00 loops=1)
         Group Key: dev, "time", 'q1_10'::text
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT DISTINCT dev, NULL, 'q1_11' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

-- distinct on expressions not supported
:PREFIX SELECT DISTINCT time_bucket(10,time), 'q1_12' FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=102.00 loops=1)
   Group Key: time_bucket(10, "time"), 'q1_12'::text
   ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT DISTINCT length(dev_name), 'q1_13' FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=4.00 loops=1)
   Group Key: length(dev_name), 'q1_13'::text
   ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT DISTINCT 3*time, 'q1_14' FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=1002.00 loops=1)
   Group Key: (3 * "time"), 'q1_14'::text
   ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT DISTINCT 'Device ' || dev_name FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=12.00 loops=1)
   Group Key: ('Device '::text || dev_name)
   ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

-- DISTINCT ON queries
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_2' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_3', NULL FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_4', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_5', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) *, 'q2_7' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, time, 'q2_8' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, NULL, 'q2_9' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) time, 'q2_10' FROM :TABLE ORDER by dev, time;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, tableoid::regclass, 'q2_11' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_immutable(), 'q2_12' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_stable(), 'q2_13' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_volatile(), 'q2_14' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

-- DISTINCT ON queries on TEXT column
:PREFIX SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev_name > NULL::text)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE WHERE dev_name IS NOT NULL;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=11.00 loops=1)
               Index Cond: ((dev_name > NULL::text) AND (dev_name IS NOT NULL))

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_2' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_3', NULL FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_4', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_5', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) * FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) *, 'q3_7' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, time, 'q3_8' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, NULL, 'q3_9' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) time, 'q3_10' FROM :TABLE ORDER by dev_name, time;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Sort (actual rows=10022.00 loops=1)
         Sort Key: dev_name, "time"
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, tableoid::regclass, 'q3_11' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name::varchar) dev_name::varchar FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) dev, int_func_immutable(), 'q3_13' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev, int_func_stable(), 'q3_14' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev, int_func_volatile(), 'q3_15' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)

\qecho DISTINCT with wholerow var
DISTINCT with wholerow var
:PREFIX SELECT DISTINCT ON (dev) :TABLE FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)

-- should not use SkipScan since we only support SkipScan on single-column distinct
:PREFIX SELECT DISTINCT :TABLE FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=10022.00 loops=1)
   Group Key: skip_scan.*
   ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

\qecho LIMIT queries on :TABLE
LIMIT queries on skip_scan
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=3.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=3.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev DESC, time DESC LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=3.00 loops=1)
               ->  Index Only Scan Backward using skip_scan_dev_time_idx on skip_scan (actual rows=3.00 loops=1)
                     Index Cond: (dev < NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev, time LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=3.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan (actual rows=3.00 loops=1)
                     Index Cond: (dev > NULL::integer)

\qecho range queries on :TABLE
range queries on skip_scan
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time BETWEEN 100 AND 300;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan (actual rows=11.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND ("time" >= 100) AND ("time" <= 300))

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time < 200;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan (actual rows=11.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND ("time" < 200))

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time > 800;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan (actual rows=11.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND ("time" > 800))

\qecho ordered append on :TABLE
ordered append on skip_scan
:PREFIX SELECT * FROM :TABLE ORDER BY time;
--- QUERY PLAN ---
 Index Scan using skip_scan_time_dev_idx on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT DISTINCT ON (time) time FROM :TABLE WHERE time BETWEEN 0 AND 5000;
--- QUERY PLAN ---
 Unique (actual rows=1001.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=1001.00 loops=1)
         ->  Index Only Scan using skip_scan_time_dev_idx on skip_scan (actual rows=1001.00 loops=1)
               Index Cond: (("time" > NULL::integer) AND ("time" >= 0) AND ("time" <= 5000))

\qecho SUBSELECTS on :TABLE
SUBSELECTS on skip_scan
:PREFIX SELECT time, dev, val, 'q4_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=12.00 loops=1)
   ->  Result (actual rows=12.00 loops=1)
         ->  Unique (actual rows=12.00 loops=1)
               ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
                     ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT NULL, dev, NULL, 'q4_3' FROM (SELECT DISTINCT ON (dev) dev FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT time, dev, NULL, 'q4_4' FROM (SELECT DISTINCT ON (dev) dev, time FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)

\qecho ORDER BY
ORDER BY
:PREFIX SELECT time, dev, val, 'q5_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE ORDER BY dev, time) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=12.00 loops=1)
   ->  Result (actual rows=12.00 loops=1)
         ->  Unique (actual rows=12.00 loops=1)
               ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
                     ->  Index Scan using skip_scan_dev_time_idx on skip_scan (actual rows=12.00 loops=1)

:PREFIX SELECT time, dev, val, 'q5_2' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE ORDER BY dev DESC, time DESC) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=12.00 loops=1)
   ->  Result (actual rows=12.00 loops=1)
         ->  Unique (actual rows=12.00 loops=1)
               ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
                     ->  Index Scan Backward using skip_scan_dev_time_idx on skip_scan (actual rows=12.00 loops=1)

\qecho WHERE CLAUSES
WHERE CLAUSES
:PREFIX SELECT time, dev, val, 'q6_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > 5) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  Result (actual rows=5.00 loops=1)
         ->  Unique (actual rows=5.00 loops=1)
               ->  Custom Scan (SkipScan) on skip_scan (actual rows=5.00 loops=1)
                     ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=5.00 loops=1)
                           Index Cond: (dev > 5)

:PREFIX SELECT time, dev, val, 'q6_2' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE time > 5) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
                     ->  Index Scan using skip_scan_dev_time_idx on skip_scan (actual rows=11.00 loops=1)
                           Index Cond: ("time" > 5)

:PREFIX SELECT time, dev, val, 'q6_3' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a WHERE dev > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  Result (actual rows=5.00 loops=1)
         ->  Unique (actual rows=5.00 loops=1)
               ->  Custom Scan (SkipScan) on skip_scan (actual rows=5.00 loops=1)
                     ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=5.00 loops=1)
                           Index Cond: (dev > 5)

:PREFIX SELECT time, dev, val, 'q6_4' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a WHERE time > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=0.00 loops=1)
   Filter: (a."time" > 5)
   Rows Removed by Filter: 12
   ->  Result (actual rows=12.00 loops=1)
         ->  Unique (actual rows=12.00 loops=1)
               ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
                     ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)

--\qecho immutable func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) *, 'q6_5' FROM :TABLE WHERE dev > int_func_immutable();
--- QUERY PLAN ---
 Result (actual rows=9.00 loops=1)
   ->  Unique (actual rows=9.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=9.00 loops=1)
               ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=9.00 loops=1)
                     Index Cond: (dev > 1)

--\qecho stable func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) *, 'q6_6' FROM :TABLE WHERE dev > int_func_stable();
--- QUERY PLAN ---
 Result (actual rows=8.00 loops=1)
   ->  Unique (actual rows=8.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=8.00 loops=1)
               ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=8.00 loops=1)
                     Index Cond: (dev > int_func_stable())

--\qecho volatile func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > int_func_volatile();
--- QUERY PLAN ---
 Unique (actual rows=7.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=7.00 loops=1)
         ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=7.00 loops=1)
               Filter: (dev > int_func_volatile())
               Rows Removed by Filter: 3022

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_immutable());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=3.00 loops=1)
         ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=3.00 loops=1)
               Index Cond: (dev = ANY ('{1,2,3}'::integer[]))

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_stable());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=3.00 loops=1)
         ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=3.00 loops=1)
               Index Cond: (dev = ANY (inta_func_stable()))

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_volatile());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=3.00 loops=1)
         ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=3.00 loops=1)
               Filter: (dev = ANY (inta_func_volatile()))
               Rows Removed by Filter: 7022

-- RowCompareExpr
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE (dev, time) > (5,100);
--- QUERY PLAN ---
 Unique (actual rows=6.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=6.00 loops=1)
         ->  Index Scan using skip_scan_dev_time_idx on skip_scan (actual rows=6.00 loops=1)
               Index Cond: (ROW(dev, "time") > ROW(5, 100))

-- always false expr similar to our initial skip qual
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > NULL;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Sort (actual rows=0.00 loops=1)
         Sort Key: dev
         Sort Method: quicksort 
         ->  Result (actual rows=0.00 loops=1)
               One-Time Filter: false

-- no tuples matching
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > 20;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=0.00 loops=1)
         ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=0.00 loops=1)
               Index Cond: (dev > 20)

-- multiple constraints in WHERE clause
:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev > 5 AND time = 100;
--- QUERY PLAN ---
 Unique (actual rows=5.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=5.00 loops=1)
         ->  Index Only Scan using skip_scan_time_dev_val_idx on skip_scan (actual rows=5.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer) AND (dev > 5))

:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev > 5 AND time > 200;
--- QUERY PLAN ---
 Unique (actual rows=5.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=5.00 loops=1)
         ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=5.00 loops=1)
               Index Cond: (dev > 5)
               Filter: ("time" > 200)
               Rows Removed by Filter: 1000

:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev >= 5 AND dev < 7 AND dev >= 2;
--- QUERY PLAN ---
 Unique (actual rows=2.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=2.00 loops=1)
         ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=2.00 loops=1)
               Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))

:PREFIX SELECT DISTINCT ON (dev) dev,time,val FROM :TABLE WHERE time > 100 AND time < 200 AND val > 10 AND val < 10000 AND dev > 2 AND dev < 7 ORDER BY dev,time;
--- QUERY PLAN ---
 Unique (actual rows=4.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=4.00 loops=1)
         ->  Index Scan using skip_scan_dev_time_idx on skip_scan (actual rows=4.00 loops=1)
               Index Cond: ((dev > 2) AND (dev < 7) AND ("time" > 100) AND ("time" < 200))
               Filter: ((val > 10) AND (val < 10000))

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE dev IS NULL;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=1.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=1.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND (dev IS NULL))

:PREFIX SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE WHERE dev_name IS NULL;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=1.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=1.00 loops=1)
               Index Cond: ((dev_name > NULL::text) AND (dev_name IS NULL))

-- test constants in ORDER BY
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = 1 ORDER BY dev, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=1.00 loops=1)
         ->  Index Scan Backward using skip_scan_dev_time_idx on skip_scan (actual rows=1.00 loops=1)
               Index Cond: (dev = 1)

:PREFIX SELECT DISTINCT dev, time FROM :TABLE WHERE dev = 1 and time = 100 ORDER BY dev, time DESC;
--- QUERY PLAN ---
 Result (actual rows=1.00 loops=1)
   ->  Unique (actual rows=1.00 loops=1)
         ->  Index Only Scan using skip_scan_time_dev_val_idx on skip_scan (actual rows=1.00 loops=1)
               Index Cond: (("time" = 100) AND (dev = 1))

:PREFIX SELECT DISTINCT dev_name::varchar FROM :TABLE  WHERE dev_name::varchar = 'device_1' ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=1000.00 loops=1)
         Index Cond: (dev_name = 'device_1'::text)

-- test distinct PathKey with sortref = 0 in PG15 due to FALSE filter not pushed into relation (should not crash in PG15)
:PREFIX SELECT DISTINCT sq.dev FROM (SELECT dev FROM :TABLE) sq JOIN :TABLE ref ON (sq.dev = ref.dev) WHERE 1 > 2;
--- QUERY PLAN ---
 HashAggregate (actual rows=0.00 loops=1)
   Group Key: skip_scan.dev
   ->  Result (actual rows=0.00 loops=1)
         One-Time Filter: false

-- test distinct PathKey with sortref not aligning with targets sortrefs in PG15 due to Window function
:PREFIX SELECT DISTINCT
    case when false then c10 else c10 end as c0,
    max(c8) over (partition by c10 order by c6) as c1
FROM (SELECT time as c6, val as c8, dev as c10 FROM :TABLE WHERE false) subq WHERE false;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Sort (actual rows=0.00 loops=1)
         Sort Key: skip_scan.dev, (max(skip_scan.val) OVER (?))
         Sort Method: quicksort 
         ->  WindowAgg (actual rows=0.00 loops=1)
               ->  Sort (actual rows=0.00 loops=1)
                     Sort Key: skip_scan.dev, skip_scan."time"
                     Sort Method: quicksort 
                     ->  Result (actual rows=0.00 loops=1)
                           One-Time Filter: (false AND false)
                           ->  Seq Scan on skip_scan (never executed)

-- test multiple distincts with all but one pinned: #7998
:PREFIX SELECT DISTINCT dev, dev FROM :TABLE ORDER BY 1;
--- QUERY PLAN ---
 Result (actual rows=12.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT dev, time FROM :TABLE WHERE time = 100 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan using skip_scan_time_dev_val_idx on skip_scan (actual rows=11.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer))

:PREFIX SELECT DISTINCT dev, time, val FROM :TABLE WHERE time = 100 and val = 100 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=1.00 loops=1)
         ->  Index Only Scan using skip_scan_time_dev_val_idx on skip_scan (actual rows=1.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer) AND (val = 100))

:PREFIX SELECT DISTINCT ON (dev, time) * FROM :TABLE WHERE time = 100 ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Scan using skip_scan_time_dev_val_idx on skip_scan (actual rows=11.00 loops=1)
               Index Cond: ("time" = 100)

:PREFIX SELECT DISTINCT ON (dev, time) dev, time FROM :TABLE WHERE dev = 1 AND time < 20 ORDER BY dev, time;
--- QUERY PLAN ---
 Unique (actual rows=19.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=19.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan (actual rows=19.00 loops=1)
               Index Cond: ((dev = 1) AND ("time" > NULL::integer) AND ("time" < 20))

-- CTE
:PREFIX WITH devices AS (
	SELECT DISTINCT ON (dev) dev FROM :TABLE
)
SELECT * FROM devices;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev > NULL::integer)

:PREFIX WITH devices AS (
	SELECT DISTINCT dev FROM :TABLE
)
SELECT * FROM devices ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev > NULL::integer)

-- prepared statements
PREPARE prep AS SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev_name > NULL::text)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev_name > NULL::text)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev_name > NULL::text)

DEALLOCATE prep;
-- ReScan tests
:PREFIX SELECT time, dev, val, 'q7_1' FROM (SELECT DISTINCT ON (dev) * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT * FROM :TABLE WHERE time != a.v) b) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Nested Loop (actual rows=20022.00 loops=1)
               Join Filter: (skip_scan."time" <> "*VALUES*".column1)
               Rows Removed by Join Filter: 22
               ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=10022.00 loops=1)
               ->  Materialize (actual rows=2.00 loops=10022)
                     ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)

:PREFIX SELECT time, dev, val, 'q7_2' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev != a.v) b) a;
--- QUERY PLAN ---
 Nested Loop (actual rows=20.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Result (actual rows=10.00 loops=2)
         ->  Unique (actual rows=10.00 loops=2)
               ->  Custom Scan (SkipScan) on skip_scan (actual rows=10.00 loops=2)
                     ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=10.00 loops=2)
                           Filter: (dev <> "*VALUES*".column1)
                           Rows Removed by Filter: 1000

-- RuntimeKeys
:PREFIX SELECT time, dev, val, 'q8_1' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev >= a.v) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=19.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Result (actual rows=10.00 loops=2)
         ->  Unique (actual rows=10.00 loops=2)
               ->  Custom Scan (SkipScan) on skip_scan (actual rows=10.00 loops=2)
                     ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=10.00 loops=2)
                           Index Cond: (dev >= "*VALUES*".column1)

-- Emulate multi-column DISTINCT using multiple SkipSkans
:PREFIX SELECT time, dev, val, 'q9_1' FROM (SELECT b.* FROM
    (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
    LATERAL (SELECT DISTINCT ON (time) * FROM :TABLE WHERE dev = a.dev) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=10001.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)
   ->  Result (actual rows=833.00 loops=12)
         ->  Unique (actual rows=833.00 loops=12)
               ->  Custom Scan (SkipScan) on skip_scan skip_scan_1 (actual rows=833.00 loops=12)
                     ->  Index Scan using skip_scan_dev_time_idx on skip_scan skip_scan_1 (actual rows=833.00 loops=12)
                           Index Cond: (dev = skip_scan.dev)

:PREFIX SELECT time, dev, NULL, 'q9_2' FROM (SELECT b.* FROM
    (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
    LATERAL (SELECT DISTINCT ON (time) dev, time FROM :TABLE WHERE dev = a.dev) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=10001.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)
   ->  Unique (actual rows=833.00 loops=12)
         ->  Custom Scan (SkipScan) on skip_scan skip_scan_1 (actual rows=833.00 loops=12)
               ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan skip_scan_1 (actual rows=833.00 loops=12)
                     Index Cond: ((dev = skip_scan.dev) AND ("time" > NULL::integer))

-- Test that the multi-column DISTINCT emulation is equivalent to a real multi-column DISTINCT
:PREFIX SELECT * FROM
   (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
   LATERAL (SELECT DISTINCT ON (time) dev, time FROM :TABLE WHERE dev = a.dev) b;
--- QUERY PLAN ---
 Nested Loop (actual rows=10001.00 loops=1)
   ->  Unique (actual rows=12.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev > NULL::integer)
   ->  Unique (actual rows=833.00 loops=12)
         ->  Custom Scan (SkipScan) on skip_scan skip_scan_1 (actual rows=833.00 loops=12)
               ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan skip_scan_1 (actual rows=833.00 loops=12)
                     Index Cond: ((dev = skip_scan.dev) AND ("time" > NULL::integer))

:PREFIX SELECT DISTINCT ON (dev, time) dev, time FROM :TABLE WHERE coalesce(dev, -1) >= 0;
--- QUERY PLAN ---
 Unique (actual rows=10001.00 loops=1)
   ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan (actual rows=10001.00 loops=1)
         Filter: (COALESCE(dev, '-1'::integer) >= 0)
         Rows Removed by Filter: 21

:PREFIX SELECT DISTINCT ON (dev, time) dev, time FROM :TABLE WHERE coalesce(dev, -1) >= 0
UNION SELECT b.* FROM
   (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
   LATERAL (SELECT DISTINCT ON (time) dev, time FROM :TABLE WHERE dev = a.dev) b;
--- QUERY PLAN ---
 Unique (actual rows=10001.00 loops=1)
   ->  Sort (actual rows=20002.00 loops=1)
         Sort Key: skip_scan.dev, skip_scan."time"
         Sort Method: quicksort 
         ->  Append (actual rows=20002.00 loops=1)
               ->  Unique (actual rows=10001.00 loops=1)
                     ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan (actual rows=10001.00 loops=1)
                           Filter: (COALESCE(dev, '-1'::integer) >= 0)
                           Rows Removed by Filter: 21
               ->  Nested Loop (actual rows=10001.00 loops=1)
                     ->  Unique (actual rows=12.00 loops=1)
                           ->  Custom Scan (SkipScan) on skip_scan skip_scan_1 (actual rows=12.00 loops=1)
                                 ->  Index Only Scan using skip_scan_dev_idx on skip_scan skip_scan_1 (actual rows=12.00 loops=1)
                                       Index Cond: (dev > NULL::integer)
                     ->  Unique (actual rows=833.00 loops=12)
                           ->  Custom Scan (SkipScan) on skip_scan skip_scan_2 (actual rows=833.00 loops=12)
                                 ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan skip_scan_2 (actual rows=833.00 loops=12)
                                       Index Cond: ((dev = skip_scan_1.dev) AND ("time" > NULL::integer))

-- SkipScan into INSERT
:PREFIX INSERT INTO skip_scan_insert(time, dev, val, query) SELECT time, dev, val, 'q10_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a;
--- QUERY PLAN ---
 Insert on skip_scan_insert (actual rows=0.00 loops=1)
   ->  Subquery Scan on a (actual rows=12.00 loops=1)
         ->  Result (actual rows=12.00 loops=1)
               ->  Unique (actual rows=12.00 loops=1)
                     ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
                           ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)

-- parallel query
SELECT set_config(CASE WHEN current_setting('server_version_num')::int < 160000 THEN 'force_parallel_mode' ELSE 'debug_parallel_query' END,'on', false);
 set_config 
------------
 on

:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=12.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
               Index Cond: (dev > NULL::integer)

SELECT set_config(CASE WHEN current_setting('server_version_num')::int < 160000 THEN 'force_parallel_mode' ELSE 'debug_parallel_query' END,'off', false);
 set_config 
------------
 off

TRUNCATE skip_scan_insert;
-- table with only nulls
:PREFIX SELECT DISTINCT ON (time) time FROM skip_scan_nulls;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan_nulls (actual rows=1.00 loops=1)
         ->  Index Only Scan using skip_scan_nulls_time_idx on skip_scan_nulls (actual rows=1.00 loops=1)
               Index Cond: ("time" > NULL::integer)

-- no tuples in resultset
:PREFIX SELECT DISTINCT ON (time) time FROM skip_scan_nulls WHERE time IS NOT NULL;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan_nulls (actual rows=0.00 loops=1)
         ->  Index Only Scan using skip_scan_nulls_time_idx on skip_scan_nulls (actual rows=0.00 loops=1)
               Index Cond: (("time" > NULL::integer) AND ("time" IS NOT NULL))

-- Test for SDC issue #2976
-- We should use index "btree ("time", dev, dev_name)" where "dev_name" index key is #3 but we have 2 index quals including SkipScan qual
-- We should not drop qual on "dev_name"
CREATE INDEX skip_scan_idx_time_dev_dname ON :TABLE(time,dev,dev_name);
:PREFIX SELECT DISTINCT time FROM :TABLE WHERE dev_name IS NULL ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=20.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=20.00 loops=1)
         ->  Index Only Scan using skip_scan_idx_time_dev_dname on skip_scan (actual rows=20.00 loops=1)
               Index Cond: (("time" > NULL::integer) AND (dev_name IS NULL))

DROP INDEX skip_scan_idx_time_dev_dname;
-- "dev_name" is not a key column: it's not in the index quals and should be a filter
CREATE INDEX skip_scan_idx_time_dev_dname ON :TABLE(time,dev) INCLUDE(dev_name);
:PREFIX SELECT DISTINCT time FROM :TABLE WHERE dev_name IS NULL ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=20.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=20.00 loops=1)
         ->  Index Scan using skip_scan_time_dev_idx on skip_scan (actual rows=20.00 loops=1)
               Filter: (dev_name IS NULL)
               Rows Removed by Filter: 10002

DROP INDEX skip_scan_idx_time_dev_dname;
\set TABLE skip_scan_ht
\ir include/skip_scan_query.sql
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
-- canary for result diff
SELECT current_setting('timescaledb.enable_skipscan') AS enable_skipscan;
 enable_skipscan 
-----------------
 on

-- test different index configurations
-- no index so we cant do SkipScan
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=11.00 loops=1)
   Sort Key: skip_scan_ht.dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_ht.dev
         ->  Append (actual rows=10020.00 loops=1)
               ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

-- NULLS LAST index on dev
CREATE INDEX skip_scan_idx_dev_nulls_last ON :TABLE(dev);
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev DESC;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev DESC
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan Backward using _hyper_1_1_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev < NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan Backward using _hyper_1_2_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev < NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan Backward using _hyper_1_3_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev < NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan Backward using _hyper_1_4_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev < NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE dev IS NOT NULL ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=10.00 loops=1)
   ->  Merge Append (actual rows=40.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_1_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_2_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_3_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_idx_dev_nulls_last on _hyper_1_4_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))

DROP INDEX skip_scan_idx_dev_nulls_last;
-- NULLS FIRST index on dev
CREATE INDEX skip_scan_idx_dev_nulls_first ON :TABLE(dev NULLS FIRST);
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev NULLS FIRST;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev NULLS FIRST
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev NULLS FIRST;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev NULLS FIRST
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE dev IS NOT NULL ORDER BY dev NULLS FIRST;
--- QUERY PLAN ---
 Unique (actual rows=10.00 loops=1)
   ->  Merge Append (actual rows=40.00 loops=1)
         Sort Key: skip_scan_ht.dev NULLS FIRST
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_1_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_2_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_3_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_idx_dev_nulls_first on _hyper_1_4_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))

DROP INDEX skip_scan_idx_dev_nulls_first;
-- multicolumn index with dev as leading column
CREATE INDEX skip_scan_idx_dev_time_idx ON :TABLE(dev, time);
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_dev_time_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_idx_dev_time_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_idx_dev_time_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_idx_dev_time_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_dev_time_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_idx_dev_time_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_idx_dev_time_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_idx_dev_time_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev DESC, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev DESC, skip_scan_ht."time" DESC
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan Backward using _hyper_1_1_chunk_skip_scan_idx_dev_time_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev < NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan Backward using _hyper_1_2_chunk_skip_scan_idx_dev_time_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev < NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan Backward using _hyper_1_3_chunk_skip_scan_idx_dev_time_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev < NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan Backward using _hyper_1_4_chunk_skip_scan_idx_dev_time_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev < NULL::integer)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE dev IS NOT NULL ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=10.00 loops=1)
   ->  Merge Append (actual rows=40.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_dev_time_idx on _hyper_1_1_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_idx_dev_time_idx on _hyper_1_2_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_idx_dev_time_idx on _hyper_1_3_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_idx_dev_time_idx on _hyper_1_4_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NOT NULL))

DROP INDEX skip_scan_idx_dev_time_idx;
-- multicolumn index with dev as non-leading column
CREATE INDEX skip_scan_idx_time_dev_idx ON :TABLE(time, dev);
:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE time = 100 ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_time_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer))

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time = 100;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_time_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer))

-- Test not-NULL mode
:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE time = 100 AND dev IS NOT NULL ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=10.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=10.00 loops=1)
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_time_dev_idx on _hyper_1_1_chunk (actual rows=10.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer) AND (dev IS NOT NULL))

DROP INDEX skip_scan_idx_time_dev_idx;
-- hash index is not ordered so can't use skipscan
CREATE INDEX skip_scan_idx_hash ON :TABLE USING hash(dev_name);
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE dev_name IN ('device_1','device_2') ORDER BY dev_name;
--- QUERY PLAN ---
 Sort (actual rows=2.00 loops=1)
   Sort Key: skip_scan_ht.dev_name
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=2.00 loops=1)
         Group Key: skip_scan_ht.dev_name
         ->  Append (actual rows=2000.00 loops=1)
               ->  Bitmap Heap Scan on _hyper_1_1_chunk (actual rows=500.00 loops=1)
                     Recheck Cond: (dev_name = ANY ('{device_1,device_2}'::text[]))
                     Heap Blocks: exact=4
                     ->  Bitmap Index Scan on _hyper_1_1_chunk_skip_scan_idx_hash (actual rows=500.00 loops=1)
                           Index Cond: (dev_name = ANY ('{device_1,device_2}'::text[]))
               ->  Bitmap Heap Scan on _hyper_1_2_chunk (actual rows=500.00 loops=1)
                     Recheck Cond: (dev_name = ANY ('{device_1,device_2}'::text[]))
                     Heap Blocks: exact=4
                     ->  Bitmap Index Scan on _hyper_1_2_chunk_skip_scan_idx_hash (actual rows=500.00 loops=1)
                           Index Cond: (dev_name = ANY ('{device_1,device_2}'::text[]))
               ->  Bitmap Heap Scan on _hyper_1_3_chunk (actual rows=500.00 loops=1)
                     Recheck Cond: (dev_name = ANY ('{device_1,device_2}'::text[]))
                     Heap Blocks: exact=4
                     ->  Bitmap Index Scan on _hyper_1_3_chunk_skip_scan_idx_hash (actual rows=500.00 loops=1)
                           Index Cond: (dev_name = ANY ('{device_1,device_2}'::text[]))
               ->  Bitmap Heap Scan on _hyper_1_4_chunk (actual rows=500.00 loops=1)
                     Recheck Cond: (dev_name = ANY ('{device_1,device_2}'::text[]))
                     Heap Blocks: exact=4
                     ->  Bitmap Index Scan on _hyper_1_4_chunk_skip_scan_idx_hash (actual rows=500.00 loops=1)
                           Index Cond: (dev_name = ANY ('{device_1,device_2}'::text[]))

DROP INDEX skip_scan_idx_hash;
-- expression indexes
-- currently not supported by skipscan
CREATE INDEX skip_scan_expr_idx ON :TABLE((dev % 3));
:PREFIX SELECT DISTINCT dev%3 FROM :TABLE ORDER BY dev%3;
--- QUERY PLAN ---
 Sort (actual rows=4.00 loops=1)
   Sort Key: ((skip_scan_ht.dev % 3))
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=4.00 loops=1)
         Group Key: (skip_scan_ht.dev % 3)
         ->  Result (actual rows=10020.00 loops=1)
               ->  Append (actual rows=10020.00 loops=1)
                     ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev%3) dev FROM :TABLE ORDER BY dev%3;
--- QUERY PLAN ---
 Unique (actual rows=4.00 loops=1)
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: ((skip_scan_ht.dev % 3))
         ->  Index Scan using _hyper_1_1_chunk_skip_scan_expr_idx on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
         ->  Index Scan using _hyper_1_2_chunk_skip_scan_expr_idx on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
         ->  Index Scan using _hyper_1_3_chunk_skip_scan_expr_idx on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
         ->  Index Scan using _hyper_1_4_chunk_skip_scan_expr_idx on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

DROP INDEX skip_scan_expr_idx;
CREATE INDEX ON :TABLE(dev_name);
-- Tests for #8107: accounting for scanning most of the input due to non-index quals
-- Non-index qual, no tuples match: SeqScan preferred
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE val < 0 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Sort (actual rows=0.00 loops=1)
         Sort Key: skip_scan_ht.dev_name
         Sort Method: quicksort 
         ->  Append (actual rows=0.00 loops=1)
               ->  Seq Scan on _hyper_1_1_chunk (actual rows=0.00 loops=1)
                     Filter: (val < 0)
                     Rows Removed by Filter: 2505
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=0.00 loops=1)
                     Filter: (val < 0)
                     Rows Removed by Filter: 2505
               ->  Seq Scan on _hyper_1_3_chunk (actual rows=0.00 loops=1)
                     Filter: (val < 0)
                     Rows Removed by Filter: 2505
               ->  Seq Scan on _hyper_1_4_chunk (actual rows=0.00 loops=1)
                     Filter: (val < 0)
                     Rows Removed by Filter: 2505

-- Highly selective non-index qual, have to scan many tuples to match: SeqScan preferred
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE time = 100 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Sort (actual rows=11.00 loops=1)
         Sort Key: _hyper_1_1_chunk.dev_name
         Sort Method: quicksort 
         ->  Seq Scan on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               Filter: ("time" = 100)
               Rows Removed by Filter: 2494

-- Same but a combo of non-index quals
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE time = 100 and dev = 1 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Sort (actual rows=1.00 loops=1)
         Sort Key: _hyper_1_1_chunk.dev_name
         Sort Method: quicksort 
         ->  Seq Scan on _hyper_1_1_chunk (actual rows=1.00 loops=1)
               Filter: (("time" = 100) AND (dev = 1))
               Rows Removed by Filter: 2504

-- Highly selective index qual: less tuples to scan for low-selective non-index qual, can choose SkipScan
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE dev_name IS NULL and dev = 1 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Merge Append (actual rows=0.00 loops=1)
         Sort Key: skip_scan_ht.dev_name
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=0.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=0.00 loops=1)
                     Index Cond: (dev_name IS NULL)
                     Filter: (dev = 1)
                     Rows Removed by Filter: 5
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=0.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=0.00 loops=1)
                     Index Cond: (dev_name IS NULL)
                     Filter: (dev = 1)
                     Rows Removed by Filter: 5
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=0.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=0.00 loops=1)
                     Index Cond: (dev_name IS NULL)
                     Filter: (dev = 1)
                     Rows Removed by Filter: 5
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=0.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=0.00 loops=1)
                     Index Cond: (dev_name IS NULL)
                     Filter: (dev = 1)
                     Rows Removed by Filter: 5

CREATE INDEX ON :TABLE(dev);
-- RowCompareExpr where some args are not in the index:
-- we extract lossy "dev >=5" index condition which is strict and doesn't allow NULLs
SET timescaledb.debug_skip_scan_info TO true;
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE (dev, time) > (5,100);
psql:include/skip_scan_query.sql:74: INFO:  SkipScan used on _hyper_1_1_chunk_skip_scan_ht_dev_idx(dev NOT NULL)
psql:include/skip_scan_query.sql:74: INFO:  SkipScan used on _hyper_1_2_chunk_skip_scan_ht_dev_idx(dev NOT NULL)
psql:include/skip_scan_query.sql:74: INFO:  SkipScan used on _hyper_1_3_chunk_skip_scan_ht_dev_idx(dev NOT NULL)
psql:include/skip_scan_query.sql:74: INFO:  SkipScan used on _hyper_1_4_chunk_skip_scan_ht_dev_idx(dev NOT NULL)
--- QUERY PLAN ---
 Unique (actual rows=6.00 loops=1)
   ->  Merge Append (actual rows=24.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=6.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=6.00 loops=1)
                     Index Cond: (dev >= 5)
                     Filter: (ROW(dev, "time") > ROW(5, 100))
                     Rows Removed by Filter: 101
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=6.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=6.00 loops=1)
                     Index Cond: (dev >= 5)
                     Filter: (ROW(dev, "time") > ROW(5, 100))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=6.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=6.00 loops=1)
                     Index Cond: (dev >= 5)
                     Filter: (ROW(dev, "time") > ROW(5, 100))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=6.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=6.00 loops=1)
                     Index Cond: (dev >= 5)
                     Filter: (ROW(dev, "time") > ROW(5, 100))

RESET timescaledb.debug_skip_scan_info;
CREATE INDEX ON :TABLE(dev, time);
CREATE INDEX ON :TABLE(time,dev);
CREATE INDEX ON :TABLE(time,dev,val);
\qecho basic DISTINCT queries on :TABLE
basic DISTINCT queries on skip_scan_ht
:PREFIX SELECT DISTINCT dev, 'q1_1' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT dev_name, 'q1_2' FROM :TABLE ORDER BY dev_name;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT dev, 'q1_3', NULL FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

\qecho stable expression in targetlist on :TABLE
stable expression in targetlist on skip_scan_ht
:PREFIX SELECT DISTINCT dev, 'q1_4', length(md5(now()::text)) FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT dev_name, 'q1_5', length(md5(now()::text)) FROM :TABLE ORDER BY dev_name;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)

-- volatile expression in targetlist
:PREFIX SELECT DISTINCT dev, 'q1_6', length(md5(random()::text)) FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Sort (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_ht.dev, (length(md5((random())::text)))
         Sort Method: quicksort 
         ->  Result (actual rows=10020.00 loops=1)
               ->  Append (actual rows=10020.00 loops=1)
                     ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

:PREFIX SELECT DISTINCT dev_name, 'q1_7', length(md5(random()::text)) FROM :TABLE ORDER BY dev_name;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Sort (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_ht.dev_name, (length(md5((random())::text)))
         Sort Method: quicksort 
         ->  Result (actual rows=10020.00 loops=1)
               ->  Append (actual rows=10020.00 loops=1)
                     ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

-- queries without skipscan because distinct is not limited to specific column
:PREFIX SELECT DISTINCT * FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=10020.00 loops=1)
   Sort Key: skip_scan_ht.dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=10020.00 loops=1)
         Group Key: skip_scan_ht.dev, skip_scan_ht."time", skip_scan_ht.dev_name, skip_scan_ht.val
         ->  Append (actual rows=10020.00 loops=1)
               ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

:PREFIX SELECT DISTINCT *, 'q1_9' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=10020.00 loops=1)
   Sort Key: skip_scan_ht.dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=10020.00 loops=1)
         Group Key: skip_scan_ht.dev, skip_scan_ht."time", skip_scan_ht.dev_name, skip_scan_ht.val, 'q1_9'::text
         ->  Result (actual rows=10020.00 loops=1)
               ->  Append (actual rows=10020.00 loops=1)
                     ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

:PREFIX SELECT DISTINCT dev, time, 'q1_10' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=10020.00 loops=1)
   Sort Key: skip_scan_ht.dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=10020.00 loops=1)
         Group Key: skip_scan_ht.dev, skip_scan_ht."time", 'q1_10'::text
         ->  Result (actual rows=10020.00 loops=1)
               ->  Append (actual rows=10020.00 loops=1)
                     ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

:PREFIX SELECT DISTINCT dev, NULL, 'q1_11' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

-- distinct on expressions not supported
:PREFIX SELECT DISTINCT time_bucket(10,time), 'q1_12' FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=100.00 loops=1)
   Group Key: time_bucket(10, skip_scan_ht."time"), 'q1_12'::text
   ->  Result (actual rows=10020.00 loops=1)
         ->  Append (actual rows=10020.00 loops=1)
               ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

:PREFIX SELECT DISTINCT length(dev_name), 'q1_13' FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=3.00 loops=1)
   Group Key: length(skip_scan_ht.dev_name), 'q1_13'::text
   ->  Result (actual rows=10020.00 loops=1)
         ->  Append (actual rows=10020.00 loops=1)
               ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

:PREFIX SELECT DISTINCT 3*time, 'q1_14' FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=1000.00 loops=1)
   Group Key: (3 * skip_scan_ht."time"), 'q1_14'::text
   ->  Result (actual rows=10020.00 loops=1)
         ->  Append (actual rows=10020.00 loops=1)
               ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

:PREFIX SELECT DISTINCT 'Device ' || dev_name FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=11.00 loops=1)
   Group Key: ('Device '::text || skip_scan_ht.dev_name)
   ->  Result (actual rows=10020.00 loops=1)
         ->  Append (actual rows=10020.00 loops=1)
               ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

-- DISTINCT ON queries
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_2' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_3', NULL FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_4', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_5', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) *, 'q2_7' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, time, 'q2_8' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, NULL, 'q2_9' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) time, 'q2_10' FROM :TABLE ORDER by dev, time;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev, skip_scan_ht."time"
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, tableoid::regclass, 'q2_11' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_immutable(), 'q2_12' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_stable(), 'q2_13' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_volatile(), 'q2_14' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

-- DISTINCT ON queries on TEXT column
:PREFIX SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev_name
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE WHERE dev_name IS NOT NULL;
--- QUERY PLAN ---
 Unique (actual rows=10.00 loops=1)
   ->  Merge Append (actual rows=40.00 loops=1)
         Sort Key: skip_scan_ht.dev_name
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev_name > NULL::text) AND (dev_name IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev_name > NULL::text) AND (dev_name IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev_name > NULL::text) AND (dev_name IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=10.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=10.00 loops=1)
                     Index Cond: ((dev_name > NULL::text) AND (dev_name IS NOT NULL))

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_2' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_3', NULL FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_4', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_5', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) * FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev_name
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) *, 'q3_7' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, time, 'q3_8' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, NULL, 'q3_9' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) time, 'q3_10' FROM :TABLE ORDER by dev_name, time;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Sort (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_ht.dev_name, skip_scan_ht."time"
         Sort Method: quicksort 
         ->  Result (actual rows=10020.00 loops=1)
               ->  Append (actual rows=10020.00 loops=1)
                     ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, tableoid::regclass, 'q3_11' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name::varchar) dev_name::varchar FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev_name > NULL::text)

:PREFIX SELECT DISTINCT ON (dev_name) dev, int_func_immutable(), 'q3_13' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev, int_func_stable(), 'q3_14' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev, int_func_volatile(), 'q3_15' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev_name
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

\qecho DISTINCT with wholerow var
DISTINCT with wholerow var
:PREFIX SELECT DISTINCT ON (dev) :TABLE FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

-- should not use SkipScan since we only support SkipScan on single-column distinct
:PREFIX SELECT DISTINCT :TABLE FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=10020.00 loops=1)
   Group Key: ((skip_scan_ht.*)::skip_scan_ht)
   ->  Append (actual rows=10020.00 loops=1)
         ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
         ->  Seq Scan on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
         ->  Seq Scan on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
         ->  Seq Scan on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

\qecho LIMIT queries on :TABLE
LIMIT queries on skip_scan_ht
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Merge Append (actual rows=9.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev DESC, time DESC LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Merge Append (actual rows=9.00 loops=1)
               Sort Key: skip_scan_ht.dev DESC, skip_scan_ht."time" DESC
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan Backward using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev < NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan Backward using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev < NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan Backward using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev < NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan Backward using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev < NULL::integer)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev, time LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Merge Append (actual rows=9.00 loops=1)
               Sort Key: skip_scan_ht.dev, skip_scan_ht."time"
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=3.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev > NULL::integer)

\qecho range queries on :TABLE
range queries on skip_scan_ht
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time BETWEEN 100 AND 300;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=22.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND ("time" >= 100) AND ("time" <= 300))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND ("time" >= 100) AND ("time" <= 300))

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time < 200;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND ("time" < 200))

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time > 800;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
         ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND ("time" > 800))

\qecho ordered append on :TABLE
ordered append on skip_scan_ht
:PREFIX SELECT * FROM :TABLE ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on skip_scan_ht (actual rows=10020.00 loops=1)
   Order: skip_scan_ht."time"
   ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_time_dev_idx on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
   ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_time_dev_idx on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
   ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_time_dev_idx on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
   ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_time_dev_idx on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

:PREFIX SELECT DISTINCT ON (time) time FROM :TABLE WHERE time BETWEEN 0 AND 5000;
--- QUERY PLAN ---
 Unique (actual rows=1000.00 loops=1)
   ->  Merge Append (actual rows=1000.00 loops=1)
         Sort Key: skip_scan_ht."time"
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=250.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_time_dev_idx on _hyper_1_1_chunk (actual rows=250.00 loops=1)
                     Index Cond: ("time" > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=250.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_time_dev_idx on _hyper_1_2_chunk (actual rows=250.00 loops=1)
                     Index Cond: ("time" > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=250.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_time_dev_idx on _hyper_1_3_chunk (actual rows=250.00 loops=1)
                     Index Cond: ("time" > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=250.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_time_dev_idx on _hyper_1_4_chunk (actual rows=250.00 loops=1)
                     Index Cond: ("time" > NULL::integer)

\qecho SUBSELECTS on :TABLE
SUBSELECTS on skip_scan_ht
:PREFIX SELECT time, dev, val, 'q4_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_ht.dev
                     ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT NULL, dev, NULL, 'q4_3' FROM (SELECT DISTINCT ON (dev) dev FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT time, dev, NULL, 'q4_4' FROM (SELECT DISTINCT ON (dev) dev, time FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

\qecho ORDER BY
ORDER BY
:PREFIX SELECT time, dev, val, 'q5_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE ORDER BY dev, time) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_ht.dev, skip_scan_ht."time"
                     ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT time, dev, val, 'q5_2' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE ORDER BY dev DESC, time DESC) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_ht.dev DESC, skip_scan_ht."time" DESC
                     ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan Backward using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan Backward using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan Backward using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan Backward using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

\qecho WHERE CLAUSES
WHERE CLAUSES
:PREFIX SELECT time, dev, val, 'q6_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > 5) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  Result (actual rows=5.00 loops=1)
         ->  Unique (actual rows=5.00 loops=1)
               ->  Merge Append (actual rows=20.00 loops=1)
                     Sort Key: skip_scan_ht.dev
                     ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=5.00 loops=1)
                           ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=5.00 loops=1)
                           ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=5.00 loops=1)
                           ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=5.00 loops=1)
                           ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (dev > 5)

:PREFIX SELECT time, dev, val, 'q6_2' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE time > 5) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_ht.dev
                     ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                                 Index Cond: ("time" > 5)
                     ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT time, dev, val, 'q6_3' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a WHERE dev > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  Result (actual rows=5.00 loops=1)
         ->  Unique (actual rows=5.00 loops=1)
               ->  Merge Append (actual rows=20.00 loops=1)
                     Sort Key: skip_scan_ht.dev
                     ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=5.00 loops=1)
                           ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=5.00 loops=1)
                           ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=5.00 loops=1)
                           ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=5.00 loops=1)
                           ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=5.00 loops=1)
                                 Index Cond: (dev > 5)

:PREFIX SELECT time, dev, val, 'q6_4' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a WHERE time > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=7.00 loops=1)
   Filter: (a."time" > 5)
   Rows Removed by Filter: 4
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_ht.dev
                     ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

--\qecho immutable func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) *, 'q6_5' FROM :TABLE WHERE dev > int_func_immutable();
--- QUERY PLAN ---
 Result (actual rows=9.00 loops=1)
   ->  Unique (actual rows=9.00 loops=1)
         ->  Merge Append (actual rows=36.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=9.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=9.00 loops=1)
                           Index Cond: (dev > 1)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=9.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=9.00 loops=1)
                           Index Cond: (dev > 1)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=9.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=9.00 loops=1)
                           Index Cond: (dev > 1)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=9.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=9.00 loops=1)
                           Index Cond: (dev > 1)

--\qecho stable func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) *, 'q6_6' FROM :TABLE WHERE dev > int_func_stable();
--- QUERY PLAN ---
 Result (actual rows=8.00 loops=1)
   ->  Unique (actual rows=8.00 loops=1)
         ->  Custom Scan (ConstraintAwareAppend) (actual rows=32.00 loops=1)
               Hypertable: skip_scan_ht
               Chunks excluded during startup: 0
               ->  Merge Append (actual rows=32.00 loops=1)
                     Sort Key: skip_scan_ht.dev
                     ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=8.00 loops=1)
                           ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=8.00 loops=1)
                                 Index Cond: (dev > int_func_stable())
                     ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=8.00 loops=1)
                           ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=8.00 loops=1)
                                 Index Cond: (dev > int_func_stable())
                     ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=8.00 loops=1)
                           ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=8.00 loops=1)
                                 Index Cond: (dev > int_func_stable())
                     ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=8.00 loops=1)
                           ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=8.00 loops=1)
                                 Index Cond: (dev > int_func_stable())

--\qecho volatile func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > int_func_volatile();
--- QUERY PLAN ---
 Unique (actual rows=7.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=28.00 loops=1)
         Hypertable: skip_scan_ht
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=28.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=7.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=7.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=7.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=7.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_immutable());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Merge Append (actual rows=12.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=3.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=3.00 loops=1)
                     Index Cond: (dev = ANY ('{1,2,3}'::integer[]))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=3.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=3.00 loops=1)
                     Index Cond: (dev = ANY ('{1,2,3}'::integer[]))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=3.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=3.00 loops=1)
                     Index Cond: (dev = ANY ('{1,2,3}'::integer[]))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=3.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=3.00 loops=1)
                     Index Cond: (dev = ANY ('{1,2,3}'::integer[]))

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_stable());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=12.00 loops=1)
         Hypertable: skip_scan_ht
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=12.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY (inta_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY (inta_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY (inta_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY (inta_func_stable()))

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_volatile());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=12.00 loops=1)
         Hypertable: skip_scan_ht
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=12.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755

-- RowCompareExpr
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE (dev, time) > (5,100);
--- QUERY PLAN ---
 Unique (actual rows=6.00 loops=1)
   ->  Merge Append (actual rows=24.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=6.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=6.00 loops=1)
                     Index Cond: (ROW(dev, "time") > ROW(5, 100))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=6.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk (actual rows=6.00 loops=1)
                     Index Cond: (ROW(dev, "time") > ROW(5, 100))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=6.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk (actual rows=6.00 loops=1)
                     Index Cond: (ROW(dev, "time") > ROW(5, 100))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=6.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk (actual rows=6.00 loops=1)
                     Index Cond: (ROW(dev, "time") > ROW(5, 100))

-- always false expr similar to our initial skip qual
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > NULL;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Sort (actual rows=0.00 loops=1)
         Sort Key: dev
         Sort Method: quicksort 
         ->  Result (actual rows=0.00 loops=1)
               One-Time Filter: false

-- no tuples matching
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > 20;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Merge Append (actual rows=0.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=0.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=0.00 loops=1)
                     Index Cond: (dev > 20)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=0.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=0.00 loops=1)
                     Index Cond: (dev > 20)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=0.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=0.00 loops=1)
                     Index Cond: (dev > 20)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=0.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=0.00 loops=1)
                     Index Cond: (dev > 20)

-- multiple constraints in WHERE clause
:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev > 5 AND time = 100;
--- QUERY PLAN ---
 Unique (actual rows=5.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=5.00 loops=1)
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_time_dev_val_idx on _hyper_1_1_chunk (actual rows=5.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer) AND (dev > 5))

:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev > 5 AND time > 200;
--- QUERY PLAN ---
 Unique (actual rows=5.00 loops=1)
   ->  Merge Append (actual rows=20.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=5.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=5.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev > 5) AND ("time" > 200))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=5.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=5.00 loops=1)
                     Index Cond: (dev > 5)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=5.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=5.00 loops=1)
                     Index Cond: (dev > 5)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=5.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=5.00 loops=1)
                     Index Cond: (dev > 5)

:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev >= 5 AND dev < 7 AND dev >= 2;
--- QUERY PLAN ---
 Unique (actual rows=2.00 loops=1)
   ->  Merge Append (actual rows=8.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=2.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=2.00 loops=1)
                     Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=2.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=2.00 loops=1)
                     Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=2.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=2.00 loops=1)
                     Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=2.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=2.00 loops=1)
                     Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))

:PREFIX SELECT DISTINCT ON (dev) dev,time,val FROM :TABLE WHERE time > 100 AND time < 200 AND val > 10 AND val < 10000 AND dev > 2 AND dev < 7 ORDER BY dev,time;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=0.00 loops=1)
         ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=0.00 loops=1)
               Index Cond: ((dev > 2) AND (dev < 7) AND ("time" > 100) AND ("time" < 200))
               Filter: ((val > 10) AND (val < 10000))
               Rows Removed by Filter: 396

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE dev IS NULL;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=1.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=1.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=1.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=1.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev IS NULL))

:PREFIX SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE WHERE dev_name IS NULL;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_ht.dev_name
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=1.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((dev_name > NULL::text) AND (dev_name IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=1.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((dev_name > NULL::text) AND (dev_name IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=1.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((dev_name > NULL::text) AND (dev_name IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=1.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=1.00 loops=1)
                     Index Cond: ((dev_name > NULL::text) AND (dev_name IS NULL))

-- test constants in ORDER BY
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = 1 ORDER BY dev, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_ht."time" DESC
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=1.00 loops=1)
               ->  Index Scan Backward using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=1.00 loops=1)
                     Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=1.00 loops=1)
               ->  Index Scan Backward using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk (actual rows=1.00 loops=1)
                     Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=1.00 loops=1)
               ->  Index Scan Backward using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk (actual rows=1.00 loops=1)
                     Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=1.00 loops=1)
               ->  Index Scan Backward using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk (actual rows=1.00 loops=1)
                     Index Cond: (dev = 1)

:PREFIX SELECT DISTINCT dev, time FROM :TABLE WHERE dev = 1 and time = 100 ORDER BY dev, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_time_dev_val_idx on _hyper_1_1_chunk (actual rows=1.00 loops=1)
         Index Cond: (("time" = 100) AND (dev = 1))

:PREFIX SELECT DISTINCT dev_name::varchar FROM :TABLE  WHERE dev_name::varchar = 'device_1' ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Result (actual rows=1000.00 loops=1)
         ->  Append (actual rows=1000.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=250.00 loops=1)
                     Index Cond: (dev_name = 'device_1'::text)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=250.00 loops=1)
                     Index Cond: (dev_name = 'device_1'::text)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=250.00 loops=1)
                     Index Cond: (dev_name = 'device_1'::text)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=250.00 loops=1)
                     Index Cond: (dev_name = 'device_1'::text)

-- test distinct PathKey with sortref = 0 in PG15 due to FALSE filter not pushed into relation (should not crash in PG15)
:PREFIX SELECT DISTINCT sq.dev FROM (SELECT dev FROM :TABLE) sq JOIN :TABLE ref ON (sq.dev = ref.dev) WHERE 1 > 2;
--- QUERY PLAN ---
 HashAggregate (actual rows=0.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  Result (actual rows=0.00 loops=1)
         One-Time Filter: false

-- test distinct PathKey with sortref not aligning with targets sortrefs in PG15 due to Window function
:PREFIX SELECT DISTINCT
    case when false then c10 else c10 end as c0,
    max(c8) over (partition by c10 order by c6) as c1
FROM (SELECT time as c6, val as c8, dev as c10 FROM :TABLE WHERE false) subq WHERE false;
--- QUERY PLAN ---
 HashAggregate (actual rows=0.00 loops=1)
   Group Key: skip_scan_ht.dev, max(skip_scan_ht.val) OVER (?)
   ->  WindowAgg (actual rows=0.00 loops=1)
         ->  Sort (actual rows=0.00 loops=1)
               Sort Key: skip_scan_ht.dev, skip_scan_ht."time"
               Sort Method: quicksort 
               ->  Result (actual rows=0.00 loops=1)
                     One-Time Filter: false

-- test multiple distincts with all but one pinned: #7998
:PREFIX SELECT DISTINCT dev, dev FROM :TABLE ORDER BY 1;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)

:PREFIX SELECT DISTINCT dev, time FROM :TABLE WHERE time = 100 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_time_dev_val_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer))

:PREFIX SELECT DISTINCT dev, time, val FROM :TABLE WHERE time = 100 and val = 100 ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=0.00 loops=1)
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_time_dev_val_idx on _hyper_1_1_chunk (actual rows=0.00 loops=1)
               Index Cond: (("time" = 100) AND (dev > NULL::integer) AND (val = 100))

:PREFIX SELECT DISTINCT ON (dev, time) * FROM :TABLE WHERE time = 100 ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_time_dev_val_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               Index Cond: ("time" = 100)

:PREFIX SELECT DISTINCT ON (dev, time) dev, time FROM :TABLE WHERE dev = 1 AND time < 20 ORDER BY dev, time;
--- QUERY PLAN ---
 Unique (actual rows=20.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=20.00 loops=1)
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=20.00 loops=1)
               Index Cond: ((dev = 1) AND ("time" > NULL::integer) AND ("time" < 20))

-- CTE
:PREFIX WITH devices AS (
	SELECT DISTINCT ON (dev) dev FROM :TABLE
)
SELECT * FROM devices;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX WITH devices AS (
	SELECT DISTINCT dev FROM :TABLE
)
SELECT * FROM devices ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

-- prepared statements
PREPARE prep AS SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev_name
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev_name
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev_name
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev_name > NULL::text)

DEALLOCATE prep;
-- ReScan tests
:PREFIX SELECT time, dev, val, 'q7_1' FROM (SELECT DISTINCT ON (dev) * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT * FROM :TABLE WHERE time != a.v) b) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Nested Loop (actual rows=20020.00 loops=1)
               Join Filter: (skip_scan_ht."time" <> "*VALUES*".column1)
               Rows Removed by Join Filter: 20
               ->  Merge Append (actual rows=10020.00 loops=1)
                     Sort Key: skip_scan_ht.dev
                     ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
                     ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
                     ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
                     ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=2505.00 loops=1)
               ->  Materialize (actual rows=2.00 loops=10020)
                     ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)

:PREFIX SELECT time, dev, val, 'q7_2' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev != a.v) b) a;
--- QUERY PLAN ---
 Nested Loop (actual rows=18.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Result (actual rows=9.00 loops=2)
         ->  Unique (actual rows=9.00 loops=2)
               ->  Merge Append (actual rows=36.00 loops=2)
                     Sort Key: skip_scan_ht.dev
                     ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=9.00 loops=2)
                           ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=9.00 loops=2)
                                 Filter: (dev <> "*VALUES*".column1)
                                 Rows Removed by Filter: 250
                     ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=9.00 loops=2)
                           ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=9.00 loops=2)
                                 Filter: (dev <> "*VALUES*".column1)
                                 Rows Removed by Filter: 250
                     ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=9.00 loops=2)
                           ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=9.00 loops=2)
                                 Filter: (dev <> "*VALUES*".column1)
                                 Rows Removed by Filter: 250
                     ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=9.00 loops=2)
                           ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=9.00 loops=2)
                                 Filter: (dev <> "*VALUES*".column1)
                                 Rows Removed by Filter: 250

-- RuntimeKeys
:PREFIX SELECT time, dev, val, 'q8_1' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev >= a.v) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=19.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Result (actual rows=10.00 loops=2)
         ->  Unique (actual rows=10.00 loops=2)
               ->  Merge Append (actual rows=38.00 loops=2)
                     Sort Key: skip_scan_ht.dev
                     ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=10.00 loops=2)
                           ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=10.00 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)
                     ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=10.00 loops=2)
                           ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=10.00 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)
                     ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=10.00 loops=2)
                           ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=10.00 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)
                     ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=10.00 loops=2)
                           ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=10.00 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)

-- Emulate multi-column DISTINCT using multiple SkipSkans
:PREFIX SELECT time, dev, val, 'q9_1' FROM (SELECT b.* FROM
    (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
    LATERAL (SELECT DISTINCT ON (time) * FROM :TABLE WHERE dev = a.dev) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=10000.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
   ->  Result (actual rows=909.00 loops=11)
         ->  Unique (actual rows=909.00 loops=11)
               ->  Merge Append (actual rows=909.00 loops=11)
                     Sort Key: skip_scan_ht_1."time"
                     ->  Custom Scan (SkipScan) on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=227.00 loops=11)
                           ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=227.00 loops=11)
                                 Index Cond: (dev = skip_scan_ht.dev)
                     ->  Custom Scan (SkipScan) on _hyper_1_2_chunk _hyper_1_2_chunk_1 (actual rows=227.00 loops=11)
                           ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk _hyper_1_2_chunk_1 (actual rows=227.00 loops=11)
                                 Index Cond: (dev = skip_scan_ht.dev)
                     ->  Custom Scan (SkipScan) on _hyper_1_3_chunk _hyper_1_3_chunk_1 (actual rows=227.00 loops=11)
                           ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk _hyper_1_3_chunk_1 (actual rows=227.00 loops=11)
                                 Index Cond: (dev = skip_scan_ht.dev)
                     ->  Custom Scan (SkipScan) on _hyper_1_4_chunk _hyper_1_4_chunk_1 (actual rows=227.00 loops=11)
                           ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk _hyper_1_4_chunk_1 (actual rows=227.00 loops=11)
                                 Index Cond: (dev = skip_scan_ht.dev)

:PREFIX SELECT time, dev, NULL, 'q9_2' FROM (SELECT b.* FROM
    (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
    LATERAL (SELECT DISTINCT ON (time) dev, time FROM :TABLE WHERE dev = a.dev) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=10000.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
   ->  Unique (actual rows=909.00 loops=11)
         ->  Merge Append (actual rows=909.00 loops=11)
               Sort Key: skip_scan_ht_1."time"
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=227.00 loops=11)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=227.00 loops=11)
                           Index Cond: ((dev = skip_scan_ht.dev) AND ("time" > NULL::integer))
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk _hyper_1_2_chunk_1 (actual rows=227.00 loops=11)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk _hyper_1_2_chunk_1 (actual rows=227.00 loops=11)
                           Index Cond: ((dev = skip_scan_ht.dev) AND ("time" > NULL::integer))
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk _hyper_1_3_chunk_1 (actual rows=227.00 loops=11)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk _hyper_1_3_chunk_1 (actual rows=227.00 loops=11)
                           Index Cond: ((dev = skip_scan_ht.dev) AND ("time" > NULL::integer))
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk _hyper_1_4_chunk_1 (actual rows=227.00 loops=11)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk _hyper_1_4_chunk_1 (actual rows=227.00 loops=11)
                           Index Cond: ((dev = skip_scan_ht.dev) AND ("time" > NULL::integer))

-- Test that the multi-column DISTINCT emulation is equivalent to a real multi-column DISTINCT
:PREFIX SELECT * FROM
   (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
   LATERAL (SELECT DISTINCT ON (time) dev, time FROM :TABLE WHERE dev = a.dev) b;
--- QUERY PLAN ---
 Nested Loop (actual rows=10000.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_ht.dev
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                           Index Cond: (dev > NULL::integer)
   ->  Unique (actual rows=909.00 loops=11)
         ->  Merge Append (actual rows=909.00 loops=11)
               Sort Key: skip_scan_ht_1."time"
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=227.00 loops=11)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=227.00 loops=11)
                           Index Cond: ((dev = skip_scan_ht.dev) AND ("time" > NULL::integer))
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk _hyper_1_2_chunk_1 (actual rows=227.00 loops=11)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk _hyper_1_2_chunk_1 (actual rows=227.00 loops=11)
                           Index Cond: ((dev = skip_scan_ht.dev) AND ("time" > NULL::integer))
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk _hyper_1_3_chunk_1 (actual rows=227.00 loops=11)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk _hyper_1_3_chunk_1 (actual rows=227.00 loops=11)
                           Index Cond: ((dev = skip_scan_ht.dev) AND ("time" > NULL::integer))
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk _hyper_1_4_chunk_1 (actual rows=227.00 loops=11)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk _hyper_1_4_chunk_1 (actual rows=227.00 loops=11)
                           Index Cond: ((dev = skip_scan_ht.dev) AND ("time" > NULL::integer))

:PREFIX SELECT DISTINCT ON (dev, time) dev, time FROM :TABLE WHERE coalesce(dev, -1) >= 0;
--- QUERY PLAN ---
 Unique (actual rows=10000.00 loops=1)
   ->  Merge Append (actual rows=10000.00 loops=1)
         Sort Key: skip_scan_ht.dev, skip_scan_ht."time"
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=2500.00 loops=1)
               Filter: (COALESCE(dev, '-1'::integer) >= 0)
               Rows Removed by Filter: 5
         ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk (actual rows=2500.00 loops=1)
               Filter: (COALESCE(dev, '-1'::integer) >= 0)
               Rows Removed by Filter: 5
         ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk (actual rows=2500.00 loops=1)
               Filter: (COALESCE(dev, '-1'::integer) >= 0)
               Rows Removed by Filter: 5
         ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk (actual rows=2500.00 loops=1)
               Filter: (COALESCE(dev, '-1'::integer) >= 0)
               Rows Removed by Filter: 5

:PREFIX SELECT DISTINCT ON (dev, time) dev, time FROM :TABLE WHERE coalesce(dev, -1) >= 0
UNION SELECT b.* FROM
   (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
   LATERAL (SELECT DISTINCT ON (time) dev, time FROM :TABLE WHERE dev = a.dev) b;
--- QUERY PLAN ---
 Unique (actual rows=10000.00 loops=1)
   ->  Sort (actual rows=20000.00 loops=1)
         Sort Key: skip_scan_ht.dev, skip_scan_ht."time"
         Sort Method: quicksort 
         ->  Append (actual rows=20000.00 loops=1)
               ->  Unique (actual rows=10000.00 loops=1)
                     ->  Merge Append (actual rows=10000.00 loops=1)
                           Sort Key: skip_scan_ht.dev, skip_scan_ht."time"
                           ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk (actual rows=2500.00 loops=1)
                                 Filter: (COALESCE(dev, '-1'::integer) >= 0)
                                 Rows Removed by Filter: 5
                           ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk (actual rows=2500.00 loops=1)
                                 Filter: (COALESCE(dev, '-1'::integer) >= 0)
                                 Rows Removed by Filter: 5
                           ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk (actual rows=2500.00 loops=1)
                                 Filter: (COALESCE(dev, '-1'::integer) >= 0)
                                 Rows Removed by Filter: 5
                           ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk (actual rows=2500.00 loops=1)
                                 Filter: (COALESCE(dev, '-1'::integer) >= 0)
                                 Rows Removed by Filter: 5
               ->  Nested Loop (actual rows=10000.00 loops=1)
                     ->  Unique (actual rows=11.00 loops=1)
                           ->  Merge Append (actual rows=44.00 loops=1)
                                 Sort Key: skip_scan_ht_1.dev
                                 ->  Custom Scan (SkipScan) on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=11.00 loops=1)
                                       ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk _hyper_1_1_chunk_1 (actual rows=11.00 loops=1)
                                             Index Cond: (dev > NULL::integer)
                                 ->  Custom Scan (SkipScan) on _hyper_1_2_chunk _hyper_1_2_chunk_1 (actual rows=11.00 loops=1)
                                       ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk _hyper_1_2_chunk_1 (actual rows=11.00 loops=1)
                                             Index Cond: (dev > NULL::integer)
                                 ->  Custom Scan (SkipScan) on _hyper_1_3_chunk _hyper_1_3_chunk_1 (actual rows=11.00 loops=1)
                                       ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk _hyper_1_3_chunk_1 (actual rows=11.00 loops=1)
                                             Index Cond: (dev > NULL::integer)
                                 ->  Custom Scan (SkipScan) on _hyper_1_4_chunk _hyper_1_4_chunk_1 (actual rows=11.00 loops=1)
                                       ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk _hyper_1_4_chunk_1 (actual rows=11.00 loops=1)
                                             Index Cond: (dev > NULL::integer)
                     ->  Unique (actual rows=909.00 loops=11)
                           ->  Merge Append (actual rows=909.00 loops=11)
                                 Sort Key: skip_scan_ht_2."time"
                                 ->  Custom Scan (SkipScan) on _hyper_1_1_chunk _hyper_1_1_chunk_2 (actual rows=227.00 loops=11)
                                       ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_time_idx on _hyper_1_1_chunk _hyper_1_1_chunk_2 (actual rows=227.00 loops=11)
                                             Index Cond: ((dev = skip_scan_ht_1.dev) AND ("time" > NULL::integer))
                                 ->  Custom Scan (SkipScan) on _hyper_1_2_chunk _hyper_1_2_chunk_2 (actual rows=227.00 loops=11)
                                       ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_time_idx on _hyper_1_2_chunk _hyper_1_2_chunk_2 (actual rows=227.00 loops=11)
                                             Index Cond: ((dev = skip_scan_ht_1.dev) AND ("time" > NULL::integer))
                                 ->  Custom Scan (SkipScan) on _hyper_1_3_chunk _hyper_1_3_chunk_2 (actual rows=227.00 loops=11)
                                       ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_time_idx on _hyper_1_3_chunk _hyper_1_3_chunk_2 (actual rows=227.00 loops=11)
                                             Index Cond: ((dev = skip_scan_ht_1.dev) AND ("time" > NULL::integer))
                                 ->  Custom Scan (SkipScan) on _hyper_1_4_chunk _hyper_1_4_chunk_2 (actual rows=227.00 loops=11)
                                       ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_time_idx on _hyper_1_4_chunk _hyper_1_4_chunk_2 (actual rows=227.00 loops=11)
                                             Index Cond: ((dev = skip_scan_ht_1.dev) AND ("time" > NULL::integer))

-- SkipScan into INSERT
:PREFIX INSERT INTO skip_scan_insert(time, dev, val, query) SELECT time, dev, val, 'q10_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a;
--- QUERY PLAN ---
 Insert on skip_scan_insert (actual rows=0.00 loops=1)
   ->  Subquery Scan on a (actual rows=11.00 loops=1)
         ->  Result (actual rows=11.00 loops=1)
               ->  Unique (actual rows=11.00 loops=1)
                     ->  Merge Append (actual rows=44.00 loops=1)
                           Sort Key: skip_scan_ht.dev
                           ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)

-- parallel query
SELECT set_config(CASE WHEN current_setting('server_version_num')::int < 160000 THEN 'force_parallel_mode' ELSE 'debug_parallel_query' END,'on', false);
 set_config 
------------
 on

:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

SELECT set_config(CASE WHEN current_setting('server_version_num')::int < 160000 THEN 'force_parallel_mode' ELSE 'debug_parallel_query' END,'off', false);
 set_config 
------------
 off

TRUNCATE skip_scan_insert;
-- table with only nulls
:PREFIX SELECT DISTINCT ON (time) time FROM skip_scan_nulls;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan_nulls (actual rows=1.00 loops=1)
         ->  Index Only Scan using skip_scan_nulls_time_idx on skip_scan_nulls (actual rows=1.00 loops=1)
               Index Cond: ("time" > NULL::integer)

-- no tuples in resultset
:PREFIX SELECT DISTINCT ON (time) time FROM skip_scan_nulls WHERE time IS NOT NULL;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan_nulls (actual rows=0.00 loops=1)
         ->  Index Only Scan using skip_scan_nulls_time_idx on skip_scan_nulls (actual rows=0.00 loops=1)
               Index Cond: (("time" > NULL::integer) AND ("time" IS NOT NULL))

-- Test for SDC issue #2976
-- We should use index "btree ("time", dev, dev_name)" where "dev_name" index key is #3 but we have 2 index quals including SkipScan qual
-- We should not drop qual on "dev_name"
CREATE INDEX skip_scan_idx_time_dev_dname ON :TABLE(time,dev,dev_name);
:PREFIX SELECT DISTINCT time FROM :TABLE WHERE dev_name IS NULL ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=20.00 loops=1)
   ->  Custom Scan (ChunkAppend) on skip_scan_ht (actual rows=20.00 loops=1)
         Order: skip_scan_ht."time"
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=5.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_idx_time_dev_dname on _hyper_1_1_chunk (actual rows=5.00 loops=1)
                     Index Cond: (("time" > NULL::integer) AND (dev_name IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=5.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_idx_time_dev_dname on _hyper_1_2_chunk (actual rows=5.00 loops=1)
                     Index Cond: (("time" > NULL::integer) AND (dev_name IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=5.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_idx_time_dev_dname on _hyper_1_3_chunk (actual rows=5.00 loops=1)
                     Index Cond: (("time" > NULL::integer) AND (dev_name IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=5.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_idx_time_dev_dname on _hyper_1_4_chunk (actual rows=5.00 loops=1)
                     Index Cond: (("time" > NULL::integer) AND (dev_name IS NULL))

DROP INDEX skip_scan_idx_time_dev_dname;
-- "dev_name" is not a key column: it's not in the index quals and should be a filter
CREATE INDEX skip_scan_idx_time_dev_dname ON :TABLE(time,dev) INCLUDE(dev_name);
:PREFIX SELECT DISTINCT time FROM :TABLE WHERE dev_name IS NULL ORDER BY 1;
--- QUERY PLAN ---
 Unique (actual rows=20.00 loops=1)
   ->  Custom Scan (ChunkAppend) on skip_scan_ht (actual rows=20.00 loops=1)
         Order: skip_scan_ht."time"
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=5.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_time_dev_idx on _hyper_1_1_chunk (actual rows=5.00 loops=1)
                     Filter: (dev_name IS NULL)
                     Rows Removed by Filter: 2500
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=5.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_time_dev_idx on _hyper_1_2_chunk (actual rows=5.00 loops=1)
                     Filter: (dev_name IS NULL)
                     Rows Removed by Filter: 2500
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=5.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_time_dev_idx on _hyper_1_3_chunk (actual rows=5.00 loops=1)
                     Filter: (dev_name IS NULL)
                     Rows Removed by Filter: 2500
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=5.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_time_dev_idx on _hyper_1_4_chunk (actual rows=5.00 loops=1)
                     Filter: (dev_name IS NULL)
                     Rows Removed by Filter: 2500

DROP INDEX skip_scan_idx_time_dev_dname;
\ir include/skip_scan_query_ht.sql
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
CREATE INDEX ON :TABLE(dev);
CREATE INDEX ON :TABLE(time);
-- To test scenarios with SkipScan/no SkipScan over a mix of uncompressed and compressed chunks
SET timescaledb.enable_compressed_skipscan TO false;
-- SkipScan with ordered append
:PREFIX SELECT DISTINCT ON (time) time FROM :TABLE ORDER BY time;
--- QUERY PLAN ---
 Unique (actual rows=1000.00 loops=1)
   ->  Custom Scan (ChunkAppend) on skip_scan_ht (actual rows=1000.00 loops=1)
         Order: skip_scan_ht."time"
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=250.00 loops=1)
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_time_idx on _hyper_1_1_chunk (actual rows=250.00 loops=1)
                     Index Cond: ("time" > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=250.00 loops=1)
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_time_idx on _hyper_1_2_chunk (actual rows=250.00 loops=1)
                     Index Cond: ("time" > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=250.00 loops=1)
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_time_idx on _hyper_1_3_chunk (actual rows=250.00 loops=1)
                     Index Cond: ("time" > NULL::integer)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=250.00 loops=1)
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_time_idx on _hyper_1_4_chunk (actual rows=250.00 loops=1)
                     Index Cond: ("time" > NULL::integer)

--baseline query with skipscan
:PREFIX SELECT DISTINCT ON (dev) dev, dev_name FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx1 on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx1 on _hyper_1_2_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx1 on _hyper_1_3_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx1 on _hyper_1_4_chunk (actual rows=11.00 loops=1)

-- compression doesnt prevent skipscan
SELECT compress_chunk('_timescaledb_internal._hyper_1_1_chunk');
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk

:PREFIX SELECT DISTINCT ON (dev) dev, dev_name FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=2538.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
               ->  Index Scan using compress_hyper_2_17_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_2_17_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx1 on _hyper_1_2_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx1 on _hyper_1_3_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx1 on _hyper_1_4_chunk (actual rows=11.00 loops=1)

SELECT decompress_chunk('_timescaledb_internal._hyper_1_1_chunk');
            decompress_chunk            
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk

--baseline query with skipscan
:PREFIX SELECT DISTINCT ON (dev) dev, dev_name FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx1 on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx1 on _hyper_1_2_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx1 on _hyper_1_3_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx1 on _hyper_1_4_chunk (actual rows=11.00 loops=1)

-- partial indexes don't prevent skipscan
DROP INDEX _timescaledb_internal._hyper_1_1_chunk_skip_scan_ht_dev_idx;
:PREFIX SELECT DISTINCT ON (dev) dev, dev_name FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx1 on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx1 on _hyper_1_2_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx1 on _hyper_1_3_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=11.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx1 on _hyper_1_4_chunk (actual rows=11.00 loops=1)

-- IndexPath without pathkeys doesnt use SkipScan
EXPLAIN (buffers off, costs off, timing off, summary off) SELECT DISTINCT 1 FROM pg_rewrite;
--- QUERY PLAN ---
 Unique
   ->  Index Only Scan using pg_rewrite_rel_rulename_index on pg_rewrite

RESET timescaledb.enable_compressed_skipscan;
-- run tests on compressed hypertable with different compression settings
\set TABLE skip_scan_htc
\ir include/skip_scan_comp_query.sql
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
-- canary for result diff
SELECT current_setting('timescaledb.enable_compressed_skipscan') AS enable_compressed_skipscan;
 enable_compressed_skipscan 
----------------------------
 on

-- To avoid ambiguity in test EXPLAIN outputs due to mixing of chunk plans with no SkipScan
SET max_parallel_workers_per_gather = 0;
-- test different compression configurations
-- compressed index on "segmentby='dev'" has default "dev ASC, NULLS LAST" sort order
ALTER TABLE skip_scan_htc SET (timescaledb.compress, timescaledb.compress_orderby='time desc', timescaledb.compress_segmentby='dev');
SELECT compress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

-- SkipScan used when sort order on distinct column "dev" matches "segmentby" sort order
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_19_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_19_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_20_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_20_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_21_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_21_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev DESC;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev DESC
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_19_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_19_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_20_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_20_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_21_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_21_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev DESC NULLS FIRST;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev DESC
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_19_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_19_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_20_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_20_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_21_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_21_chunk (actual rows=11.00 loops=1)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE dev IS NOT NULL ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=10.00 loops=1)
   ->  Merge Append (actual rows=40.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_19_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_19_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_20_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_20_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_21_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_21_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)

:PREFIX SELECT DISTINCT dev FROM :TABLE WHERE dev IS NOT NULL ORDER BY dev DESC NULLS FIRST;
--- QUERY PLAN ---
 Unique (actual rows=10.00 loops=1)
   ->  Merge Append (actual rows=40.00 loops=1)
         Sort Key: skip_scan_htc.dev DESC
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_19_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_19_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_20_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_20_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_21_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_21_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_19_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_19_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_20_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_20_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_21_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_21_chunk (actual rows=11.00 loops=1)

-- NULLS FIRST doesn't match segmentby NULL direction
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev NULLS FIRST;
--- QUERY PLAN ---
 Sort (actual rows=11.00 loops=1)
   Sort Key: skip_scan_htc.dev NULLS FIRST
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_htc.dev
         ->  Append (actual rows=10020.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_18_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_19_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_20_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_21_chunk (actual rows=11.00 loops=1)

-- multicolumn sort with dev as leading column matching (segmentby dev, order by time DESC) compression index
:PREFIX SELECT DISTINCT ON (dev) dev, time FROM :TABLE ORDER BY dev, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev, skip_scan_htc."time" DESC
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_19_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_19_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_20_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_20_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_21_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_21_chunk (actual rows=11.00 loops=1)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT ON (dev) dev, time FROM :TABLE WHERE dev IS NOT NULL ORDER BY dev, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=10.00 loops=1)
   ->  Merge Append (actual rows=40.00 loops=1)
         Sort Key: skip_scan_htc.dev, skip_scan_htc."time" DESC
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_19_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_19_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_20_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_20_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_21_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_21_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)

:PREFIX SELECT DISTINCT ON (dev) dev, time FROM :TABLE ORDER BY dev DESC, time;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev DESC, skip_scan_htc."time"
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_19_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_19_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_20_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_20_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_21_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_21_chunk (actual rows=11.00 loops=1)

-- multicolumn sort not matching compression index
:PREFIX SELECT DISTINCT ON (dev) dev, time FROM :TABLE ORDER BY dev DESC, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_htc.dev DESC, skip_scan_htc."time" DESC
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_18_chunk.dev DESC, compress_hyper_4_18_chunk._ts_meta_min_1 DESC, compress_hyper_4_18_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_4_18_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_19_chunk.dev DESC, compress_hyper_4_19_chunk._ts_meta_min_1 DESC, compress_hyper_4_19_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_4_19_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_20_chunk.dev DESC, compress_hyper_4_20_chunk._ts_meta_min_1 DESC, compress_hyper_4_20_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_4_20_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_21_chunk.dev DESC, compress_hyper_4_21_chunk._ts_meta_min_1 DESC, compress_hyper_4_21_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_4_21_chunk (actual rows=11.00 loops=1)

-- same result when we use compressed IndexPath with pathkeys not matching DecompressChunk path required path keys
SET enable_seqscan TO false;
:PREFIX SELECT DISTINCT ON (dev) dev, time FROM :TABLE ORDER BY dev DESC, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_htc.dev DESC, skip_scan_htc."time" DESC
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_18_chunk.dev DESC, compress_hyper_4_18_chunk._ts_meta_min_1 DESC, compress_hyper_4_18_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Index Scan Backward using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_19_chunk.dev DESC, compress_hyper_4_19_chunk._ts_meta_min_1 DESC, compress_hyper_4_19_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Index Scan Backward using compress_hyper_4_19_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_19_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_20_chunk.dev DESC, compress_hyper_4_20_chunk._ts_meta_min_1 DESC, compress_hyper_4_20_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Index Scan Backward using compress_hyper_4_20_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_20_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_21_chunk.dev DESC, compress_hyper_4_21_chunk._ts_meta_min_1 DESC, compress_hyper_4_21_chunk._ts_meta_max_1 DESC
                     Sort Method: quicksort 
                     ->  Index Scan Backward using compress_hyper_4_21_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_21_chunk (actual rows=11.00 loops=1)

RESET enable_seqscan;
-- Distinct column not a segmentby column: should be no SkipScan
:PREFIX SELECT DISTINCT time FROM :TABLE WHERE dev = 1 ORDER BY time DESC;
--- QUERY PLAN ---
 Unique (actual rows=1000.00 loops=1)
   ->  Custom Scan (ChunkAppend) on skip_scan_htc (actual rows=1000.00 loops=1)
         Order: skip_scan_htc."time" DESC
         ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=250.00 loops=1)
               ->  Index Scan using compress_hyper_4_21_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_21_chunk (actual rows=1.00 loops=1)
                     Index Cond: (dev = 1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=250.00 loops=1)
               ->  Index Scan using compress_hyper_4_20_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_20_chunk (actual rows=1.00 loops=1)
                     Index Cond: (dev = 1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=250.00 loops=1)
               ->  Index Scan using compress_hyper_4_19_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_19_chunk (actual rows=1.00 loops=1)
                     Index Cond: (dev = 1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=250.00 loops=1)
               ->  Index Scan using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=1.00 loops=1)
                     Index Cond: (dev = 1)

-- multicolumn sort with dev as non-leading column and with leading column pinned
-- we are able to apply SkipScan here after resolving #7998
:PREFIX SELECT DISTINCT time, dev FROM :TABLE WHERE time = 100 ORDER BY time, dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               Vectorized Filter: ("time" = 100)
               Rows Removed by Filter: 1492
               ->  Index Scan using compress_hyper_4_18_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_18_chunk (actual rows=11.00 loops=1)
                     Index Cond: ((_ts_meta_min_1 <= 100) AND (_ts_meta_max_1 >= 100))

-- multicolumn "segmentby = 'dev, dev_name'"
SELECT decompress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
            decompress_chunk            
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

ALTER TABLE skip_scan_htc SET (timescaledb.compress, timescaledb.compress_orderby='time desc', timescaledb.compress_segmentby='dev,dev_name');
SELECT compress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

-- dev is leading column
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_22_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_22_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_23_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_23_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_24_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_24_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_25_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_25_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_22_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_22_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_23_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_23_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_24_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_24_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_25_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_25_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, dev_name FROM :TABLE ORDER BY dev, dev_name;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev, skip_scan_htc.dev_name
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_22_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_22_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_23_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_23_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_24_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_24_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_25_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_25_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, dev_name FROM :TABLE ORDER BY dev DESC, dev_name DESC;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev DESC, skip_scan_htc.dev_name DESC
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_22_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_22_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_23_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_23_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_24_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_24_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_25_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_25_chunk (actual rows=11.00 loops=1)

-- query sort doesn't match "segmentby" sort
:PREFIX SELECT DISTINCT ON (dev) dev, dev_name FROM :TABLE ORDER BY dev, dev_name DESC;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_htc.dev, skip_scan_htc.dev_name DESC
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_22_chunk.dev, compress_hyper_4_22_chunk.dev_name DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_4_22_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_23_chunk.dev, compress_hyper_4_23_chunk.dev_name DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_4_23_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_24_chunk.dev, compress_hyper_4_24_chunk.dev_name DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_4_24_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
               ->  Sort (actual rows=11.00 loops=1)
                     Sort Key: compress_hyper_4_25_chunk.dev, compress_hyper_4_25_chunk.dev_name DESC
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_4_25_chunk (actual rows=11.00 loops=1)

-- dev_name is not a leading column
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE dev = 1 ORDER BY dev_name;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_htc.dev_name
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_22_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_22_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_23_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_23_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_24_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_24_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_25_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_25_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT dev_name FROM :TABLE WHERE dev = 1 AND dev_name IS NOT NULL ORDER BY dev_name;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_htc.dev_name
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_22_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_22_chunk (actual rows=1.00 loops=1)
                           Index Cond: ((dev = 1) AND (dev_name IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_23_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_23_chunk (actual rows=1.00 loops=1)
                           Index Cond: ((dev = 1) AND (dev_name IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_24_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_24_chunk (actual rows=1.00 loops=1)
                           Index Cond: ((dev = 1) AND (dev_name IS NOT NULL))
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_25_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_25_chunk (actual rows=1.00 loops=1)
                           Index Cond: ((dev = 1) AND (dev_name IS NOT NULL))

:PREFIX SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE WHERE dev = 1;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_htc.dev_name
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_22_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_22_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_23_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_23_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_24_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_24_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_25_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_25_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)

-- Basic tests for "segmentby = 'dev'"
-----------------------------------------
SELECT decompress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
            decompress_chunk            
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

ALTER TABLE skip_scan_htc SET (timescaledb.compress, timescaledb.compress_orderby='time desc', timescaledb.compress_segmentby='dev');
SELECT compress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

\qecho basic DISTINCT queries on :TABLE
basic DISTINCT queries on skip_scan_htc
:PREFIX SELECT DISTINCT dev, 'q1_1' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT dev, 'q1_3', NULL FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

\qecho stable expression in targetlist on :TABLE
stable expression in targetlist on skip_scan_htc
:PREFIX SELECT DISTINCT dev, 'q1_4', length(md5(now()::text)) FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

-- volatile expression in targetlist counts as extra distinct column, no SkipScan
:PREFIX SELECT DISTINCT dev, 'q1_6', length(md5(random()::text)) FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Sort (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_htc.dev, (length(md5((random())::text)))
         Sort Method: quicksort 
         ->  Result (actual rows=10020.00 loops=1)
               ->  Append (actual rows=10020.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

-- queries without skipscan because distinct is not limited to specific column
:PREFIX SELECT DISTINCT * FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=10020.00 loops=1)
   Sort Key: skip_scan_htc.dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=10020.00 loops=1)
         Group Key: skip_scan_htc.dev, skip_scan_htc."time", skip_scan_htc.dev_name, skip_scan_htc.val
         ->  Append (actual rows=10020.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT *, 'q1_9' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=10020.00 loops=1)
   Sort Key: skip_scan_htc.dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=10020.00 loops=1)
         Group Key: skip_scan_htc.dev, skip_scan_htc."time", skip_scan_htc.dev_name, skip_scan_htc.val, 'q1_9'::text
         ->  Result (actual rows=10020.00 loops=1)
               ->  Append (actual rows=10020.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT dev, time, 'q1_10' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=10020.00 loops=1)
   Sort Key: skip_scan_htc.dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=10020.00 loops=1)
         Group Key: skip_scan_htc.dev, skip_scan_htc."time", 'q1_10'::text
         ->  Result (actual rows=10020.00 loops=1)
               ->  Append (actual rows=10020.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

-- use SkipScan as only one non-const distinct column
:PREFIX SELECT DISTINCT dev, NULL, 'q1_11' FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

-- distinct on expressions not supported
:PREFIX SELECT DISTINCT dev + 1, 'q1_13' FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=11.00 loops=1)
   Group Key: (skip_scan_htc.dev + 1), 'q1_13'::text
   ->  Result (actual rows=10020.00 loops=1)
         ->  Append (actual rows=10020.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

-- DISTINCT ON queries
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE dev_name IS NOT NULL;
--- QUERY PLAN ---
 Unique (actual rows=10.00 loops=1)
   ->  Merge Append (actual rows=40.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=10.00 loops=1)
                     Vectorized Filter: (dev_name IS NOT NULL)
                     Rows Removed by Filter: 5
                     ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=10.00 loops=1)
                     Vectorized Filter: (dev_name IS NOT NULL)
                     Rows Removed by Filter: 5
                     ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=10.00 loops=1)
                     Vectorized Filter: (dev_name IS NOT NULL)
                     Rows Removed by Filter: 5
                     ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=10.00 loops=1)
                     Vectorized Filter: (dev_name IS NOT NULL)
                     Rows Removed by Filter: 5
                     ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_2' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_3', NULL FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_4', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_5', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) *, 'q2_7' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, time, 'q2_8' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, NULL, 'q2_9' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) time, 'q2_10' FROM :TABLE ORDER by dev, time DESC;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev, skip_scan_htc."time" DESC
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, tableoid::regclass, 'q2_11' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_immutable(), 'q2_12' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_stable(), 'q2_13' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_volatile(), 'q2_14' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

\qecho DISTINCT with wholerow var
DISTINCT with wholerow var
:PREFIX SELECT DISTINCT ON (dev) :TABLE FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

-- should not use SkipScan since we only support SkipScan on single-column distinct
:PREFIX SELECT DISTINCT :TABLE FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=10020.00 loops=1)
   Group Key: ((skip_scan_htc.*)::skip_scan_htc)
   ->  Append (actual rows=10020.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on compress_hyper_4_28_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
               ->  Seq Scan on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)

\qecho LIMIT queries on :TABLE
LIMIT queries on skip_scan_htc
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Merge Append (actual rows=9.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=3.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev DESC, time LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Merge Append (actual rows=9.00 loops=1)
               Sort Key: skip_scan_htc.dev DESC, skip_scan_htc."time"
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan Backward using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan Backward using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan Backward using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan Backward using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=3.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev, time DESC LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Merge Append (actual rows=9.00 loops=1)
               Sort Key: skip_scan_htc.dev, skip_scan_htc."time" DESC
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_28_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_28_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=3.00 loops=1)

\qecho range queries on :TABLE
range queries on skip_scan_htc
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time BETWEEN 100 AND 300;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=22.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     Vectorized Filter: (("time" >= 100) AND ("time" <= 300))
                     ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
                           Index Cond: ((_ts_meta_min_1 <= 300) AND (_ts_meta_max_1 >= 100))
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     Vectorized Filter: (("time" >= 100) AND ("time" <= 300))
                     Rows Removed by Filter: 1993
                     ->  Index Scan using compress_hyper_4_27_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_27_chunk (actual rows=11.00 loops=1)
                           Index Cond: ((_ts_meta_min_1 <= 300) AND (_ts_meta_max_1 >= 100))

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time < 200;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               Vectorized Filter: ("time" < 200)
               Rows Removed by Filter: 501
               ->  Index Scan using compress_hyper_4_26_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_26_chunk (actual rows=11.00 loops=1)
                     Index Cond: (_ts_meta_min_1 < 200)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time > 800;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               Vectorized Filter: ("time" > 800)
               ->  Index Scan using compress_hyper_4_29_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_29_chunk (actual rows=11.00 loops=1)
                     Index Cond: (_ts_meta_max_1 > 800)

-- Basic tests for text index "segmentby = 'dev_name'"
------------------------------------------------------
SELECT decompress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
            decompress_chunk            
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

ALTER TABLE skip_scan_htc SET (timescaledb.compress, timescaledb.compress_orderby='time desc', timescaledb.compress_segmentby='dev_name');
SELECT compress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

:PREFIX SELECT DISTINCT dev_name, 'q1_2' FROM :TABLE ORDER BY dev_name;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

\qecho stable expression in targetlist on :TABLE
stable expression in targetlist on skip_scan_htc
:PREFIX SELECT DISTINCT dev_name, 'q1_5', length(md5(now()::text)) FROM :TABLE ORDER BY dev_name;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

-- volatile expression in targetlist counts as extra distinct column, no SkipScan
:PREFIX SELECT DISTINCT dev_name, 'q1_7', length(md5(random()::text)) FROM :TABLE ORDER BY dev_name;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Sort (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_htc.dev_name, (length(md5((random())::text)))
         Sort Method: quicksort 
         ->  Result (actual rows=10020.00 loops=1)
               ->  Append (actual rows=10020.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
                           ->  Seq Scan on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

-- distinct on expressions not supported
:PREFIX SELECT DISTINCT 'Device ' || dev_name FROM :TABLE;
--- QUERY PLAN ---
 HashAggregate (actual rows=11.00 loops=1)
   Group Key: ('Device '::text || skip_scan_htc.dev_name)
   ->  Result (actual rows=10020.00 loops=1)
         ->  Append (actual rows=10020.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
                     ->  Seq Scan on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

-- DISTINCT ON queries on TEXT column
:PREFIX SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev_name
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

-- Test not-NULL mode
:PREFIX SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE WHERE dev_name IS NOT NULL;
--- QUERY PLAN ---
 Unique (actual rows=10.00 loops=1)
   ->  Merge Append (actual rows=40.00 loops=1)
         Sort Key: skip_scan_htc.dev_name
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev_name IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev_name IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev_name IS NOT NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=10.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=10.00 loops=1)
                     ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev_name IS NOT NULL)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_2' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_3', NULL FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_4', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, 'q3_5', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) * FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev_name
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) *, 'q3_7' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, time, 'q3_8' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, NULL, 'q3_9' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) time, 'q3_10' FROM :TABLE ORDER by dev_name, time DESC;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name, skip_scan_htc."time" DESC
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name, tableoid::regclass, 'q3_11' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name::varchar) dev_name::varchar FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev, int_func_immutable(), 'q3_13' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev, int_func_stable(), 'q3_14' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev, int_func_volatile(), 'q3_15' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev_name
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev_name) dev_name FROM :TABLE WHERE dev_name IS NULL;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_htc.dev_name
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_30_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_30_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev_name IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_31_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_31_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev_name IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_32_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_32_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev_name IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_33_chunk_dev_name__ts_meta_min_1__ts_meta__idx on compress_hyper_4_33_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev_name IS NULL)

-- Various tests for "segmentby = 'dev'"
---------------------------------------
SELECT decompress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
            decompress_chunk            
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

ALTER TABLE skip_scan_htc SET (timescaledb.compress, timescaledb.compress_orderby='time', timescaledb.compress_segmentby='dev');
SELECT compress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

\qecho SUBSELECTS on :TABLE
SUBSELECTS on skip_scan_htc
:PREFIX SELECT time, dev, val, 'q4_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_htc.dev
                     ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT NULL, dev, NULL, 'q4_3' FROM (SELECT DISTINCT ON (dev) dev FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT time, dev, NULL, 'q4_4' FROM (SELECT DISTINCT ON (dev) dev, time FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

\qecho ORDER BY
ORDER BY
:PREFIX SELECT time, dev, val, 'q5_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE ORDER BY dev, time) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_htc.dev, skip_scan_htc."time"
                     ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT time, dev, val, 'q5_2' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE ORDER BY dev DESC, time DESC) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_htc.dev DESC, skip_scan_htc."time" DESC
                     ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan Backward using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan Backward using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan Backward using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan Backward using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

\qecho WHERE CLAUSES
WHERE CLAUSES
:PREFIX SELECT time, dev, val, 'q6_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > 5) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  Result (actual rows=5.00 loops=1)
         ->  Unique (actual rows=5.00 loops=1)
               ->  Merge Append (actual rows=20.00 loops=1)
                     Sort Key: skip_scan_htc.dev
                     ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)

:PREFIX SELECT time, dev, val, 'q6_2' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE time > 5) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_htc.dev
                     ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                                 Vectorized Filter: ("time" > 5)
                                 Rows Removed by Filter: 61
                                 ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
                                       Index Cond: (_ts_meta_max_1 > 5)
                     ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT time, dev, val, 'q6_3' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a WHERE dev > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  Result (actual rows=5.00 loops=1)
         ->  Unique (actual rows=5.00 loops=1)
               ->  Merge Append (actual rows=20.00 loops=1)
                     Sort Key: skip_scan_htc.dev
                     ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)

:PREFIX SELECT time, dev, val, 'q6_4' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a WHERE time > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=7.00 loops=1)
   Filter: (a."time" > 5)
   Rows Removed by Filter: 4
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_htc.dev
                     ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

--\qecho immutable func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) *, 'q6_5' FROM :TABLE WHERE dev > int_func_immutable();
--- QUERY PLAN ---
 Result (actual rows=9.00 loops=1)
   ->  Unique (actual rows=9.00 loops=1)
         ->  Merge Append (actual rows=36.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=9.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=9.00 loops=1)
                           ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=9.00 loops=1)
                                 Index Cond: (dev > 1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=9.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=9.00 loops=1)
                           ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=9.00 loops=1)
                                 Index Cond: (dev > 1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=9.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=9.00 loops=1)
                           ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=9.00 loops=1)
                                 Index Cond: (dev > 1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=9.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=9.00 loops=1)
                           ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=9.00 loops=1)
                                 Index Cond: (dev > 1)

--\qecho stable func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) *, 'q6_6' FROM :TABLE WHERE dev > int_func_stable();
--- QUERY PLAN ---
 Result (actual rows=8.00 loops=1)
   ->  Unique (actual rows=8.00 loops=1)
         ->  Custom Scan (ConstraintAwareAppend) (actual rows=32.00 loops=1)
               Hypertable: skip_scan_htc
               Chunks excluded during startup: 0
               ->  Merge Append (actual rows=32.00 loops=1)
                     Sort Key: skip_scan_htc.dev
                     ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=8.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=8.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=8.00 loops=1)
                                       Index Cond: (dev > int_func_stable())
                     ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=8.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=8.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=8.00 loops=1)
                                       Index Cond: (dev > int_func_stable())
                     ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=8.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=8.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=8.00 loops=1)
                                       Index Cond: (dev > int_func_stable())
                     ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=8.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=8.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=8.00 loops=1)
                                       Index Cond: (dev > int_func_stable())

--\qecho volatile func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > int_func_volatile();
--- QUERY PLAN ---
 Unique (actual rows=7.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=28.00 loops=1)
         Hypertable: skip_scan_htc
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=28.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=7.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755
                           ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=7.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755
                           ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=7.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755
                           ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=7.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755
                           ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_immutable());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Merge Append (actual rows=12.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY ('{1,2,3}'::integer[]))
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY ('{1,2,3}'::integer[]))
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY ('{1,2,3}'::integer[]))
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY ('{1,2,3}'::integer[]))

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_stable());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=12.00 loops=1)
         Hypertable: skip_scan_htc
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=12.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=3.00 loops=1)
                                 Index Cond: (dev = ANY (inta_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=3.00 loops=1)
                                 Index Cond: (dev = ANY (inta_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=3.00 loops=1)
                                 Index Cond: (dev = ANY (inta_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=3.00 loops=1)
                                 Index Cond: (dev = ANY (inta_func_stable()))

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_volatile());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=12.00 loops=1)
         Hypertable: skip_scan_htc
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=12.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755
                           ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755
                           ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755
                           ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755
                           ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

-- RowCompareExpr
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE (dev, time) > (5,100);
--- QUERY PLAN ---
 Unique (actual rows=6.00 loops=1)
   ->  Merge Append (actual rows=24.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=6.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=6.00 loops=1)
                     Filter: (ROW(dev, "time") > ROW(5, 100))
                     Rows Removed by Filter: 1106
                     ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=6.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=6.00 loops=1)
                     Filter: (ROW(dev, "time") > ROW(5, 100))
                     Rows Removed by Filter: 1005
                     ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=6.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=6.00 loops=1)
                     Filter: (ROW(dev, "time") > ROW(5, 100))
                     Rows Removed by Filter: 1005
                     ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=6.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=6.00 loops=1)
                     Filter: (ROW(dev, "time") > ROW(5, 100))
                     Rows Removed by Filter: 1005
                     ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

-- always false expr similar to our initial skip qual
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > NULL;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Sort (actual rows=0.00 loops=1)
         Sort Key: dev
         Sort Method: quicksort 
         ->  Result (actual rows=0.00 loops=1)
               One-Time Filter: false

-- no tuples matching
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > 20;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Merge Append (actual rows=0.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=0.00 loops=1)
                           Index Cond: (dev > 20)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=0.00 loops=1)
                           Index Cond: (dev > 20)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=0.00 loops=1)
                           Index Cond: (dev > 20)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=0.00 loops=1)
                           Index Cond: (dev > 20)

-- multiple constraints in WHERE clause
:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev > 5 AND time = 100;
--- QUERY PLAN ---
 Unique (actual rows=5.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=5.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=5.00 loops=1)
               Vectorized Filter: ("time" = 100)
               Rows Removed by Filter: 500
               ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=5.00 loops=1)
                     Index Cond: ((dev > 5) AND (_ts_meta_min_1 <= 100) AND (_ts_meta_max_1 >= 100))

:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev > 5 AND time > 200;
--- QUERY PLAN ---
 Unique (actual rows=5.00 loops=1)
   ->  Merge Append (actual rows=20.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=5.00 loops=1)
                     Vectorized Filter: ("time" > 200)
                     Rows Removed by Filter: 1005
                     ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=5.00 loops=1)
                           Index Cond: ((dev > 5) AND (_ts_meta_max_1 > 200))
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=5.00 loops=1)
                     ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=5.00 loops=1)
                           Index Cond: (dev > 5)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=5.00 loops=1)
                     ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=5.00 loops=1)
                           Index Cond: (dev > 5)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=5.00 loops=1)
                     ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=5.00 loops=1)
                           Index Cond: (dev > 5)

:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev >= 5 AND dev < 7 AND dev >= 2;
--- QUERY PLAN ---
 Unique (actual rows=2.00 loops=1)
   ->  Merge Append (actual rows=8.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=2.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2.00 loops=1)
                     ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=2.00 loops=1)
                           Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=2.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2.00 loops=1)
                     ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=2.00 loops=1)
                           Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=2.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2.00 loops=1)
                     ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=2.00 loops=1)
                           Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=2.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2.00 loops=1)
                     ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=2.00 loops=1)
                           Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))

:PREFIX SELECT DISTINCT ON (dev) dev,time,val FROM :TABLE WHERE time > 100 AND time < 200 AND val > 10 AND val < 10000 AND dev > 2 AND dev < 7 ORDER BY dev,time;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=0.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=0.00 loops=1)
               Vectorized Filter: (("time" > 100) AND ("time" < 200) AND (val > 10) AND (val < 10000))
               Rows Removed by Filter: 1000
               ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=4.00 loops=1)
                     Index Cond: ((dev > 2) AND (dev < 7) AND (_ts_meta_min_1 < 200) AND (_ts_meta_max_1 > 100))

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE dev IS NULL;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev IS NULL)

-- test constants in ORDER BY
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = 1 ORDER BY dev, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_htc."time" DESC
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)

-- CTE
:PREFIX WITH devices AS (
	SELECT DISTINCT ON (dev) dev FROM :TABLE
)
SELECT * FROM devices;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

:PREFIX WITH devices AS (
	SELECT DISTINCT dev FROM :TABLE
)
SELECT * FROM devices ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

-- prepared statements
PREPARE prep AS SELECT DISTINCT ON (dev) dev FROM :TABLE;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)

DEALLOCATE prep;
-- ReScan tests
-- no SkipScan as distinct is over subquery
:PREFIX SELECT time, dev, val, 'q7_1' FROM (SELECT DISTINCT ON (dev) * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT * FROM :TABLE WHERE time != a.v) b) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Nested Loop (actual rows=20020.00 loops=1)
               Join Filter: (skip_scan_htc."time" <> "*VALUES*".column1)
               Rows Removed by Join Filter: 20
               ->  Merge Append (actual rows=10020.00 loops=1)
                     Sort Key: skip_scan_htc.dev
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.00 loops=1)
                           ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.00 loops=1)
                           ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.00 loops=1)
                           ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.00 loops=1)
                           ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=11.00 loops=1)
               ->  Materialize (actual rows=2.00 loops=10020)
                     ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)

-- have SkipScan as Distinct is over index
:PREFIX SELECT time, dev, val, 'q7_2' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev != a.v) b) a;
--- QUERY PLAN ---
 Nested Loop (actual rows=18.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Result (actual rows=9.00 loops=2)
         ->  Unique (actual rows=9.00 loops=2)
               ->  Merge Append (actual rows=36.00 loops=2)
                     Sort Key: skip_scan_htc.dev
                     ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=9.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=9.00 loops=2)
                                 ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=9.00 loops=2)
                                       Filter: (dev <> "*VALUES*".column1)
                                       Rows Removed by Filter: 1
                     ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=9.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=9.00 loops=2)
                                 ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=9.00 loops=2)
                                       Filter: (dev <> "*VALUES*".column1)
                                       Rows Removed by Filter: 1
                     ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=9.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=9.00 loops=2)
                                 ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=9.00 loops=2)
                                       Filter: (dev <> "*VALUES*".column1)
                                       Rows Removed by Filter: 1
                     ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=9.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=9.00 loops=2)
                                 ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=9.00 loops=2)
                                       Filter: (dev <> "*VALUES*".column1)
                                       Rows Removed by Filter: 1

-- RuntimeKeys
:PREFIX SELECT time, dev, val, 'q8_1' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev >= a.v) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=19.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Result (actual rows=10.00 loops=2)
         ->  Unique (actual rows=10.00 loops=2)
               ->  Merge Append (actual rows=38.00 loops=2)
                     Sort Key: skip_scan_htc.dev
                     ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=10.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=10.00 loops=2)
                                 ->  Index Scan using compress_hyper_4_34_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_34_chunk (actual rows=10.00 loops=2)
                                       Index Cond: (dev >= "*VALUES*".column1)
                     ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=10.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=10.00 loops=2)
                                 ->  Index Scan using compress_hyper_4_35_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_35_chunk (actual rows=10.00 loops=2)
                                       Index Cond: (dev >= "*VALUES*".column1)
                     ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=10.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=10.00 loops=2)
                                 ->  Index Scan using compress_hyper_4_36_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_36_chunk (actual rows=10.00 loops=2)
                                       Index Cond: (dev >= "*VALUES*".column1)
                     ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=10.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=10.00 loops=2)
                                 ->  Index Scan using compress_hyper_4_37_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_4_37_chunk (actual rows=10.00 loops=2)
                                       Index Cond: (dev >= "*VALUES*".column1)

-- Emulate multi-column DISTINCT using multiple SkipSkans
-- "segmentby = 'dev, val'"
---------------------------------------
SELECT decompress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
            decompress_chunk            
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

ALTER TABLE skip_scan_htc SET (timescaledb.compress, timescaledb.compress_orderby='time', timescaledb.compress_segmentby='dev, val');
SELECT compress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

:PREFIX SELECT time, dev, val, 'q9_1' FROM (SELECT b.* FROM
    (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
    LATERAL (SELECT DISTINCT ON (val) * FROM :TABLE WHERE dev = a.dev) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=20.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk (actual rows=11.00 loops=1)
   ->  Result (actual rows=2.00 loops=11)
         ->  Unique (actual rows=2.00 loops=11)
               ->  Merge Append (actual rows=7.00 loops=11)
                     Sort Key: skip_scan_htc_1.val
                     ->  Custom Scan (SkipScan) on _hyper_3_5_chunk _hyper_3_5_chunk_1 (actual rows=2.00 loops=11)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk _hyper_3_5_chunk_1 (actual rows=2.00 loops=11)
                                 ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk compress_hyper_4_38_chunk_1 (actual rows=2.00 loops=11)
                                       Index Cond: (dev = skip_scan_htc.dev)
                     ->  Custom Scan (SkipScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=2.00 loops=11)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=2.00 loops=11)
                                 ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk compress_hyper_4_39_chunk_1 (actual rows=2.00 loops=11)
                                       Index Cond: (dev = skip_scan_htc.dev)
                     ->  Custom Scan (SkipScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=2.00 loops=11)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=2.00 loops=11)
                                 ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk compress_hyper_4_40_chunk_1 (actual rows=2.00 loops=11)
                                       Index Cond: (dev = skip_scan_htc.dev)
                     ->  Custom Scan (SkipScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=2.00 loops=11)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=2.00 loops=11)
                                 ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk compress_hyper_4_41_chunk_1 (actual rows=2.00 loops=11)
                                       Index Cond: (dev = skip_scan_htc.dev)

:PREFIX SELECT val, dev, NULL, 'q9_2' FROM (SELECT b.* FROM
    (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
    LATERAL (SELECT DISTINCT ON (val) dev, val FROM :TABLE WHERE dev = a.dev) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=20.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk (actual rows=11.00 loops=1)
   ->  Unique (actual rows=2.00 loops=11)
         ->  Merge Append (actual rows=7.00 loops=11)
               Sort Key: skip_scan_htc_1.val
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk _hyper_3_5_chunk_1 (actual rows=2.00 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk _hyper_3_5_chunk_1 (actual rows=2.00 loops=11)
                           ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk compress_hyper_4_38_chunk_1 (actual rows=2.00 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=2.00 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=2.00 loops=11)
                           ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk compress_hyper_4_39_chunk_1 (actual rows=2.00 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=2.00 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=2.00 loops=11)
                           ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk compress_hyper_4_40_chunk_1 (actual rows=2.00 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=2.00 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=2.00 loops=11)
                           ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk compress_hyper_4_41_chunk_1 (actual rows=2.00 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)

-- Test that the multi-column DISTINCT emulation is equivalent to a real multi-column DISTINCT
:PREFIX SELECT * FROM
   (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
   LATERAL (SELECT DISTINCT ON (val) dev, val FROM :TABLE WHERE dev = a.dev) b;
--- QUERY PLAN ---
 Nested Loop (actual rows=20.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk (actual rows=11.00 loops=1)
   ->  Unique (actual rows=2.00 loops=11)
         ->  Merge Append (actual rows=7.00 loops=11)
               Sort Key: skip_scan_htc_1.val
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk _hyper_3_5_chunk_1 (actual rows=2.00 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk _hyper_3_5_chunk_1 (actual rows=2.00 loops=11)
                           ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk compress_hyper_4_38_chunk_1 (actual rows=2.00 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=2.00 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=2.00 loops=11)
                           ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk compress_hyper_4_39_chunk_1 (actual rows=2.00 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=2.00 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=2.00 loops=11)
                           ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk compress_hyper_4_40_chunk_1 (actual rows=2.00 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=2.00 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=2.00 loops=11)
                           ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk compress_hyper_4_41_chunk_1 (actual rows=2.00 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)

-- no SkipScan: 2 distinct columns
:PREFIX SELECT DISTINCT ON (dev, val) dev, val FROM :TABLE WHERE dev IS NOT NULL;
--- QUERY PLAN ---
 Unique (actual rows=20.00 loops=1)
   ->  Merge Append (actual rows=10000.00 loops=1)
         Sort Key: skip_scan_htc.dev, skip_scan_htc.val
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2500.00 loops=1)
               ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk (actual rows=20.00 loops=1)
                     Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2500.00 loops=1)
               ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk (actual rows=20.00 loops=1)
                     Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2500.00 loops=1)
               ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk (actual rows=20.00 loops=1)
                     Index Cond: (dev IS NOT NULL)
         ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2500.00 loops=1)
               ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk (actual rows=20.00 loops=1)
                     Index Cond: (dev IS NOT NULL)

:PREFIX SELECT DISTINCT ON (dev, val) dev, val FROM :TABLE WHERE dev IS NOT NULL
UNION SELECT b.* FROM
   (SELECT DISTINCT ON (dev) dev FROM :TABLE) a,
   LATERAL (SELECT DISTINCT ON (val) dev, val FROM :TABLE WHERE dev = a.dev) b;
--- QUERY PLAN ---
 Unique (actual rows=20.00 loops=1)
   ->  Sort (actual rows=40.00 loops=1)
         Sort Key: skip_scan_htc.dev, skip_scan_htc.val
         Sort Method: quicksort 
         ->  Append (actual rows=40.00 loops=1)
               ->  Unique (actual rows=20.00 loops=1)
                     ->  Merge Append (actual rows=10000.00 loops=1)
                           Sort Key: skip_scan_htc.dev, skip_scan_htc.val
                           ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2500.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk (actual rows=20.00 loops=1)
                                       Index Cond: (dev IS NOT NULL)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2500.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk (actual rows=20.00 loops=1)
                                       Index Cond: (dev IS NOT NULL)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2500.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk (actual rows=20.00 loops=1)
                                       Index Cond: (dev IS NOT NULL)
                           ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2500.00 loops=1)
                                 ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk (actual rows=20.00 loops=1)
                                       Index Cond: (dev IS NOT NULL)
               ->  Nested Loop (actual rows=20.00 loops=1)
                     ->  Unique (actual rows=11.00 loops=1)
                           ->  Merge Append (actual rows=44.00 loops=1)
                                 Sort Key: skip_scan_htc_1.dev
                                 ->  Custom Scan (SkipScan) on _hyper_3_5_chunk _hyper_3_5_chunk_1 (actual rows=11.00 loops=1)
                                       ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk _hyper_3_5_chunk_1 (actual rows=11.00 loops=1)
                                             ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk compress_hyper_4_38_chunk_1 (actual rows=11.00 loops=1)
                                 ->  Custom Scan (SkipScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=11.00 loops=1)
                                       ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=11.00 loops=1)
                                             ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk compress_hyper_4_39_chunk_1 (actual rows=11.00 loops=1)
                                 ->  Custom Scan (SkipScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=11.00 loops=1)
                                       ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=11.00 loops=1)
                                             ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk compress_hyper_4_40_chunk_1 (actual rows=11.00 loops=1)
                                 ->  Custom Scan (SkipScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=11.00 loops=1)
                                       ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=11.00 loops=1)
                                             ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk compress_hyper_4_41_chunk_1 (actual rows=11.00 loops=1)
                     ->  Unique (actual rows=2.00 loops=11)
                           ->  Merge Append (actual rows=7.00 loops=11)
                                 Sort Key: skip_scan_htc_2.val
                                 ->  Custom Scan (SkipScan) on _hyper_3_5_chunk _hyper_3_5_chunk_2 (actual rows=2.00 loops=11)
                                       ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk _hyper_3_5_chunk_2 (actual rows=2.00 loops=11)
                                             ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk compress_hyper_4_38_chunk_2 (actual rows=2.00 loops=11)
                                                   Index Cond: (dev = skip_scan_htc_1.dev)
                                 ->  Custom Scan (SkipScan) on _hyper_3_6_chunk _hyper_3_6_chunk_2 (actual rows=2.00 loops=11)
                                       ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk _hyper_3_6_chunk_2 (actual rows=2.00 loops=11)
                                             ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk compress_hyper_4_39_chunk_2 (actual rows=2.00 loops=11)
                                                   Index Cond: (dev = skip_scan_htc_1.dev)
                                 ->  Custom Scan (SkipScan) on _hyper_3_7_chunk _hyper_3_7_chunk_2 (actual rows=2.00 loops=11)
                                       ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk _hyper_3_7_chunk_2 (actual rows=2.00 loops=11)
                                             ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk compress_hyper_4_40_chunk_2 (actual rows=2.00 loops=11)
                                                   Index Cond: (dev = skip_scan_htc_1.dev)
                                 ->  Custom Scan (SkipScan) on _hyper_3_8_chunk _hyper_3_8_chunk_2 (actual rows=2.00 loops=11)
                                       ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk _hyper_3_8_chunk_2 (actual rows=2.00 loops=11)
                                             ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk compress_hyper_4_41_chunk_2 (actual rows=2.00 loops=11)
                                                   Index Cond: (dev = skip_scan_htc_1.dev)

-- SkipScan into INSERT
:PREFIX INSERT INTO skip_scan_insert(time, dev, val, query) SELECT time, dev, val, 'q10_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a;
--- QUERY PLAN ---
 Insert on skip_scan_insert (actual rows=0.00 loops=1)
   ->  Subquery Scan on a (actual rows=11.00 loops=1)
         ->  Result (actual rows=11.00 loops=1)
               ->  Unique (actual rows=11.00 loops=1)
                     ->  Merge Append (actual rows=44.00 loops=1)
                           Sort Key: skip_scan_htc.dev
                           ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                                 ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                                       ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                                 ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                                       ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                                 ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                                       ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                                 ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                                       ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk (actual rows=11.00 loops=1)

-- parallel query
RESET max_parallel_workers_per_gather;
SELECT set_config(CASE WHEN current_setting('server_version_num')::int < 160000 THEN 'force_parallel_mode' ELSE 'debug_parallel_query' END,'on', false);
 set_config 
------------
 on

:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk (actual rows=11.00 loops=1)

SELECT set_config(CASE WHEN current_setting('server_version_num')::int < 160000 THEN 'force_parallel_mode' ELSE 'debug_parallel_query' END,'off', false);
 set_config 
------------
 off

TRUNCATE skip_scan_insert;
-- table with only nulls
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE where val IS NULL;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk (actual rows=1.00 loops=1)
                           Index Cond: (val IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk (actual rows=1.00 loops=1)
                           Index Cond: (val IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk (actual rows=1.00 loops=1)
                           Index Cond: (val IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk (actual rows=1.00 loops=1)
                           Index Cond: (val IS NULL)

-- no tuples in resultset
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE val IS NULL AND dev > 100;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Merge Append (actual rows=0.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_4_38_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_38_chunk (actual rows=0.00 loops=1)
                           Index Cond: ((dev > 100) AND (val IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_4_39_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_39_chunk (actual rows=0.00 loops=1)
                           Index Cond: ((dev > 100) AND (val IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_4_40_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_40_chunk (actual rows=0.00 loops=1)
                           Index Cond: ((dev > 100) AND (val IS NULL))
         ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_4_41_chunk_dev_val__ts_meta_min_1__ts_meta_m_idx on compress_hyper_4_41_chunk (actual rows=0.00 loops=1)
                           Index Cond: ((dev > 100) AND (val IS NULL))

SELECT decompress_chunk(ch) FROM show_chunks('skip_scan_htc') ch;
            decompress_chunk            
----------------------------------------
 _timescaledb_internal._hyper_3_5_chunk
 _timescaledb_internal._hyper_3_6_chunk
 _timescaledb_internal._hyper_3_7_chunk
 _timescaledb_internal._hyper_3_8_chunk

-- run tests on compressed hypertable with different layouts of compressed chunks
\set TABLE skip_scan_htcl
\ir include/skip_scan_load_comp_query.sql
-- This file and its contents are licensed under the Timescale License.
-- Please see the included NOTICE for copyright information and
-- LICENSE-TIMESCALE for a copy of the license.
-- canary for result diff
SELECT current_setting('timescaledb.enable_compressed_skipscan') AS enable_compressed_skipscan;
 enable_compressed_skipscan 
----------------------------
 on

-- To avoid ambiguity in test EXPLAIN outputs due to mixing of chunk plans with no SkipScan
SET max_parallel_workers_per_gather = 0;
-- Run SkipScan queries on the provided compression layout
-- compressed index on "segmentby='dev'" has default "dev ASC, NULLS LAST" sort order
-- SkipScan used when sort order on distinct column "dev" matches "segmentby" sort order
:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev DESC;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev DESC
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT dev FROM :TABLE ORDER BY dev DESC NULLS FIRST;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev DESC
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

-- multicolumn sort with dev as leading column matching (segmentby dev, order by time DESC) compression index
:PREFIX SELECT DISTINCT ON (dev) dev, time FROM :TABLE ORDER BY dev, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev, skip_scan_htcl."time" DESC
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, time FROM :TABLE ORDER BY dev DESC, time;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev DESC, skip_scan_htcl."time"
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan Backward using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

\qecho stable expression in targetlist on :TABLE
stable expression in targetlist on skip_scan_htcl
:PREFIX SELECT DISTINCT dev, 'q1_4', length(md5(now()::text)) FROM :TABLE ORDER BY dev;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

-- DISTINCT ON queries
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_2' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_3', NULL FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_4', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, 'q2_5', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) *, 'q2_7' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, time, 'q2_8' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, NULL, 'q2_9' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) time, 'q2_10' FROM :TABLE ORDER by dev, time DESC;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev, skip_scan_htcl."time" DESC
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, tableoid::regclass, 'q2_11' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_immutable(), 'q2_12' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_stable(), 'q2_13' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev, int_func_volatile(), 'q2_14' FROM :TABLE;
--- QUERY PLAN ---
 Result (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

\qecho DISTINCT with wholerow var
DISTINCT with wholerow var
:PREFIX SELECT DISTINCT ON (dev) :TABLE FROM :TABLE;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

\qecho LIMIT queries on :TABLE
LIMIT queries on skip_scan_htcl
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Merge Append (actual rows=9.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=3.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev DESC, time LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Merge Append (actual rows=9.00 loops=1)
               Sort Key: skip_scan_htcl.dev DESC, skip_scan_htcl."time"
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan Backward using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan Backward using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan Backward using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan Backward using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=3.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE ORDER BY dev, time DESC LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  Unique (actual rows=3.00 loops=1)
         ->  Merge Append (actual rows=9.00 loops=1)
               Sort Key: skip_scan_htcl.dev, skip_scan_htcl."time" DESC
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=3.00 loops=1)

\qecho range queries on :TABLE
range queries on skip_scan_htcl
set enable_seqscan to off;
:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time BETWEEN 100 AND 300;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=22.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     Vectorized Filter: (("time" >= 100) AND ("time" <= 300))
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
                           Index Cond: ((_ts_meta_min_1 <= 300) AND (_ts_meta_max_1 >= 100))
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     Vectorized Filter: (("time" >= 100) AND ("time" <= 300))
                     Rows Removed by Filter: 1993
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
                           Index Cond: ((_ts_meta_min_1 <= 300) AND (_ts_meta_max_1 >= 100))

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time < 200;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               Vectorized Filter: ("time" < 200)
               Rows Removed by Filter: 501
               ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
                     Index Cond: (_ts_meta_min_1 < 200)

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE time > 800;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               Vectorized Filter: ("time" > 800)
               ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)
                     Index Cond: (_ts_meta_max_1 > 800)

reset enable_seqscan;
-- Various tests for "segmentby = 'dev'"
---------------------------------------
\qecho SUBSELECTS on :TABLE
SUBSELECTS on skip_scan_htcl
:PREFIX SELECT time, dev, val, 'q4_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_htcl.dev
                     ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT NULL, dev, NULL, 'q4_3' FROM (SELECT DISTINCT ON (dev) dev FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT time, dev, NULL, 'q4_4' FROM (SELECT DISTINCT ON (dev) dev, time FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Unique (actual rows=11.00 loops=1)
         ->  Merge Append (actual rows=44.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

\qecho ORDER BY
ORDER BY
:PREFIX SELECT time, dev, val, 'q5_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE ORDER BY dev, time DESC) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_htcl.dev, skip_scan_htcl."time" DESC
                     ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT time, dev, val, 'q5_2' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE ORDER BY dev DESC, time) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_htcl.dev DESC, skip_scan_htcl."time"
                     ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan Backward using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan Backward using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan Backward using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan Backward using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

\qecho WHERE CLAUSES
WHERE CLAUSES
:PREFIX SELECT time, dev, val, 'q6_2' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE time > 5) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_htcl.dev
                     ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                                 Vectorized Filter: ("time" > 5)
                                 ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
                                       Index Cond: (_ts_meta_max_1 > 5)
                     ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT time, dev, val, 'q6_4' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a WHERE time > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   Filter: (a."time" > 5)
   ->  Result (actual rows=11.00 loops=1)
         ->  Unique (actual rows=11.00 loops=1)
               ->  Merge Append (actual rows=44.00 loops=1)
                     Sort Key: skip_scan_htcl.dev
                     ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
                     ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

-- Force not choosing SeqScan under DecompressChunks before SkipScan can evaluate it,
-- as cost of scanning and sorting a small dataset can be less than scanning an index, including startup cost.
-- After the fix in #8056 we take startup costs into account,
-- but even startup costs for scanning and sorting can be smaller for seqscan if we also have a filter on the index columns.
-- So for below queries with filters on "dev" we still need to disable SeqScan to choose IndexScan+SkipScan.
SET enable_seqscan = false;
:PREFIX SELECT time, dev, val, 'q6_1' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > 5) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  Result (actual rows=5.00 loops=1)
         ->  Unique (actual rows=5.00 loops=1)
               ->  Merge Append (actual rows=20.00 loops=1)
                     Sort Key: skip_scan_htcl.dev
                     ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)

:PREFIX SELECT time, dev, val, 'q6_3' FROM (SELECT DISTINCT ON (dev) * FROM :TABLE) a WHERE dev > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  Result (actual rows=5.00 loops=1)
         ->  Unique (actual rows=5.00 loops=1)
               ->  Merge Append (actual rows=20.00 loops=1)
                     Sort Key: skip_scan_htcl.dev
                     ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)
                     ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=5.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=5.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=5.00 loops=1)
                                       Index Cond: (dev > 5)

--\qecho immutable func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) *, 'q6_5' FROM :TABLE WHERE dev > int_func_immutable();
--- QUERY PLAN ---
 Result (actual rows=9.00 loops=1)
   ->  Unique (actual rows=9.00 loops=1)
         ->  Merge Append (actual rows=36.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=9.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=9.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=9.00 loops=1)
                                 Index Cond: (dev > 1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=9.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=9.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=9.00 loops=1)
                                 Index Cond: (dev > 1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=9.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=9.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=9.00 loops=1)
                                 Index Cond: (dev > 1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=9.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=9.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=9.00 loops=1)
                                 Index Cond: (dev > 1)

--\qecho stable func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) *, 'q6_6' FROM :TABLE WHERE dev > int_func_stable();
--- QUERY PLAN ---
 Result (actual rows=8.00 loops=1)
   ->  Unique (actual rows=8.00 loops=1)
         ->  Custom Scan (ConstraintAwareAppend) (actual rows=32.00 loops=1)
               Hypertable: skip_scan_htcl
               Chunks excluded during startup: 0
               ->  Merge Append (actual rows=32.00 loops=1)
                     Sort Key: skip_scan_htcl.dev
                     ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=8.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=8.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=8.00 loops=1)
                                       Index Cond: (dev > int_func_stable())
                     ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=8.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=8.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=8.00 loops=1)
                                       Index Cond: (dev > int_func_stable())
                     ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=8.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=8.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=8.00 loops=1)
                                       Index Cond: (dev > int_func_stable())
                     ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=8.00 loops=1)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=8.00 loops=1)
                                 ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=8.00 loops=1)
                                       Index Cond: (dev > int_func_stable())

--\qecho volatile func in WHERE clause on :TABLE
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > int_func_volatile();
--- QUERY PLAN ---
 Unique (actual rows=7.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=28.00 loops=1)
         Hypertable: skip_scan_htcl
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=28.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=7.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=7.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=7.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=7.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=7.00 loops=1)
                           Filter: (dev > int_func_volatile())
                           Rows Removed by Filter: 755
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_immutable());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Merge Append (actual rows=12.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY ('{1,2,3}'::integer[]))
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY ('{1,2,3}'::integer[]))
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY ('{1,2,3}'::integer[]))
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=3.00 loops=1)
                           Index Cond: (dev = ANY ('{1,2,3}'::integer[]))

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_stable());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=12.00 loops=1)
         Hypertable: skip_scan_htcl
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=12.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=3.00 loops=1)
                                 Index Cond: (dev = ANY (inta_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=3.00 loops=1)
                                 Index Cond: (dev = ANY (inta_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=3.00 loops=1)
                                 Index Cond: (dev = ANY (inta_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=3.00 loops=1)
                                 Index Cond: (dev = ANY (inta_func_stable()))

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = ANY(inta_func_volatile());
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Custom Scan (ConstraintAwareAppend) (actual rows=12.00 loops=1)
         Hypertable: skip_scan_htcl
         Chunks excluded during startup: 0
         ->  Merge Append (actual rows=12.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755
                           ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755
                           ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755
                           ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=3.00 loops=1)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755
                           ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

-- RowCompareExpr
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE (dev, time) > (5,100);
--- QUERY PLAN ---
 Unique (actual rows=6.00 loops=1)
   ->  Merge Append (actual rows=24.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=6.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=6.00 loops=1)
                     Filter: (ROW(dev, "time") > ROW(5, 100))
                     Rows Removed by Filter: 1005
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=6.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=6.00 loops=1)
                     Filter: (ROW(dev, "time") > ROW(5, 100))
                     Rows Removed by Filter: 1005
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=6.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=6.00 loops=1)
                     Filter: (ROW(dev, "time") > ROW(5, 100))
                     Rows Removed by Filter: 1005
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=6.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=6.00 loops=1)
                     Filter: (ROW(dev, "time") > ROW(5, 100))
                     Rows Removed by Filter: 1005
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > NULL;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Sort (actual rows=0.00 loops=1)
         Sort Key: dev
         Sort Method: quicksort 
         ->  Result (actual rows=0.00 loops=1)
               One-Time Filter: false

-- no tuples matching
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev > 20;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Merge Append (actual rows=0.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=0.00 loops=1)
                           Index Cond: (dev > 20)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=0.00 loops=1)
                           Index Cond: (dev > 20)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=0.00 loops=1)
                           Index Cond: (dev > 20)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=0.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=0.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=0.00 loops=1)
                           Index Cond: (dev > 20)

-- multiple constraints in WHERE clause
:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev > 5 AND time = 100;
--- QUERY PLAN ---
 Unique (actual rows=5.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=5.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=5.00 loops=1)
               Vectorized Filter: ("time" = 100)
               Rows Removed by Filter: 745
               ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=5.00 loops=1)
                     Index Cond: ((dev > 5) AND (_ts_meta_min_1 <= 100) AND (_ts_meta_max_1 >= 100))

:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev > 5 AND time > 200;
--- QUERY PLAN ---
 Unique (actual rows=5.00 loops=1)
   ->  Merge Append (actual rows=20.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=5.00 loops=1)
                     Vectorized Filter: ("time" > 200)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=5.00 loops=1)
                           Index Cond: ((dev > 5) AND (_ts_meta_max_1 > 200))
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=5.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=5.00 loops=1)
                           Index Cond: (dev > 5)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=5.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=5.00 loops=1)
                           Index Cond: (dev > 5)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=5.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=5.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=5.00 loops=1)
                           Index Cond: (dev > 5)

:PREFIX SELECT DISTINCT ON (dev) dev,time FROM :TABLE WHERE dev >= 5 AND dev < 7 AND dev >= 2;
--- QUERY PLAN ---
 Unique (actual rows=2.00 loops=1)
   ->  Merge Append (actual rows=8.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=2.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=2.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=2.00 loops=1)
                           Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=2.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=2.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=2.00 loops=1)
                           Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=2.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=2.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=2.00 loops=1)
                           Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=2.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=2.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=2.00 loops=1)
                           Index Cond: ((dev >= 5) AND (dev < 7) AND (dev >= 2))

:PREFIX SELECT DISTINCT ON (dev) dev,time,val FROM :TABLE WHERE time > 100 AND time < 200 AND val > 10 AND val < 10000 AND dev > 2 AND dev < 7 ORDER BY dev,time DESC;
--- QUERY PLAN ---
 Unique (actual rows=0.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=0.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=0.00 loops=1)
               Vectorized Filter: (("time" > 100) AND ("time" < 200) AND (val > 10) AND (val < 10000))
               Rows Removed by Filter: 1000
               ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=4.00 loops=1)
                     Index Cond: ((dev > 2) AND (dev < 7) AND (_ts_meta_min_1 < 200) AND (_ts_meta_max_1 > 100))

:PREFIX SELECT DISTINCT ON (dev) dev FROM :TABLE WHERE dev IS NULL;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev IS NULL)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev IS NULL)

-- test constants in ORDER BY
:PREFIX SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev = 1 ORDER BY dev, time DESC;
--- QUERY PLAN ---
 Unique (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=4.00 loops=1)
         Sort Key: skip_scan_htcl."time" DESC
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=1.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=1.00 loops=1)
                           Index Cond: (dev = 1)

-- CTE
:PREFIX WITH devices AS (
	SELECT DISTINCT ON (dev) dev FROM :TABLE
)
SELECT * FROM devices;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX WITH devices AS (
	SELECT DISTINCT dev FROM :TABLE
)
SELECT * FROM devices ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

-- prepared statements
PREPARE prep AS SELECT DISTINCT ON (dev) dev FROM :TABLE;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Merge Append (actual rows=44.00 loops=1)
         Sort Key: skip_scan_htcl.dev
         ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=11.00 loops=1)
         ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=11.00 loops=1)
                     ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=11.00 loops=1)

DEALLOCATE prep;
-- ReScan tests
-- have SkipScan as Distinct is over index
:PREFIX SELECT time, dev, val, 'q7_2' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev != a.v) b) a;
--- QUERY PLAN ---
 Nested Loop (actual rows=18.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Result (actual rows=9.00 loops=2)
         ->  Unique (actual rows=9.00 loops=2)
               ->  Merge Append (actual rows=36.00 loops=2)
                     Sort Key: skip_scan_htcl.dev
                     ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=9.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=9.00 loops=2)
                                 ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=9.00 loops=2)
                                       Filter: (dev <> "*VALUES*".column1)
                                       Rows Removed by Filter: 1
                     ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=9.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=9.00 loops=2)
                                 ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=9.00 loops=2)
                                       Filter: (dev <> "*VALUES*".column1)
                                       Rows Removed by Filter: 1
                     ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=9.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=9.00 loops=2)
                                 ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=9.00 loops=2)
                                       Filter: (dev <> "*VALUES*".column1)
                                       Rows Removed by Filter: 1
                     ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=9.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=9.00 loops=2)
                                 ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=9.00 loops=2)
                                       Filter: (dev <> "*VALUES*".column1)
                                       Rows Removed by Filter: 1

-- RuntimeKeys
:PREFIX SELECT time, dev, val, 'q8_1' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT DISTINCT ON (dev) * FROM :TABLE WHERE dev >= a.v) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=19.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Result (actual rows=10.00 loops=2)
         ->  Unique (actual rows=10.00 loops=2)
               ->  Merge Append (actual rows=38.00 loops=2)
                     Sort Key: skip_scan_htcl.dev
                     ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=10.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=10.00 loops=2)
                                 ->  Index Scan using compress_hyper_6_10_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_10_chunk (actual rows=10.00 loops=2)
                                       Index Cond: (dev >= "*VALUES*".column1)
                     ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=10.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=10.00 loops=2)
                                 ->  Index Scan using compress_hyper_6_14_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_14_chunk (actual rows=10.00 loops=2)
                                       Index Cond: (dev >= "*VALUES*".column1)
                     ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=10.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=10.00 loops=2)
                                 ->  Index Scan using compress_hyper_6_15_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_15_chunk (actual rows=10.00 loops=2)
                                       Index Cond: (dev >= "*VALUES*".column1)
                     ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=10.00 loops=2)
                           ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=10.00 loops=2)
                                 ->  Index Scan using compress_hyper_6_16_chunk_dev__ts_meta_min_1__ts_meta_max_1_idx on compress_hyper_6_16_chunk (actual rows=10.00 loops=2)
                                       Index Cond: (dev >= "*VALUES*".column1)

RESET max_parallel_workers_per_gather;
RESET enable_seqscan;
-- try one query with EXPLAIN only for coverage
EXPLAIN (buffers off, costs off, timing off, summary off) SELECT DISTINCT ON (dev_name) dev_name FROM skip_scan;
--- QUERY PLAN ---
 Unique
   ->  Custom Scan (SkipScan) on skip_scan
         ->  Index Only Scan using skip_scan_dev_name_idx on skip_scan
               Index Cond: (dev_name > NULL::text)

EXPLAIN (buffers off, costs off, timing off, summary off) SELECT DISTINCT ON (dev_name) dev_name FROM skip_scan_ht;
--- QUERY PLAN ---
 Unique
   ->  Merge Append
         Sort Key: skip_scan_ht.dev_name
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk
               ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk
               ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk
               ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk
                     Index Cond: (dev_name > NULL::text)
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk
               ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk
                     Index Cond: (dev_name > NULL::text)

-- #3629 skipscan with constant skipscan column in where clause
CREATE TABLE i3629(a int, time timestamptz NOT NULL);
SELECT table_name FROM create_hypertable('i3629', 'time');
 table_name 
------------
 i3629

INSERT INTO i3629 SELECT i, '2020-04-01'::date-10-i from generate_series(1,20) i;
EXPLAIN (SUMMARY OFF, BUFFERS OFF, COSTS OFF) SELECT DISTINCT ON (a) * FROM i3629 WHERE a in (2) ORDER BY a ASC, time DESC;
--- QUERY PLAN ---
 Unique
   ->  Sort
         Sort Key: i3629."time" DESC
         ->  Append
               ->  Seq Scan on _hyper_7_42_chunk
                     Filter: (a = 2)
               ->  Seq Scan on _hyper_7_43_chunk
                     Filter: (a = 2)
               ->  Seq Scan on _hyper_7_44_chunk
                     Filter: (a = 2)
               ->  Seq Scan on _hyper_7_45_chunk
                     Filter: (a = 2)

SELECT DISTINCT ON (a) * FROM i3629 WHERE a in (2) ORDER BY a ASC, time DESC;
 a |             time             
---+------------------------------
 2 | Fri Mar 20 00:00:00 2020 PDT

-- #3720 skipscan not being used on varchar column
CREATE TABLE i3720(time timestamptz not null,data varchar);
SELECT table_name FROM create_hypertable('i3720','time');
WARNING:  column type "character varying" used for "data" does not follow best practices
 table_name 
------------
 i3720

INSERT INTO i3720
SELECT time, (array['Yes', 'No', 'Maybe'])[floor(random() * 3 + 1)]
FROM generate_series('2000-01-01'::timestamptz,'2000-01-03'::timestamptz, '10 minute'::interval) AS g1(time);
CREATE INDEX ON i3720(data, time);
ANALYZE i3720;
:PREFIX SELECT DISTINCT ON(data) * FROM i3720;
--- QUERY PLAN ---
 Unique (actual rows=3.00 loops=1)
   ->  Custom Scan (SkipScan) on _hyper_8_46_chunk (actual rows=3.00 loops=1)
         ->  Index Only Scan using _hyper_8_46_chunk_i3720_data_time_idx on _hyper_8_46_chunk (actual rows=3.00 loops=1)
               Index Cond: (data > NULL::text)

