-- 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_dagg_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_for_distinct_aggregates') AS enable_dagg_skipscan;
 enable_dagg_skipscan 
----------------------
 on

-- test different index configurations
-- no index so we cant do SkipScan
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Sort (actual rows=10022.00 loops=1)
         Sort Key: dev
         Sort Method: quicksort 
         ->  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 count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev
   ->  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)

-- Test not-NULL mode
:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE dev IS NOT NULL GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: dev
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan Backward 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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev NULLS FIRST;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE WHERE dev IS NOT NULL GROUP BY dev ORDER BY dev  NULLS FIRST;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE WHERE dev IS NOT NULL GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: dev
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=11.00 loops=1)
         ->  Index Only Scan Backward 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 count(DISTINCT dev) FROM :TABLE WHERE time = 100;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), dev FROM :TABLE WHERE time = 100 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE WHERE time = 100 AND dev IS NOT NULL GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=10.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev_name) FROM :TABLE WHERE dev_name IN ('device_1','device_2');
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Sort (actual rows=2000.00 loops=1)
         Sort Key: dev_name
         Sort Method: quicksort 
         ->  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 count(DISTINCT dev%3) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Index Scan using skip_scan_expr_idx on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT count(DISTINCT dev%3), dev%3 FROM :TABLE GROUP BY dev%3 ORDER BY dev%3;
--- QUERY PLAN ---
 GroupAggregate (actual rows=4.00 loops=1)
   Group Key: (dev % 3)
   ->  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);
CREATE INDEX ON :TABLE(dev);
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
-- Various distint aggs over same column is OK
:PREFIX SELECT count(DISTINCT dev), sum(DISTINCT dev), 'q1_1' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev_name), max(DISTINCT dev_name), 'q1_2' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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)

-- Distinct agg over Const is OK
:PREFIX SELECT count(DISTINCT dev), count(DISTINCT 2), 'q1_3', NULL FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 over distinct agg is OK
:PREFIX SELECT DISTINCT count(DISTINCT dev), dev, 'q1_4' FROM :TABLE GROUP BY dev 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, count(DISTINCT dev)
         ->  GroupAggregate (actual rows=12.00 loops=1)
               Group Key: dev
               ->  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 count(DISTINCT dev), 'q1_5', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev_name), 'q1_6', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), 'q1_7', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev_name), 'q1_8', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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)

-- Mix of aggregates on different columns and distinct/not distinct
-- currently not supported by skipscan
:PREFIX SELECT count(DISTINCT dev), max(DISTINCT dev_name), 'q1_9' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Index Scan using skip_scan_dev_idx on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT count(DISTINCT dev), sum(dev), 'q1_10' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT count(DISTINCT dev), dev_name, 'q1_11' FROM :TABLE GROUP BY dev_name ORDER BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev_name
   ->  Sort (actual rows=10022.00 loops=1)
         Sort Key: dev_name, dev
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

-- distinct on expressions not supported
:PREFIX SELECT count(DISTINCT time_bucket(10,time)), 'q1_12' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Sort (actual rows=10022.00 loops=1)
         Sort Key: (time_bucket(10, "time"))
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT count(DISTINCT length(dev_name)), 'q1_13' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Sort (actual rows=10022.00 loops=1)
         Sort Key: (length(dev_name))
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

:PREFIX SELECT count(DISTINCT 3*time), 'q1_14' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Sort (actual rows=10022.00 loops=1)
         Sort Key: ((3 * "time"))
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

-- But expressions over distinct aggregates are supported
:PREFIX SELECT count(DISTINCT dev) + 1, sum(DISTINCT dev)/count(DISTINCT dev), 'q1_15' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 aggs grouped on their args
:PREFIX SELECT count(DISTINCT dev), dev, 'q2_1' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev, 'q2_2', NULL FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev, 'q2_3', length(md5(now()::text)) FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev, 'q2_4', length(md5(random()::text)) FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev, int_func_immutable(), 'q2_5' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev, int_func_stable(), 'q2_6' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev, int_func_volatile(), 'q2_7' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev+1, 'q2_8' FROM :TABLE GROUP BY dev ORDER BY 2;
--- QUERY PLAN ---
 Sort (actual rows=12.00 loops=1)
   Sort Key: ((dev + 1))
   Sort Method: quicksort 
   ->  GroupAggregate (actual rows=12.00 loops=1)
         Group Key: dev
         ->  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 count(DISTINCT dev), dev+1, dev+2, 'q2_9' FROM :TABLE GROUP BY dev, dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev
   ->  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)

-- Cannot do SkipScan as we group on a column which is not the distinct agg argument
:PREFIX SELECT time, count(DISTINCT dev), 'q2_10' FROM :TABLE GROUP BY time;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1002.00 loops=1)
   Group Key: "time"
   ->  Index Only Scan using skip_scan_time_dev_idx on skip_scan (actual rows=10022.00 loops=1)

-- Cannot do SkipScan if we group on 2+ columns
:PREFIX SELECT count(DISTINCT dev), dev, tableoid::regclass, 'q2_11' FROM :TABLE GROUP BY dev, tableoid ORDER BY dev, tableoid;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev, tableoid
   ->  Sort (actual rows=10022.00 loops=1)
         Sort Key: dev, tableoid
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

-- DISTINCT aggs grouped on their TEXT args
:PREFIX SELECT count(DISTINCT dev_name), dev_name, 'q3_1' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_11' FROM :TABLE WHERE dev_name IS NOT NULL GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_2', NULL FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_3', length(md5(now()::text)) FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_4', length(md5(random()::text)) FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev_name
   ->  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 count(DISTINCT dev_name::varchar), dev_name::varchar, 'q3_5' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev_name
   ->  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 count(DISTINCT dev_name), dev_name, int_func_immutable(), 'q3_6' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev_name
   ->  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 count(DISTINCT dev_name), dev_name, int_func_stable(), 'q3_7' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev_name
   ->  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 count(DISTINCT dev_name), dev_name, int_func_volatile(), 'q3_8' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev_name
   ->  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)

-- Cannot do SkipScan as we group on a column which is not the distinct agg argument
:PREFIX SELECT count(DISTINCT dev_name), dev_name, tableoid::regclass, 'q3_9' FROM :TABLE GROUP BY dev_name, tableoid ORDER BY dev_name, tableoid;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: dev_name, tableoid
   ->  Sort (actual rows=10022.00 loops=1)
         Sort Key: dev_name, tableoid
         Sort Method: quicksort 
         ->  Seq Scan on skip_scan (actual rows=10022.00 loops=1)

-- Can do SkipScan if extra group column is eliminated by pinning to a Const
-- and when it changes group by ordering
:PREFIX SELECT count(DISTINCT dev_name), dev, dev_name FROM :TABLE WHERE dev = 1 GROUP BY dev, dev_name ORDER BY dev, dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1.00 loops=1)
   Group Key: dev_name
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=1.00 loops=1)
         ->  Index Scan using skip_scan_dev_name_idx on skip_scan (actual rows=1.00 loops=1)
               Filter: (dev = 1)
               Rows Removed by Filter: 9022

\qecho LIMIT queries on :TABLE
LIMIT queries on skip_scan
:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE GROUP BY dev LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  GroupAggregate (actual rows=3.00 loops=1)
         Group Key: dev
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=4.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=4.00 loops=1)
                     Index Cond: (dev > NULL::integer)

:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  GroupAggregate (actual rows=3.00 loops=1)
         Group Key: dev
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=4.00 loops=1)
               ->  Index Only Scan Backward using skip_scan_dev_idx on skip_scan (actual rows=4.00 loops=1)
                     Index Cond: (dev < NULL::integer)

\qecho range queries on :TABLE
range queries on skip_scan
:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE time BETWEEN 100 AND 300 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE WHERE time < 200 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE WHERE time > 800 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT time), time FROM :TABLE WHERE time BETWEEN 0 AND 5000  GROUP BY time;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1001.00 loops=1)
   Group Key: "time"
   ->  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 c1, c2, 'q4_1' FROM (SELECT count(DISTINCT dev) as c1, sum(DISTINCT dev) as c2 FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.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 NULL, dev, NULL, 'q4_2' FROM (SELECT count(DISTINCT dev) as dev FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.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 NULL, dev, NULL, c1, 2, c3, 'q4_3' FROM (SELECT count(DISTINCT dev) as c1, dev, 1 as c3 FROM :TABLE GROUP BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=12.00 loops=1)
   ->  GroupAggregate (actual rows=12.00 loops=1)
         Group Key: skip_scan.dev
         ->  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 ORDER BY
ORDER BY
:PREFIX SELECT c, dev, 'q5_1' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev ORDER BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=12.00 loops=1)
   ->  GroupAggregate (actual rows=12.00 loops=1)
         Group Key: skip_scan.dev
         ->  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 c, dev, 'q5_2' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev ORDER BY dev DESC) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=12.00 loops=1)
   ->  GroupAggregate (actual rows=12.00 loops=1)
         Group Key: skip_scan.dev
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=12.00 loops=1)
               ->  Index Only Scan Backward using skip_scan_dev_idx on skip_scan (actual rows=12.00 loops=1)
                     Index Cond: (dev < NULL::integer)

\qecho WHERE CLAUSES
WHERE CLAUSES
:PREFIX SELECT c, dev, 'q6_1' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE WHERE dev > 5 GROUP BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  GroupAggregate (actual rows=5.00 loops=1)
         Group Key: skip_scan.dev
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=5.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=5.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev > 5))

:PREFIX SELECT c, dev, 'q6_2' FROM (SELECT sum(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev HAVING sum(DISTINCT dev)>2) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=8.00 loops=1)
   ->  GroupAggregate (actual rows=8.00 loops=1)
         Group Key: skip_scan.dev
         Filter: (sum(DISTINCT skip_scan.dev) > 2)
         Rows Removed by Filter: 4
         ->  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 c, dev, 'q6_3' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev) a WHERE dev > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  GroupAggregate (actual rows=5.00 loops=1)
         Group Key: skip_scan.dev
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=5.00 loops=1)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=5.00 loops=1)
                     Index Cond: ((dev > NULL::integer) AND (dev > 5))

:PREFIX SELECT c, dev, 'q6_4' FROM (SELECT sum(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev) a WHERE c > 2;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=8.00 loops=1)
   ->  GroupAggregate (actual rows=8.00 loops=1)
         Group Key: skip_scan.dev
         Filter: (sum(DISTINCT skip_scan.dev) > 2)
         Rows Removed by Filter: 4
         ->  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 immutable func in WHERE clause on :TABLE
:PREFIX SELECT count(DISTINCT dev), 'q6_5' FROM :TABLE WHERE dev > int_func_immutable();
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=9.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=9.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND (dev > 1))

--\qecho stable func in WHERE clause on :TABLE
:PREFIX SELECT count(DISTINCT dev), 'q6_6' FROM :TABLE WHERE dev > int_func_stable();
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=8.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=8.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND (dev > int_func_stable()))

--\qecho volatile func in WHERE clause on :TABLE:PREFIX SELECT count(DISTINCT dev), 'q6_7' FROM :TABLE WHERE dev > int_func_volatile();
:PREFIX SELECT count(DISTINCT dev), 'q6_8' FROM :TABLE WHERE dev = ANY(inta_func_immutable());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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) AND (dev = ANY ('{1,2,3}'::integer[])))

:PREFIX SELECT count(DISTINCT dev), 'q6_9' FROM :TABLE WHERE dev = ANY(inta_func_stable());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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) AND (dev = ANY (inta_func_stable())))

:PREFIX SELECT count(DISTINCT dev), 'q6_10' FROM :TABLE WHERE dev = ANY(inta_func_volatile());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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)
               Filter: (dev = ANY (inta_func_volatile()))
               Rows Removed by Filter: 7022

-- always false expr similar to our initial skip qual
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE dev > NULL;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev) FROM :TABLE WHERE dev > 20;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=0.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=0.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND (dev > 20))

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

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

:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE dev >= 5 AND dev < 7 AND dev >= 2;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Custom Scan (SkipScan) on skip_scan (actual rows=2.00 loops=1)
         ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=2.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND (dev >= 5) AND (dev < 7) AND (dev >= 2))

:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE time > 100 AND time < 200 AND val > 10 AND val < 10000 AND dev > 2 AND dev < 7 GROUP BY dev ORDER BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=4.00 loops=1)
   Group Key: dev
   ->  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 count(DISTINCT dev) FROM :TABLE WHERE dev IS NULL;
--- QUERY PLAN ---
 Aggregate (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 count(DISTINCT dev_name) FROM :TABLE WHERE dev_name IS NULL;
--- QUERY PLAN ---
 Aggregate (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))

-- Distinct aggregate path with no pathkeys because of Const predicate.
-- PG is smart to add LIMIT 1 to SELECT DISTINCT in this case,
-- but not smart enough to add LIMIT 1 to distinct aggregate input.
-- TODO: create an issue for this task, i.e. add LIMIT 1 to distinct aggregate input when input equals to a Const
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE dev = 1;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=1000.00 loops=1)
         Index Cond: (dev = 1)

:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE dev = 1 GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1.00 loops=1)
   ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=1000.00 loops=1)
         Index Cond: (dev = 1)

-- CTE
:PREFIX WITH devices AS (
	SELECT count(DISTINCT dev) FROM :TABLE
)
SELECT * FROM devices;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 dev, count(DISTINCT dev) FROM :TABLE GROUP BY dev
)
SELECT * FROM devices ORDER BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=12.00 loops=1)
   Group Key: skip_scan.dev
   ->  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 count(DISTINCT dev_name) FROM :TABLE;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 ---
 Aggregate (actual rows=1.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 ---
 Aggregate (actual rows=1.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 c, 'q7_1' FROM (SELECT count(DISTINCT dev) c FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT * FROM :TABLE WHERE time != a.v) b) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.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 c, 'q7_2' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT count(DISTINCT dev) c FROM :TABLE WHERE dev != a.v) b) a;
--- QUERY PLAN ---
 Nested Loop (actual rows=2.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Aggregate (actual rows=1.00 loops=2)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=10.00 loops=2)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=10.00 loops=2)
                     Index Cond: (dev > NULL::integer)
                     Filter: (dev <> "*VALUES*".column1)
                     Rows Removed by Filter: 1000

-- RuntimeKeys
:PREFIX SELECT c, 'q8_1' FROM (SELECT * FROM (VALUES (1), (2)) a(v), LATERAL (SELECT count(DISTINCT dev) c FROM :TABLE WHERE dev >= a.v) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=2.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Aggregate (actual rows=1.00 loops=2)
         ->  Custom Scan (SkipScan) on skip_scan (actual rows=9.50 loops=2)
               ->  Index Only Scan using skip_scan_dev_idx on skip_scan (actual rows=9.50 loops=2)
                     Index Cond: ((dev > NULL::integer) AND (dev >= "*VALUES*".column1))

--  DISTINCT aggs on different columns in different subqueries
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE UNION ALL SELECT count(DISTINCT time) FROM :TABLE;
--- QUERY PLAN ---
 Append (actual rows=2.00 loops=1)
   ->  Aggregate (actual rows=1.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)
   ->  Aggregate (actual rows=1.00 loops=1)
         ->  Custom Scan (SkipScan) on skip_scan skip_scan_1 (actual rows=1002.00 loops=1)
               ->  Index Only Scan using skip_scan_time_dev_idx on skip_scan skip_scan_1 (actual rows=1002.00 loops=1)
                     Index Cond: ("time" > NULL::integer)

:PREFIX SELECT *, 'q9_2' FROM (SELECT count(DISTINCT dev) cd, dev FROM :TABLE GROUP BY dev) a, LATERAL (SELECT count(DISTINCT time) ct FROM :TABLE WHERE dev = a.dev) b;
--- QUERY PLAN ---
 Nested Loop (actual rows=12.00 loops=1)
   ->  GroupAggregate (actual rows=12.00 loops=1)
         Group Key: skip_scan.dev
         ->  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)
   ->  Aggregate (actual rows=1.00 loops=12)
         ->  Custom Scan (SkipScan) on skip_scan skip_scan_1 (actual rows=833.42 loops=12)
               ->  Index Only Scan using skip_scan_dev_time_idx on skip_scan skip_scan_1 (actual rows=833.42 loops=12)
                     Index Cond: ((dev = skip_scan.dev) AND ("time" > NULL::integer))

-- SkipScan into INSERT
:PREFIX INSERT INTO skip_scan_insert(dev, val, query) SELECT dev, sd, 'q10_1' FROM (SELECT sum(DISTINCT dev) sd, dev FROM :TABLE GROUP BY dev) a;
--- QUERY PLAN ---
 Insert on skip_scan_insert (actual rows=0.00 loops=1)
   ->  Subquery Scan on a (actual rows=12.00 loops=1)
         ->  GroupAggregate (actual rows=12.00 loops=1)
               Group Key: skip_scan.dev
               ->  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)

-- 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 count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT time) FROM skip_scan_nulls;
--- QUERY PLAN ---
 Aggregate (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 count(DISTINCT time) FROM skip_scan_nulls WHERE time IS NOT NULL;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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))

\set TABLE skip_scan_ht
\ir include/skip_scan_dagg_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_for_distinct_aggregates') AS enable_dagg_skipscan;
 enable_dagg_skipscan 
----------------------
 on

-- test different index configurations
-- no index so we cant do SkipScan
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Sort (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_ht.dev
         Sort Method: quicksort 
         ->  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 count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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)

-- Test not-NULL mode
:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE dev IS NOT NULL GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=10.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  Merge Append (actual rows=40.00 loops=1)
         Sort Key: skip_scan_ht.dev DESC
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=10.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=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 Backward 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 Backward 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 Backward 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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev NULLS FIRST;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE WHERE dev IS NOT NULL GROUP BY dev ORDER BY dev  NULLS FIRST;
--- QUERY PLAN ---
 GroupAggregate (actual rows=10.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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 count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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_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 count(DISTINCT dev), dev FROM :TABLE WHERE dev IS NOT NULL GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=10.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  Merge Append (actual rows=40.00 loops=1)
         Sort Key: skip_scan_ht.dev DESC
         ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=10.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=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 Backward 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 Backward 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 Backward 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 count(DISTINCT dev) FROM :TABLE WHERE time = 100;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), dev FROM :TABLE WHERE time = 100 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: _hyper_1_1_chunk.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_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 count(DISTINCT dev), dev FROM :TABLE WHERE time = 100 AND dev IS NOT NULL GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=10.00 loops=1)
   Group Key: _hyper_1_1_chunk.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_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 count(DISTINCT dev_name) FROM :TABLE WHERE dev_name IN ('device_1','device_2');
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Sort (actual rows=2000.00 loops=1)
         Sort Key: skip_scan_ht.dev_name
         Sort Method: quicksort 
         ->  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 count(DISTINCT dev%3) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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)

:PREFIX SELECT count(DISTINCT dev%3), dev%3 FROM :TABLE GROUP BY dev%3 ORDER BY dev%3;
--- QUERY PLAN ---
 GroupAggregate (actual rows=4.00 loops=1)
   Group Key: ((skip_scan_ht.dev % 3))
   ->  Result (actual rows=10020.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);
CREATE INDEX ON :TABLE(dev);
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
-- Various distint aggs over same column is OK
:PREFIX SELECT count(DISTINCT dev), sum(DISTINCT dev), 'q1_1' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev_name), max(DISTINCT dev_name), 'q1_2' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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)

-- Distinct agg over Const is OK
:PREFIX SELECT count(DISTINCT dev), count(DISTINCT 2), 'q1_3', NULL FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 over distinct agg is OK
:PREFIX SELECT DISTINCT count(DISTINCT dev), dev, 'q1_4' FROM :TABLE GROUP BY dev 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, count(DISTINCT skip_scan_ht.dev)
         ->  GroupAggregate (actual rows=11.00 loops=1)
               Group Key: skip_scan_ht.dev
               ->  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 count(DISTINCT dev), 'q1_5', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev_name), 'q1_6', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), 'q1_7', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev_name), 'q1_8', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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)

-- Mix of aggregates on different columns and distinct/not distinct
-- currently not supported by skipscan
:PREFIX SELECT count(DISTINCT dev), max(DISTINCT dev_name), 'q1_9' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  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)

:PREFIX SELECT count(DISTINCT dev), sum(dev), 'q1_10' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
         ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
         ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
         ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

:PREFIX SELECT count(DISTINCT dev), dev_name, 'q1_11' FROM :TABLE GROUP BY dev_name ORDER BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev_name
   ->  Sort (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_ht.dev_name, skip_scan_ht.dev
         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)

-- distinct on expressions not supported
:PREFIX SELECT count(DISTINCT time_bucket(10,time)), 'q1_12' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: (time_bucket(10, skip_scan_ht."time"))
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_time_dev_idx on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
         ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_time_dev_idx on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
         ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_time_dev_idx on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
         ->  Index Only 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 count(DISTINCT length(dev_name)), 'q1_13' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Sort (actual rows=10020.00 loops=1)
         Sort Key: (length(skip_scan_ht.dev_name))
         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 count(DISTINCT 3*time), 'q1_14' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: ((3 * skip_scan_ht."time"))
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_time_dev_idx on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
         ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_time_dev_idx on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
         ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_time_dev_idx on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
         ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_time_dev_idx on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

-- But expressions over distinct aggregates are supported
:PREFIX SELECT count(DISTINCT dev) + 1, sum(DISTINCT dev)/count(DISTINCT dev), 'q1_15' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 aggs grouped on their args
:PREFIX SELECT count(DISTINCT dev), dev, 'q2_1' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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 count(DISTINCT dev), dev, 'q2_2', NULL FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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 count(DISTINCT dev), dev, 'q2_3', length(md5(now()::text)) FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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 count(DISTINCT dev), dev, 'q2_4', length(md5(random()::text)) FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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 count(DISTINCT dev), dev, int_func_immutable(), 'q2_5' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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 count(DISTINCT dev), dev, int_func_stable(), 'q2_6' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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 count(DISTINCT dev), dev, int_func_volatile(), 'q2_7' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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 count(DISTINCT dev), dev+1, 'q2_8' FROM :TABLE GROUP BY dev ORDER BY 2;
--- QUERY PLAN ---
 Sort (actual rows=11.00 loops=1)
   Sort Key: ((skip_scan_ht.dev + 1))
   Sort Method: quicksort 
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_ht.dev
         ->  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 count(DISTINCT dev), dev+1, dev+2, 'q2_9' FROM :TABLE GROUP BY dev, dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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)

-- Cannot do SkipScan as we group on a column which is not the distinct agg argument
:PREFIX SELECT time, count(DISTINCT dev), 'q2_10' FROM :TABLE GROUP BY time;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1000.00 loops=1)
   Group Key: skip_scan_ht."time"
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_ht."time", skip_scan_ht.dev
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_time_dev_idx on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
         ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_time_dev_idx on _hyper_1_2_chunk (actual rows=2505.00 loops=1)
         ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_time_dev_idx on _hyper_1_3_chunk (actual rows=2505.00 loops=1)
         ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_time_dev_idx on _hyper_1_4_chunk (actual rows=2505.00 loops=1)

-- Cannot do SkipScan if we group on 2+ columns
:PREFIX SELECT count(DISTINCT dev), dev, tableoid::regclass, 'q2_11' FROM :TABLE GROUP BY dev, tableoid ORDER BY dev, tableoid;
--- QUERY PLAN ---
 GroupAggregate (actual rows=44.00 loops=1)
   Group Key: skip_scan_ht.dev, skip_scan_ht.tableoid
   ->  Sort (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_ht.dev, skip_scan_ht.tableoid
         Sort Method: quicksort 
         ->  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 aggs grouped on their TEXT args
:PREFIX SELECT count(DISTINCT dev_name), dev_name, 'q3_1' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_11' FROM :TABLE WHERE dev_name IS NOT NULL GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=10.00 loops=1)
   Group Key: skip_scan_ht.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_2', NULL FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_3', length(md5(now()::text)) FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_4', length(md5(random()::text)) FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev_name
   ->  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 count(DISTINCT dev_name::varchar), dev_name::varchar, 'q3_5' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, int_func_immutable(), 'q3_6' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, int_func_stable(), 'q3_7' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, int_func_volatile(), 'q3_8' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev_name
   ->  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)

-- Cannot do SkipScan as we group on a column which is not the distinct agg argument
:PREFIX SELECT count(DISTINCT dev_name), dev_name, tableoid::regclass, 'q3_9' FROM :TABLE GROUP BY dev_name, tableoid ORDER BY dev_name, tableoid;
--- QUERY PLAN ---
 GroupAggregate (actual rows=44.00 loops=1)
   Group Key: skip_scan_ht.dev_name, skip_scan_ht.tableoid
   ->  Sort (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_ht.dev_name, skip_scan_ht.tableoid
         Sort Method: quicksort 
         ->  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)

-- Can do SkipScan if extra group column is eliminated by pinning to a Const
-- and when it changes group by ordering
:PREFIX SELECT count(DISTINCT dev_name), dev, dev_name FROM :TABLE WHERE dev = 1 GROUP BY dev, dev_name ORDER BY dev, dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1.00 loops=1)
   Group Key: skip_scan_ht.dev_name
   ->  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 Scan using _hyper_1_1_chunk_skip_scan_ht_dev_name_idx on _hyper_1_1_chunk (actual rows=1.00 loops=1)
                     Filter: (dev = 1)
                     Rows Removed by Filter: 2255
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=1.00 loops=1)
               ->  Index Scan using _hyper_1_2_chunk_skip_scan_ht_dev_name_idx on _hyper_1_2_chunk (actual rows=1.00 loops=1)
                     Filter: (dev = 1)
                     Rows Removed by Filter: 2255
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=1.00 loops=1)
               ->  Index Scan using _hyper_1_3_chunk_skip_scan_ht_dev_name_idx on _hyper_1_3_chunk (actual rows=1.00 loops=1)
                     Filter: (dev = 1)
                     Rows Removed by Filter: 2255
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=1.00 loops=1)
               ->  Index Scan using _hyper_1_4_chunk_skip_scan_ht_dev_name_idx on _hyper_1_4_chunk (actual rows=1.00 loops=1)
                     Filter: (dev = 1)
                     Rows Removed by Filter: 2255

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

:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  GroupAggregate (actual rows=3.00 loops=1)
         Group Key: skip_scan_ht.dev
         ->  Merge Append (actual rows=13.00 loops=1)
               Sort Key: skip_scan_ht.dev DESC
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk (actual rows=4.00 loops=1)
                     ->  Index Only Scan Backward using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=4.00 loops=1)
                           Index Cond: (dev < NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=4.00 loops=1)
                     ->  Index Only Scan Backward using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=4.00 loops=1)
                           Index Cond: (dev < NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=4.00 loops=1)
                     ->  Index Only Scan Backward using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=4.00 loops=1)
                           Index Cond: (dev < NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=4.00 loops=1)
                     ->  Index Only Scan Backward using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=4.00 loops=1)
                           Index Cond: (dev < NULL::integer)

\qecho range queries on :TABLE
range queries on skip_scan_ht
:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE time BETWEEN 100 AND 300 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE WHERE time < 200 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: _hyper_1_1_chunk.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" < 200))

:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE time > 800 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: _hyper_1_4_chunk.dev
   ->  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 count(DISTINCT time), time FROM :TABLE WHERE time BETWEEN 0 AND 5000  GROUP BY time;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1000.00 loops=1)
   Group Key: skip_scan_ht."time"
   ->  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 c1, c2, 'q4_1' FROM (SELECT count(DISTINCT dev) as c1, sum(DISTINCT dev) as c2 FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.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 NULL, dev, NULL, 'q4_2' FROM (SELECT count(DISTINCT dev) as dev FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.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 NULL, dev, NULL, c1, 2, c3, 'q4_3' FROM (SELECT count(DISTINCT dev) as c1, dev, 1 as c3 FROM :TABLE GROUP BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_ht.dev
         ->  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 ORDER BY
ORDER BY
:PREFIX SELECT c, dev, 'q5_1' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev ORDER BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_ht.dev
         ->  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 c, dev, 'q5_2' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev ORDER BY dev DESC) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_ht.dev
         ->  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_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 Backward 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 Backward 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 Backward 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 WHERE CLAUSES
WHERE CLAUSES
:PREFIX SELECT c, dev, 'q6_1' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE WHERE dev > 5 GROUP BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  GroupAggregate (actual rows=5.00 loops=1)
         Group Key: skip_scan_ht.dev
         ->  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_idx on _hyper_1_1_chunk (actual rows=5.00 loops=1)
                           Index Cond: ((dev > NULL::integer) AND (dev > 5))
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=5.00 loops=1)
                     ->  Index Only 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 > NULL::integer) AND (dev > 5))
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=5.00 loops=1)
                     ->  Index Only 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 > NULL::integer) AND (dev > 5))
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=5.00 loops=1)
                     ->  Index Only 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 > NULL::integer) AND (dev > 5))

:PREFIX SELECT c, dev, 'q6_2' FROM (SELECT sum(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev HAVING sum(DISTINCT dev)>2) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=8.00 loops=1)
   ->  GroupAggregate (actual rows=8.00 loops=1)
         Group Key: skip_scan_ht.dev
         Filter: (sum(DISTINCT skip_scan_ht.dev) > 2)
         Rows Removed by Filter: 3
         ->  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 c, dev, 'q6_3' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev) a WHERE dev > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  GroupAggregate (actual rows=5.00 loops=1)
         Group Key: skip_scan_ht.dev
         ->  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_idx on _hyper_1_1_chunk (actual rows=5.00 loops=1)
                           Index Cond: ((dev > NULL::integer) AND (dev > 5))
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=5.00 loops=1)
                     ->  Index Only 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 > NULL::integer) AND (dev > 5))
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=5.00 loops=1)
                     ->  Index Only 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 > NULL::integer) AND (dev > 5))
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=5.00 loops=1)
                     ->  Index Only 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 > NULL::integer) AND (dev > 5))

:PREFIX SELECT c, dev, 'q6_4' FROM (SELECT sum(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev) a WHERE c > 2;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=8.00 loops=1)
   ->  GroupAggregate (actual rows=8.00 loops=1)
         Group Key: skip_scan_ht.dev
         Filter: (sum(DISTINCT skip_scan_ht.dev) > 2)
         Rows Removed by Filter: 3
         ->  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 immutable func in WHERE clause on :TABLE
:PREFIX SELECT count(DISTINCT dev), 'q6_5' FROM :TABLE WHERE dev > int_func_immutable();
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 Only 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 > NULL::integer) AND (dev > 1))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=9.00 loops=1)
               ->  Index Only 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 > NULL::integer) AND (dev > 1))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=9.00 loops=1)
               ->  Index Only 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 > NULL::integer) AND (dev > 1))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=9.00 loops=1)
               ->  Index Only 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 > NULL::integer) AND (dev > 1))

--\qecho stable func in WHERE clause on :TABLE
:PREFIX SELECT count(DISTINCT dev), 'q6_6' FROM :TABLE WHERE dev > int_func_stable();
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 Only 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 > NULL::integer) AND (dev > int_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=8.00 loops=1)
                     ->  Index Only 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 > NULL::integer) AND (dev > int_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=8.00 loops=1)
                     ->  Index Only 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 > NULL::integer) AND (dev > int_func_stable()))
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=8.00 loops=1)
                     ->  Index Only 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 > NULL::integer) AND (dev > int_func_stable()))

--\qecho volatile func in WHERE clause on :TABLE:PREFIX SELECT count(DISTINCT dev), 'q6_7' FROM :TABLE WHERE dev > int_func_volatile();
:PREFIX SELECT count(DISTINCT dev), 'q6_8' FROM :TABLE WHERE dev = ANY(inta_func_immutable());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 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) AND (dev = ANY ('{1,2,3}'::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) AND (dev = ANY ('{1,2,3}'::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) AND (dev = ANY ('{1,2,3}'::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) AND (dev = ANY ('{1,2,3}'::integer[])))

:PREFIX SELECT count(DISTINCT dev), 'q6_9' FROM :TABLE WHERE dev = ANY(inta_func_stable());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 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) AND (dev = ANY (inta_func_stable())))
               ->  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) AND (dev = ANY (inta_func_stable())))
               ->  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) AND (dev = ANY (inta_func_stable())))
               ->  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) AND (dev = ANY (inta_func_stable())))

:PREFIX SELECT count(DISTINCT dev), 'q6_10' FROM :TABLE WHERE dev = ANY(inta_func_volatile());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 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)
                           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 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)
                           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 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)
                           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 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)
                           Filter: (dev = ANY (inta_func_volatile()))
                           Rows Removed by Filter: 1755

-- always false expr similar to our initial skip qual
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE dev > NULL;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev) FROM :TABLE WHERE dev > 20;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 Only 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 > NULL::integer) AND (dev > 20))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=0.00 loops=1)
               ->  Index Only 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 > NULL::integer) AND (dev > 20))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=0.00 loops=1)
               ->  Index Only 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 > NULL::integer) AND (dev > 20))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=0.00 loops=1)
               ->  Index Only 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 > NULL::integer) AND (dev > 20))

-- multiple constraints in WHERE clause
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE dev > 5 AND time = 100;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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_dev_time_idx on _hyper_1_1_chunk (actual rows=5.00 loops=1)
               Index Cond: ((dev > NULL::integer) AND (dev > 5) AND ("time" = 100))

:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE dev > 5 AND time > 200;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 Only 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 > NULL::integer) AND (dev > 5))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=5.00 loops=1)
               ->  Index Only 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 > NULL::integer) AND (dev > 5))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=5.00 loops=1)
               ->  Index Only 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 > NULL::integer) AND (dev > 5))

:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE dev >= 5 AND dev < 7 AND dev >= 2;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 Only 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 > NULL::integer) AND (dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=2.00 loops=1)
               ->  Index Only 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 > NULL::integer) AND (dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=2.00 loops=1)
               ->  Index Only 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 > NULL::integer) AND (dev >= 5) AND (dev < 7) AND (dev >= 2))
         ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=2.00 loops=1)
               ->  Index Only 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 > NULL::integer) AND (dev >= 5) AND (dev < 7) AND (dev >= 2))

:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE time > 100 AND time < 200 AND val > 10 AND val < 10000 AND dev > 2 AND dev < 7 GROUP BY dev ORDER BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=0.00 loops=1)
   Group Key: _hyper_1_1_chunk.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_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 count(DISTINCT dev) FROM :TABLE WHERE dev IS NULL;
--- QUERY PLAN ---
 Aggregate (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 count(DISTINCT dev_name) FROM :TABLE WHERE dev_name IS NULL;
--- QUERY PLAN ---
 Aggregate (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))

-- Distinct aggregate path with no pathkeys because of Const predicate.
-- PG is smart to add LIMIT 1 to SELECT DISTINCT in this case,
-- but not smart enough to add LIMIT 1 to distinct aggregate input.
-- TODO: create an issue for this task, i.e. add LIMIT 1 to distinct aggregate input when input equals to a Const
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE dev = 1;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Append (actual rows=1000.00 loops=1)
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)
         ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)
         ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)
         ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)

:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE dev = 1 GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1.00 loops=1)
   ->  Append (actual rows=1000.00 loops=1)
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)
         ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)
         ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)
         ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)

-- CTE
:PREFIX WITH devices AS (
	SELECT count(DISTINCT dev) FROM :TABLE
)
SELECT * FROM devices;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 dev, count(DISTINCT dev) FROM :TABLE GROUP BY dev
)
SELECT * FROM devices ORDER BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_ht.dev
   ->  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 count(DISTINCT dev_name) FROM :TABLE;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 ---
 Aggregate (actual rows=1.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 ---
 Aggregate (actual rows=1.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 c, 'q7_1' FROM (SELECT count(DISTINCT dev) c FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT * FROM :TABLE WHERE time != a.v) b) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.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 c, 'q7_2' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT count(DISTINCT dev) c FROM :TABLE WHERE dev != a.v) b) a;
--- QUERY PLAN ---
 Nested Loop (actual rows=2.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Aggregate (actual rows=1.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 Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=9.00 loops=2)
                           Index Cond: (dev > NULL::integer)
                           Filter: (dev <> "*VALUES*".column1)
                           Rows Removed by Filter: 250
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=9.00 loops=2)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=9.00 loops=2)
                           Index Cond: (dev > NULL::integer)
                           Filter: (dev <> "*VALUES*".column1)
                           Rows Removed by Filter: 250
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=9.00 loops=2)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=9.00 loops=2)
                           Index Cond: (dev > NULL::integer)
                           Filter: (dev <> "*VALUES*".column1)
                           Rows Removed by Filter: 250
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=9.00 loops=2)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=9.00 loops=2)
                           Index Cond: (dev > NULL::integer)
                           Filter: (dev <> "*VALUES*".column1)
                           Rows Removed by Filter: 250

-- RuntimeKeys
:PREFIX SELECT c, 'q8_1' FROM (SELECT * FROM (VALUES (1), (2)) a(v), LATERAL (SELECT count(DISTINCT dev) c FROM :TABLE WHERE dev >= a.v) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=2.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Aggregate (actual rows=1.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=9.50 loops=2)
                     ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx on _hyper_1_1_chunk (actual rows=9.50 loops=2)
                           Index Cond: ((dev > NULL::integer) AND (dev >= "*VALUES*".column1))
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk (actual rows=9.50 loops=2)
                     ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx on _hyper_1_2_chunk (actual rows=9.50 loops=2)
                           Index Cond: ((dev > NULL::integer) AND (dev >= "*VALUES*".column1))
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk (actual rows=9.50 loops=2)
                     ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx on _hyper_1_3_chunk (actual rows=9.50 loops=2)
                           Index Cond: ((dev > NULL::integer) AND (dev >= "*VALUES*".column1))
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk (actual rows=9.50 loops=2)
                     ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx on _hyper_1_4_chunk (actual rows=9.50 loops=2)
                           Index Cond: ((dev > NULL::integer) AND (dev >= "*VALUES*".column1))

--  DISTINCT aggs on different columns in different subqueries
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE UNION ALL SELECT count(DISTINCT time) FROM :TABLE;
--- QUERY PLAN ---
 Append (actual rows=2.00 loops=1)
   ->  Aggregate (actual rows=1.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)
   ->  Aggregate (actual rows=1.00 loops=1)
         ->  Merge Append (actual rows=1000.00 loops=1)
               Sort Key: skip_scan_ht_1."time"
               ->  Custom Scan (SkipScan) on _hyper_1_1_chunk _hyper_1_1_chunk_1 (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 _hyper_1_1_chunk_1 (actual rows=250.00 loops=1)
                           Index Cond: ("time" > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_2_chunk _hyper_1_2_chunk_1 (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 _hyper_1_2_chunk_1 (actual rows=250.00 loops=1)
                           Index Cond: ("time" > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_3_chunk _hyper_1_3_chunk_1 (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 _hyper_1_3_chunk_1 (actual rows=250.00 loops=1)
                           Index Cond: ("time" > NULL::integer)
               ->  Custom Scan (SkipScan) on _hyper_1_4_chunk _hyper_1_4_chunk_1 (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 _hyper_1_4_chunk_1 (actual rows=250.00 loops=1)
                           Index Cond: ("time" > NULL::integer)

:PREFIX SELECT *, 'q9_2' FROM (SELECT count(DISTINCT dev) cd, dev FROM :TABLE GROUP BY dev) a, LATERAL (SELECT count(DISTINCT time) ct FROM :TABLE WHERE dev = a.dev) b;
--- QUERY PLAN ---
 Nested Loop (actual rows=11.00 loops=1)
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_ht.dev
         ->  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)
   ->  Aggregate (actual rows=1.00 loops=11)
         ->  Merge Append (actual rows=909.09 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.27 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.27 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.27 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.27 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.27 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.27 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.27 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.27 loops=11)
                           Index Cond: ((dev = skip_scan_ht.dev) AND ("time" > NULL::integer))

-- SkipScan into INSERT
:PREFIX INSERT INTO skip_scan_insert(dev, val, query) SELECT dev, sd, 'q10_1' FROM (SELECT sum(DISTINCT dev) sd, dev FROM :TABLE GROUP BY dev) a;
--- QUERY PLAN ---
 Insert on skip_scan_insert (actual rows=0.00 loops=1)
   ->  Subquery Scan on a (actual rows=11.00 loops=1)
         ->  GroupAggregate (actual rows=11.00 loops=1)
               Group Key: skip_scan_ht.dev
               ->  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)

-- 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 count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT time) FROM skip_scan_nulls;
--- QUERY PLAN ---
 Aggregate (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 count(DISTINCT time) FROM skip_scan_nulls WHERE time IS NOT NULL;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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))

\ir include/skip_scan_dagg_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;
-- IndexPath without pathkeys doesnt use SkipScan
EXPLAIN (buffers off, costs off, timing off, summary off) SELECT count(DISTINCT 1) FROM pg_rewrite;
--- QUERY PLAN ---
 Aggregate
   ->  Index Only Scan using pg_rewrite_rel_rulename_index on pg_rewrite

:PREFIX SELECT count(DISTINCT dev) FROM :TABLE where dev=1;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Append (actual rows=1000.00 loops=1)
         ->  Index Only Scan using _hyper_1_1_chunk_skip_scan_ht_dev_idx1 on _hyper_1_1_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)
         ->  Index Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx1 on _hyper_1_2_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)
         ->  Index Only Scan using _hyper_1_3_chunk_skip_scan_ht_dev_idx1 on _hyper_1_3_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)
         ->  Index Only Scan using _hyper_1_4_chunk_skip_scan_ht_dev_idx1 on _hyper_1_4_chunk (actual rows=250.00 loops=1)
               Index Cond: (dev = 1)

-- SkipScan with ordered append
:PREFIX SELECT count(DISTINCT time), time FROM :TABLE GROUP BY time ORDER BY time;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1000.00 loops=1)
   Group Key: skip_scan_ht."time"
   ->  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 count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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_idx1 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_idx1 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_idx1 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_idx1 on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

-- compression on one chunk doesnt prevent skipscan on other chunks
SELECT compress_chunk('_timescaledb_internal._hyper_1_1_chunk');
             compress_chunk             
----------------------------------------
 _timescaledb_internal._hyper_1_1_chunk

:PREFIX SELECT count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 Only Scan using _hyper_1_2_chunk_skip_scan_ht_dev_idx1 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_idx1 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_idx1 on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

-- compression on one chunk will prevent skipscan if it's the only chunk remaining
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE time = 100;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Custom Scan (ColumnarScan) on _hyper_1_1_chunk (actual rows=11.00 loops=1)
         Vectorized Filter: ("time" = 100)
         Rows Removed by Filter: 2494
         ->  Sort (actual rows=11.00 loops=1)
               Sort Key: compress_hyper_2_17_chunk.dev
               Sort Method: quicksort 
               ->  Seq Scan on compress_hyper_2_17_chunk (actual rows=11.00 loops=1)
                     Filter: ((_ts_meta_min_1 <= 100) AND (_ts_meta_max_1 >= 100))

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

-- skipscan will be applied on decompressed chunk if it's the only chunk remaining
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE time = 100;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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" = 100))

--baseline query with skipscan
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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_idx1 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_idx1 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_idx1 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_idx1 on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

-- partial indexes don't prevent skipscan
DROP INDEX _timescaledb_internal._hyper_1_1_chunk_skip_scan_ht_dev_idx;
DROP INDEX _timescaledb_internal._hyper_1_1_chunk_skip_scan_ht_dev_idx1;
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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_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_idx1 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_idx1 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_idx1 on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

DROP INDEX _timescaledb_internal._hyper_1_1_chunk_skip_scan_ht_dev_time_idx;
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=2538.00 loops=1)
         Sort Key: skip_scan_ht.dev
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_1_1_chunk.dev
               Sort Method: quicksort 
               ->  Seq Scan on _hyper_1_1_chunk (actual rows=2505.00 loops=1)
         ->  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_idx1 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_idx1 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_idx1 on _hyper_1_4_chunk (actual rows=11.00 loops=1)
                     Index Cond: (dev > NULL::integer)

RESET timescaledb.enable_compressed_skipscan;
-- run tests on compressed hypertable with different compression settings
\set TABLE skip_scan_htc
\ir include/skip_scan_dagg_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 count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC NULLS FIRST;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE WHERE dev IS NOT NULL GROUP BY dev ORDER BY dev DESC NULLS FIRST;
--- QUERY PLAN ---
 GroupAggregate (actual rows=10.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE WHERE dev IS NOT NULL GROUP BY dev ORDER BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=10.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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)

-- NULLS FIRST doesn't match segmentby NULL direction
:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev NULLS FIRST;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_htc.dev NULLS FIRST
         ->  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 NULLS FIRST
                     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 NULLS FIRST
                     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 NULLS FIRST
                     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 NULLS FIRST
                     Sort Method: quicksort 
                     ->  Seq Scan on compress_hyper_4_21_chunk (actual rows=11.00 loops=1)

-- 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

-- multicolumn compressed index with dev as leading column
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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_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)

-- Test not-NULL mode
:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE dev IS NOT NULL GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=10.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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_22_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_22_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_23_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_23_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_24_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_24_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_25_chunk_dev_dev_name__ts_meta_min_1__ts_m_idx on compress_hyper_4_25_chunk (actual rows=10.00 loops=1)
                           Index Cond: (dev IS NOT NULL)

-- multicolumn compressed index with dev as leading column and with extra distinct column pinned
-- TODO: should be able to apply SkipScan here, issue created: #7998
:PREFIX SELECT count(DISTINCT dev), count(DISTINCT dev_name) FROM :TABLE WHERE dev_name = 'device_1';
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=1000.00 loops=1)
         Sort Key: skip_scan_htc.dev
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=250.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_name = 'device_1'::text)
         ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=250.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_name = 'device_1'::text)
         ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=250.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_name = 'device_1'::text)
         ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=250.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_name = 'device_1'::text)

-- multicolumn compressed index with dev as non-leading column
:PREFIX SELECT count(DISTINCT dev_name) FROM :TABLE WHERE dev = 1;
--- QUERY PLAN ---
 Aggregate (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)

:PREFIX SELECT count(DISTINCT dev_name), dev_name FROM :TABLE WHERE dev = 1 GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  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)

-- multicolumn compressed index with dev as non-leading column and with leading column pinned
-- TODO: should be able to apply SkipScan here, issue created: #7998
:PREFIX SELECT count(DISTINCT dev), count(DISTINCT dev_name) FROM :TABLE WHERE dev = 1;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=1000.00 loops=1)
         Sort Key: skip_scan_htc.dev_name
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=250.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 (ColumnarScan) on _hyper_3_6_chunk (actual rows=250.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 (ColumnarScan) on _hyper_3_7_chunk (actual rows=250.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 (ColumnarScan) on _hyper_3_8_chunk (actual rows=250.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
-- Various distint aggs over same column is OK
:PREFIX SELECT count(DISTINCT dev), sum(DISTINCT dev), 'q1_1' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 agg over Const is OK
:PREFIX SELECT count(DISTINCT dev), count(DISTINCT 2), 'q1_3', NULL FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 over distinct agg is OK
:PREFIX SELECT DISTINCT count(DISTINCT dev), dev, 'q1_4' FROM :TABLE GROUP BY dev ORDER BY dev;
--- QUERY PLAN ---
 Sort (actual rows=11.00 loops=1)
   Sort Key: skip_scan_htc.dev
   Sort Method: quicksort 
   ->  HashAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_htc.dev, count(DISTINCT skip_scan_htc.dev)
         ->  GroupAggregate (actual rows=11.00 loops=1)
               Group Key: skip_scan_htc.dev
               ->  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 count(DISTINCT dev), 'q1_5', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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
:PREFIX SELECT count(DISTINCT dev), 'q1_7', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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)

-- Mix of aggregates on different columns and distinct/not distinct
-- currently not supported by skipscan
:PREFIX SELECT count(DISTINCT dev), max(DISTINCT dev_name), 'q1_9' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  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_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 (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.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 (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.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 (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.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 count(DISTINCT dev), sum(dev), 'q1_10' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  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_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 (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.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 (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.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 (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.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 count(DISTINCT dev), dev_name, 'q1_11' FROM :TABLE GROUP BY dev_name ORDER BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_htc.dev_name, skip_scan_htc.dev
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_5_chunk.dev_name, _hyper_3_5_chunk.dev
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_6_chunk.dev_name, _hyper_3_6_chunk.dev
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_7_chunk.dev_name, _hyper_3_7_chunk.dev
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_8_chunk.dev_name, _hyper_3_8_chunk.dev
               Sort Method: quicksort 
               ->  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 expressions not supported
:PREFIX SELECT count(DISTINCT dev + 1), 'q1_13' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: ((skip_scan_htc.dev + 1))
         ->  Result (actual rows=2505.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=2505.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)
         ->  Result (actual rows=2505.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=2505.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)
         ->  Result (actual rows=2505.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=2505.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)
         ->  Result (actual rows=2505.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=2505.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)

-- But expressions over distinct aggregates are supported
:PREFIX SELECT count(DISTINCT dev) + 1, sum(DISTINCT dev)/count(DISTINCT dev), 'q1_15' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 aggs grouped on their args
:PREFIX SELECT count(DISTINCT dev), dev, 'q2_1' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev), dev, 'q2_2', NULL FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev), dev, 'q2_3', length(md5(now()::text)) FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev), dev, 'q2_4', length(md5(random()::text)) FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev), dev, int_func_immutable(), 'q2_5' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev), dev, int_func_stable(), 'q2_6' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev), dev, int_func_volatile(), 'q2_7' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev), dev+1, 'q2_8' FROM :TABLE GROUP BY dev ORDER BY 2;
--- QUERY PLAN ---
 Sort (actual rows=11.00 loops=1)
   Sort Key: ((skip_scan_htc.dev + 1))
   Sort Method: quicksort 
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_htc.dev
         ->  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 count(DISTINCT dev), dev+1, dev+2, 'q2_9' FROM :TABLE GROUP BY dev, dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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)

-- Cannot do SkipScan as we group on a column which is not the distinct agg argument
:PREFIX SELECT time, count(DISTINCT dev), 'q2_10' FROM :TABLE GROUP BY time;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1000.00 loops=1)
   Group Key: skip_scan_htc."time"
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_htc."time", skip_scan_htc.dev
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_5_chunk."time", _hyper_3_5_chunk.dev
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_6_chunk."time", _hyper_3_6_chunk.dev
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_7_chunk."time", _hyper_3_7_chunk.dev
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_8_chunk."time", _hyper_3_8_chunk.dev
               Sort Method: quicksort 
               ->  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)

-- Cannot do SkipScan if we group on 2+ columns
:PREFIX SELECT count(DISTINCT dev), dev, tableoid::regclass, 'q2_11' FROM :TABLE GROUP BY dev, tableoid ORDER BY dev, tableoid;
--- QUERY PLAN ---
 GroupAggregate (actual rows=44.00 loops=1)
   Group Key: skip_scan_htc.dev, skip_scan_htc.tableoid
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_htc.dev, skip_scan_htc.tableoid
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_5_chunk.dev, _hyper_3_5_chunk.tableoid
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_6_chunk.dev, _hyper_3_6_chunk.tableoid
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_7_chunk.dev, _hyper_3_7_chunk.tableoid
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_8_chunk.dev, _hyper_3_8_chunk.tableoid
               Sort Method: quicksort 
               ->  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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  GroupAggregate (actual rows=3.00 loops=1)
         Group Key: skip_scan_htc.dev
         ->  Merge Append (actual rows=13.00 loops=1)
               Sort Key: skip_scan_htc.dev
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=4.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=4.00 loops=1)

:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  GroupAggregate (actual rows=3.00 loops=1)
         Group Key: skip_scan_htc.dev
         ->  Merge Append (actual rows=13.00 loops=1)
               Sort Key: skip_scan_htc.dev DESC
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=4.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=4.00 loops=1)

\qecho range queries on :TABLE
range queries on skip_scan_htc
:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE time BETWEEN 100 AND 300 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE WHERE time < 200 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: _hyper_3_5_chunk.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" < 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 count(DISTINCT dev), dev FROM :TABLE WHERE time > 800 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: _hyper_3_8_chunk.dev
   ->  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

-- Various distint aggs over same column is OK
:PREFIX SELECT count(DISTINCT dev_name), max(DISTINCT dev_name), 'q1_2' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev_name), 'q1_6', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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
:PREFIX SELECT count(DISTINCT dev_name), 'q1_8', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev_name) FROM :TABLE WHERE dev_name IS NULL;
--- QUERY PLAN ---
 Aggregate (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)

-- distinct on expressions not supported
:PREFIX SELECT count(DISTINCT length(dev_name)), 'q1_13' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: (length(skip_scan_htc.dev_name))
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: (length(_hyper_3_5_chunk.dev_name))
               Sort Method: quicksort 
               ->  Result (actual rows=2505.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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: (length(_hyper_3_6_chunk.dev_name))
               Sort Method: quicksort 
               ->  Result (actual rows=2505.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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: (length(_hyper_3_7_chunk.dev_name))
               Sort Method: quicksort 
               ->  Result (actual rows=2505.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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: (length(_hyper_3_8_chunk.dev_name))
               Sort Method: quicksort 
               ->  Result (actual rows=2505.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 aggs grouped on their TEXT args
:PREFIX SELECT count(DISTINCT dev_name), dev_name, 'q3_1' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_11' FROM :TABLE WHERE dev_name IS NOT NULL GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=10.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_2', NULL FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_3', length(md5(now()::text)) FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, 'q3_4', length(md5(random()::text)) FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  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 count(DISTINCT dev_name::varchar), dev_name::varchar, 'q3_5' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, int_func_immutable(), 'q3_6' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, int_func_stable(), 'q3_7' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  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 count(DISTINCT dev_name), dev_name, int_func_volatile(), 'q3_8' FROM :TABLE GROUP BY dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  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)

-- Cannot do SkipScan as we group on a column which is not the distinct agg argument
:PREFIX SELECT count(DISTINCT dev_name), dev_name, tableoid::regclass, 'q3_9' FROM :TABLE GROUP BY dev_name, tableoid ORDER BY dev_name, tableoid;
--- QUERY PLAN ---
 GroupAggregate (actual rows=44.00 loops=1)
   Group Key: skip_scan_htc.dev_name, skip_scan_htc.tableoid
   ->  Merge Append (actual rows=10020.00 loops=1)
         Sort Key: skip_scan_htc.dev_name, skip_scan_htc.tableoid
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_5_chunk.dev_name, _hyper_3_5_chunk.tableoid
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_6_chunk.dev_name, _hyper_3_6_chunk.tableoid
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_7_chunk.dev_name, _hyper_3_7_chunk.tableoid
               Sort Method: quicksort 
               ->  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)
         ->  Sort (actual rows=2505.00 loops=1)
               Sort Key: _hyper_3_8_chunk.dev_name, _hyper_3_8_chunk.tableoid
               Sort Method: quicksort 
               ->  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)

-- Can do SkipScan if extra group column is eliminated by pinning to a Const
-- and when it changes group by ordering
:PREFIX SELECT count(DISTINCT dev_name), dev, dev_name FROM :TABLE WHERE dev = 1 GROUP BY dev, dev_name ORDER BY dev, dev_name;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1.00 loops=1)
   Group Key: skip_scan_htc.dev_name
   ->  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)
                     Vectorized Filter: (dev = 1)
                     Rows Removed by Filter: 2255
                     ->  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=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: (dev = 1)
                     Rows Removed by Filter: 2255
                     ->  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=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: (dev = 1)
                     Rows Removed by Filter: 2255
                     ->  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=1.00 loops=1)
               ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=1.00 loops=1)
                     Vectorized Filter: (dev = 1)
                     Rows Removed by Filter: 2255
                     ->  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)

-- 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 c1, c2, 'q4_1' FROM (SELECT count(DISTINCT dev) as c1, sum(DISTINCT dev) as c2 FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.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_2' FROM (SELECT count(DISTINCT dev) as dev FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.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, c1, 2, c3, 'q4_3' FROM (SELECT count(DISTINCT dev) as c1, dev, 1 as c3 FROM :TABLE GROUP BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_htc.dev
         ->  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 c, dev, 'q5_1' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev ORDER BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_htc.dev
         ->  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 c, dev, 'q5_2' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev ORDER BY dev DESC) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_htc.dev
         ->  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_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 c, dev, 'q6_1' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE WHERE dev > 5 GROUP BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  GroupAggregate (actual rows=5.00 loops=1)
         Group Key: skip_scan_htc.dev
         ->  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 c, dev, 'q6_2' FROM (SELECT sum(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev HAVING sum(DISTINCT dev)>2) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=8.00 loops=1)
   ->  GroupAggregate (actual rows=8.00 loops=1)
         Group Key: skip_scan_htc.dev
         Filter: (sum(DISTINCT skip_scan_htc.dev) > 2)
         Rows Removed by Filter: 3
         ->  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 c, dev, 'q6_3' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev) a WHERE dev > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  GroupAggregate (actual rows=5.00 loops=1)
         Group Key: skip_scan_htc.dev
         ->  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 c, dev, 'q6_4' FROM (SELECT sum(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev) a WHERE c > 2;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=8.00 loops=1)
   ->  GroupAggregate (actual rows=8.00 loops=1)
         Group Key: skip_scan_htc.dev
         Filter: (sum(DISTINCT skip_scan_htc.dev) > 2)
         Rows Removed by Filter: 3
         ->  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 count(DISTINCT dev), 'q6_5' FROM :TABLE WHERE dev > int_func_immutable();
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), 'q6_6' FROM :TABLE WHERE dev > int_func_stable();
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), 'q6_7' FROM :TABLE WHERE dev > int_func_volatile();
:PREFIX SELECT count(DISTINCT dev), 'q6_8' FROM :TABLE WHERE dev = ANY(inta_func_immutable());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), 'q6_9' FROM :TABLE WHERE dev = ANY(inta_func_stable());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), 'q6_10' FROM :TABLE WHERE dev = ANY(inta_func_volatile());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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)

-- always false expr similar to our initial skip qual
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE dev > NULL;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev) FROM :TABLE WHERE dev > 20;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev) FROM :TABLE WHERE dev > 5 AND time = 100;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev) FROM :TABLE WHERE dev > 5 AND time > 200;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev) FROM :TABLE WHERE dev >= 5 AND dev < 7 AND dev >= 2;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), dev FROM :TABLE WHERE time > 100 AND time < 200 AND val > 10 AND val < 10000 AND dev > 2 AND dev < 7 GROUP BY dev ORDER BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=0.00 loops=1)
   Group Key: _hyper_3_5_chunk.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)
               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 count(DISTINCT dev) FROM :TABLE WHERE dev IS NULL;
--- QUERY PLAN ---
 Aggregate (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)

-- Distinct aggregate path with no pathkeys because of Const predicate.
-- PG is smart to add LIMIT 1 to SELECT DISTINCT in this case,
-- but not smart enough to add LIMIT 1 to distinct aggregate input.
-- TODO: create an issue for this task, i.e. add LIMIT 1 to distinct aggregate input when input equals to a Const
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE dev = 1;
--- QUERY PLAN ---
 Aggregate (actual rows=1.00 loops=1)
   ->  Append (actual rows=1000.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=250.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 = 1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=250.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 = 1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=250.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 = 1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=250.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 = 1)

:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE dev = 1 GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=1.00 loops=1)
   ->  Append (actual rows=1000.00 loops=1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=250.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 = 1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=250.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 = 1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=250.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 = 1)
         ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=250.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 = 1)

-- CTE
:PREFIX WITH devices AS (
	SELECT count(DISTINCT dev) FROM :TABLE
)
SELECT * FROM devices;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 dev, count(DISTINCT dev) FROM :TABLE GROUP BY dev
)
SELECT * FROM devices ORDER BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htc.dev
   ->  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 count(DISTINCT dev) FROM :TABLE;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 ---
 Aggregate (actual rows=1.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 ---
 Aggregate (actual rows=1.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
:PREFIX SELECT c, 'q7_1' FROM (SELECT count(DISTINCT dev) c FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT * FROM :TABLE WHERE time != a.v) b) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.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)

:PREFIX SELECT c, 'q7_2' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT count(DISTINCT dev) c FROM :TABLE WHERE dev != a.v) b) a;
--- QUERY PLAN ---
 Nested Loop (actual rows=2.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Aggregate (actual rows=1.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 c, 'q8_1' FROM (SELECT * FROM (VALUES (1), (2)) a(v), LATERAL (SELECT count(DISTINCT dev) c FROM :TABLE WHERE dev >= a.v) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=2.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Aggregate (actual rows=1.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=9.50 loops=2)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk (actual rows=9.50 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.50 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk (actual rows=9.50 loops=2)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk (actual rows=9.50 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.50 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk (actual rows=9.50 loops=2)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk (actual rows=9.50 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.50 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk (actual rows=9.50 loops=2)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk (actual rows=9.50 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.50 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)

--  DISTINCT aggs on different columns in different subqueries
-- "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 count(DISTINCT dev) FROM :TABLE UNION ALL SELECT count(DISTINCT val) FROM :TABLE WHERE dev = 1;
--- QUERY PLAN ---
 Append (actual rows=2.00 loops=1)
   ->  Aggregate (actual rows=1.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)
   ->  Aggregate (actual rows=1.00 loops=1)
         ->  Merge Append (actual rows=8.00 loops=1)
               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=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk _hyper_3_5_chunk_1 (actual rows=2.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=2.00 loops=1)
                                 Index Cond: (dev = 1)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=2.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=2.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=2.00 loops=1)
                                 Index Cond: (dev = 1)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=2.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=2.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=2.00 loops=1)
                                 Index Cond: (dev = 1)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=2.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=2.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=2.00 loops=1)
                                 Index Cond: (dev = 1)

:PREFIX SELECT *, 'q9_2' FROM (SELECT count(DISTINCT dev) cd, dev FROM :TABLE GROUP BY dev) a, LATERAL (SELECT count(DISTINCT val) ct FROM :TABLE WHERE dev = a.dev) b;
--- QUERY PLAN ---
 Nested Loop (actual rows=11.00 loops=1)
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_htc.dev
         ->  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)
   ->  Aggregate (actual rows=1.00 loops=11)
         ->  Merge Append (actual rows=7.27 loops=11)
               Sort Key: skip_scan_htc_1.val
               ->  Custom Scan (SkipScan) on _hyper_3_5_chunk _hyper_3_5_chunk_1 (actual rows=1.82 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_5_chunk _hyper_3_5_chunk_1 (actual rows=1.82 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=1.82 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)
               ->  Custom Scan (SkipScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=1.82 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_6_chunk _hyper_3_6_chunk_1 (actual rows=1.82 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=1.82 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)
               ->  Custom Scan (SkipScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=1.82 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_7_chunk _hyper_3_7_chunk_1 (actual rows=1.82 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=1.82 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)
               ->  Custom Scan (SkipScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=1.82 loops=11)
                     ->  Custom Scan (ColumnarScan) on _hyper_3_8_chunk _hyper_3_8_chunk_1 (actual rows=1.82 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=1.82 loops=11)
                                 Index Cond: (dev = skip_scan_htc.dev)

-- SkipScan into INSERT
:PREFIX INSERT INTO skip_scan_insert(dev, val, query) SELECT dev, sd, 'q10_1' FROM (SELECT sum(DISTINCT dev) sd, dev FROM :TABLE GROUP BY dev) a;
--- QUERY PLAN ---
 Insert on skip_scan_insert (actual rows=0.00 loops=1)
   ->  Subquery Scan on a (actual rows=11.00 loops=1)
         ->  GroupAggregate (actual rows=11.00 loops=1)
               Group Key: skip_scan_htc.dev
               ->  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 count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev) FROM :TABLE where val IS NULL;
--- QUERY PLAN ---
 Aggregate (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 count(DISTINCT dev) FROM :TABLE WHERE val IS NULL AND dev > 100;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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_dagg_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 count(DISTINCT dev) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC NULLS FIRST;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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)

\qecho basic DISTINCT queries on :TABLE
basic DISTINCT queries on skip_scan_htcl
-- Various distint aggs over same column is OK
:PREFIX SELECT count(DISTINCT dev), sum(DISTINCT dev), 'q1_1' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 agg over Const is OK
:PREFIX SELECT count(DISTINCT dev), count(DISTINCT 2), 'q1_3', NULL FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 over distinct agg is OK
:PREFIX SELECT DISTINCT count(DISTINCT dev), dev, 'q1_4' FROM :TABLE GROUP BY dev ORDER BY dev;
--- QUERY PLAN ---
 Unique (actual rows=11.00 loops=1)
   ->  Incremental Sort (actual rows=11.00 loops=1)
         Sort Key: skip_scan_htcl.dev, (count(DISTINCT skip_scan_htcl.dev))
         Presorted Key: skip_scan_htcl.dev
         Full-sort Groups: 1  Sort Method: quicksort 
         ->  GroupAggregate (actual rows=11.00 loops=1)
               Group Key: skip_scan_htcl.dev
               ->  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 stable expression in targetlist on :TABLE
stable expression in targetlist on skip_scan_htcl
:PREFIX SELECT count(DISTINCT dev), 'q1_5', length(md5(now()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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)

-- volatile expression in targetlist
:PREFIX SELECT count(DISTINCT dev), 'q1_7', length(md5(random()::text)) FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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)

-- expressions over distinct aggregates are supported
:PREFIX SELECT count(DISTINCT dev) + 1, sum(DISTINCT dev)/count(DISTINCT dev), 'q1_15' FROM :TABLE;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 aggs grouped on their args
:PREFIX SELECT count(DISTINCT dev), dev, 'q2_1' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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 count(DISTINCT dev), dev, 'q2_2', NULL FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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 count(DISTINCT dev), dev, 'q2_3', length(md5(now()::text)) FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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 count(DISTINCT dev), dev, 'q2_4', length(md5(random()::text)) FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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 count(DISTINCT dev), dev, int_func_immutable(), 'q2_5' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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 count(DISTINCT dev), dev, int_func_stable(), 'q2_6' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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 count(DISTINCT dev), dev, int_func_volatile(), 'q2_7' FROM :TABLE GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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 count(DISTINCT dev), dev+1, 'q2_8' FROM :TABLE GROUP BY dev ORDER BY 2;
--- QUERY PLAN ---
 Sort (actual rows=11.00 loops=1)
   Sort Key: ((skip_scan_htcl.dev + 1))
   Sort Method: quicksort 
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_htcl.dev
         ->  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 count(DISTINCT dev), dev+1, dev+2, 'q2_9' FROM :TABLE GROUP BY dev, dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE GROUP BY dev LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  GroupAggregate (actual rows=3.00 loops=1)
         Group Key: skip_scan_htcl.dev
         ->  Merge Append (actual rows=13.00 loops=1)
               Sort Key: skip_scan_htcl.dev
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=4.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=4.00 loops=1)

:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE GROUP BY dev ORDER BY dev DESC LIMIT 3;
--- QUERY PLAN ---
 Limit (actual rows=3.00 loops=1)
   ->  GroupAggregate (actual rows=3.00 loops=1)
         Group Key: skip_scan_htcl.dev
         ->  Merge Append (actual rows=13.00 loops=1)
               Sort Key: skip_scan_htcl.dev DESC
               ->  Custom Scan (SkipScan) on _hyper_5_9_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=4.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=4.00 loops=1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=4.00 loops=1)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=4.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=4.00 loops=1)

\qecho range queries on :TABLE
range queries on skip_scan_htcl
set enable_seqscan to off;
:PREFIX SELECT count(DISTINCT dev), dev FROM :TABLE WHERE time BETWEEN 100 AND 300 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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 count(DISTINCT dev), dev FROM :TABLE WHERE time < 200 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: _hyper_5_9_chunk.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" < 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 count(DISTINCT dev), dev FROM :TABLE WHERE time > 800 GROUP BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: _hyper_5_13_chunk.dev
   ->  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 c1, c2, 'q4_1' FROM (SELECT count(DISTINCT dev) as c1, sum(DISTINCT dev) as c2 FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.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_2' FROM (SELECT count(DISTINCT dev) as dev FROM :TABLE) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.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, c1, 2, c3, 'q4_3' FROM (SELECT count(DISTINCT dev) as c1, dev, 1 as c3 FROM :TABLE GROUP BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_htcl.dev
         ->  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 c, dev, 'q5_1' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev ORDER BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_htcl.dev
         ->  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 c, dev, 'q5_2' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev ORDER BY dev DESC) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=11.00 loops=1)
   ->  GroupAggregate (actual rows=11.00 loops=1)
         Group Key: skip_scan_htcl.dev
         ->  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)

-- 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;
\qecho WHERE CLAUSES
WHERE CLAUSES
:PREFIX SELECT c, dev, 'q6_1' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE WHERE dev > 5 GROUP BY dev) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  GroupAggregate (actual rows=5.00 loops=1)
         Group Key: skip_scan_htcl.dev
         ->  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 c, dev, 'q6_2' FROM (SELECT sum(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev HAVING sum(DISTINCT dev)>2) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=8.00 loops=1)
   ->  GroupAggregate (actual rows=8.00 loops=1)
         Group Key: skip_scan_htcl.dev
         Filter: (sum(DISTINCT skip_scan_htcl.dev) > 2)
         Rows Removed by Filter: 3
         ->  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 c, dev, 'q6_3' FROM (SELECT count(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev) a WHERE dev > 5;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=5.00 loops=1)
   ->  GroupAggregate (actual rows=5.00 loops=1)
         Group Key: skip_scan_htcl.dev
         ->  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 c, dev, 'q6_4' FROM (SELECT sum(DISTINCT dev) as c, dev FROM :TABLE GROUP BY dev) a WHERE c > 2;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=8.00 loops=1)
   ->  GroupAggregate (actual rows=8.00 loops=1)
         Group Key: skip_scan_htcl.dev
         Filter: (sum(DISTINCT skip_scan_htcl.dev) > 2)
         Rows Removed by Filter: 3
         ->  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 immutable func in WHERE clause on :TABLE
:PREFIX SELECT count(DISTINCT dev), 'q6_5' FROM :TABLE WHERE dev > int_func_immutable();
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), 'q6_6' FROM :TABLE WHERE dev > int_func_stable();
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), 'q6_7' FROM :TABLE WHERE dev > int_func_volatile();
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), 'q6_8' FROM :TABLE WHERE dev = ANY(inta_func_immutable());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), 'q6_9' FROM :TABLE WHERE dev = ANY(inta_func_stable());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), 'q6_10' FROM :TABLE WHERE dev = ANY(inta_func_volatile());
--- QUERY PLAN ---
 Aggregate (actual rows=1.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)

-- always false expr similar to our initial skip qual
:PREFIX SELECT count(DISTINCT dev) FROM :TABLE WHERE dev > NULL;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev) FROM :TABLE WHERE dev > 20;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev) FROM :TABLE WHERE dev > 5 AND time = 100;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev) FROM :TABLE WHERE dev > 5 AND time > 200;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev) FROM :TABLE WHERE dev >= 5 AND dev < 7 AND dev >= 2;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 count(DISTINCT dev), dev FROM :TABLE WHERE time > 100 AND time < 200 AND val > 10 AND val < 10000 AND dev > 2 AND dev < 7 GROUP BY dev ORDER BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=0.00 loops=1)
   Group Key: _hyper_5_9_chunk.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)
               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 count(DISTINCT dev) FROM :TABLE WHERE dev IS NULL;
--- QUERY PLAN ---
 Aggregate (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)

-- CTE
:PREFIX WITH devices AS (
	SELECT count(DISTINCT dev) FROM :TABLE
)
SELECT * FROM devices;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 dev, count(DISTINCT dev) FROM :TABLE GROUP BY dev
)
SELECT * FROM devices ORDER BY dev;
--- QUERY PLAN ---
 GroupAggregate (actual rows=11.00 loops=1)
   Group Key: skip_scan_htcl.dev
   ->  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 count(DISTINCT dev) FROM :TABLE;
:PREFIX EXECUTE prep;
--- QUERY PLAN ---
 Aggregate (actual rows=1.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 ---
 Aggregate (actual rows=1.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 ---
 Aggregate (actual rows=1.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
:PREFIX SELECT c, 'q7_1' FROM (SELECT count(DISTINCT dev) c FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT * FROM :TABLE WHERE time != a.v) b) a;
--- QUERY PLAN ---
 Subquery Scan on a (actual rows=1.00 loops=1)
   ->  Aggregate (actual rows=1.00 loops=1)
         ->  Nested Loop (actual rows=20020.00 loops=1)
               Join Filter: (skip_scan_htcl."time" <> "*VALUES*".column1)
               Rows Removed by Join Filter: 20
               ->  Merge Append (actual rows=10020.00 loops=1)
                     Sort Key: skip_scan_htcl.dev
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=2505.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 (ColumnarScan) on _hyper_5_11_chunk (actual rows=2505.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 (ColumnarScan) on _hyper_5_12_chunk (actual rows=2505.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 (ColumnarScan) on _hyper_5_13_chunk (actual rows=2505.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)
               ->  Materialize (actual rows=2.00 loops=10020)
                     ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)

:PREFIX SELECT c, 'q7_2' FROM (SELECT * FROM (
    VALUES (1), (2)) a(v),
    LATERAL (SELECT count(DISTINCT dev) c FROM :TABLE WHERE dev != a.v) b) a;
--- QUERY PLAN ---
 Nested Loop (actual rows=2.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Aggregate (actual rows=1.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 c, 'q8_1' FROM (SELECT * FROM (VALUES (1), (2)) a(v), LATERAL (SELECT count(DISTINCT dev) c FROM :TABLE WHERE dev >= a.v) b) c;
--- QUERY PLAN ---
 Nested Loop (actual rows=2.00 loops=1)
   ->  Values Scan on "*VALUES*" (actual rows=2.00 loops=1)
   ->  Aggregate (actual rows=1.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=9.50 loops=2)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_9_chunk (actual rows=9.50 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.50 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)
               ->  Custom Scan (SkipScan) on _hyper_5_11_chunk (actual rows=9.50 loops=2)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_11_chunk (actual rows=9.50 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.50 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)
               ->  Custom Scan (SkipScan) on _hyper_5_12_chunk (actual rows=9.50 loops=2)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_12_chunk (actual rows=9.50 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.50 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)
               ->  Custom Scan (SkipScan) on _hyper_5_13_chunk (actual rows=9.50 loops=2)
                     ->  Custom Scan (ColumnarScan) on _hyper_5_13_chunk (actual rows=9.50 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.50 loops=2)
                                 Index Cond: (dev >= "*VALUES*".column1)

RESET max_parallel_workers_per_gather;
RESET enable_seqscan;
