-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
\set PREFIX 'EXPLAIN (buffers off, costs off) '
\ir include/plan_expand_hypertable_load.sql
-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
--single time dimension
CREATE TABLE hyper ("time_broken" bigint NOT NULL, "value" integer);
ALTER TABLE hyper
DROP COLUMN time_broken,
ADD COLUMN time BIGINT;
SELECT create_hypertable('hyper', 'time',  chunk_time_interval => 10);
 create_hypertable  
--------------------
 (1,public,hyper,t)

INSERT INTO hyper SELECT g, g FROM generate_series(0,1000) g;
--insert a point with INT_MAX_64
INSERT INTO hyper (time, value) SELECT 9223372036854775807::bigint, 0;
--time and space
CREATE TABLE hyper_w_space ("time_broken" bigint NOT NULL, "device_id" text, "value" integer);
ALTER TABLE hyper_w_space
DROP COLUMN time_broken,
ADD COLUMN time BIGINT;
SELECT create_hypertable('hyper_w_space', 'time', 'device_id', 4, chunk_time_interval => 10);
     create_hypertable      
----------------------------
 (2,public,hyper_w_space,t)

INSERT INTO hyper_w_space (time, device_id, value) SELECT g, 'dev' || g, g FROM generate_series(0,30) g;
CREATE VIEW hyper_w_space_view AS (SELECT * FROM hyper_w_space);
--with timestamp and space
CREATE TABLE tag (id serial PRIMARY KEY, name text);
CREATE TABLE hyper_ts ("time_broken" timestamptz NOT NULL, "device_id" text, tag_id INT REFERENCES tag(id), "value" integer);
ALTER TABLE hyper_ts
DROP COLUMN time_broken,
ADD COLUMN time TIMESTAMPTZ;
SELECT create_hypertable('hyper_ts', 'time', 'device_id', 2, chunk_time_interval => '10 seconds'::interval);
   create_hypertable   
-----------------------
 (3,public,hyper_ts,t)

INSERT INTO tag(name) SELECT 'tag'||g FROM generate_series(0,10) g;
INSERT INTO hyper_ts (time, device_id, tag_id, value) SELECT to_timestamp(g), 'dev' || g, (random() /10)+1, g FROM generate_series(0,30) g;
--one in the future
INSERT INTO hyper_ts (time, device_id, tag_id, value)  VALUES ('2100-01-01 02:03:04 PST', 'dev101', 1, 0);
--time partitioning function
CREATE OR REPLACE FUNCTION unix_to_timestamp(unixtime float8)
    RETURNS TIMESTAMPTZ LANGUAGE SQL IMMUTABLE PARALLEL SAFE STRICT AS
$BODY$
    SELECT to_timestamp(unixtime);
$BODY$;
CREATE TABLE hyper_timefunc ("time" float8 NOT NULL, "device_id" text, "value" integer);
SELECT create_hypertable('hyper_timefunc', 'time', 'device_id', 4, chunk_time_interval => 10, time_partitioning_func => 'unix_to_timestamp');
psql:include/plan_expand_hypertable_load.sql:57: WARNING:  unexpected interval: smaller than one second
      create_hypertable      
-----------------------------
 (4,public,hyper_timefunc,t)

INSERT INTO hyper_timefunc (time, device_id, value) SELECT g, 'dev' || g, g FROM generate_series(0,30) g;
CREATE TABLE metrics_timestamp(time timestamp);
SELECT create_hypertable('metrics_timestamp','time');
psql:include/plan_expand_hypertable_load.sql:62: WARNING:  column type "timestamp without time zone" used for "time" does not follow best practices
       create_hypertable        
--------------------------------
 (5,public,metrics_timestamp,t)

INSERT INTO metrics_timestamp SELECT generate_series('2000-01-01'::timestamp,'2000-02-01'::timestamp,'1d'::interval);
CREATE TABLE metrics_timestamptz(time timestamptz, device_id int);
SELECT create_hypertable('metrics_timestamptz','time');
        create_hypertable         
----------------------------------
 (6,public,metrics_timestamptz,t)

INSERT INTO metrics_timestamptz SELECT generate_series('2000-01-01'::timestamptz,'2000-02-01'::timestamptz,'1d'::interval), 1;
INSERT INTO metrics_timestamptz SELECT generate_series('2000-01-01'::timestamptz,'2000-02-01'::timestamptz,'1d'::interval), 2;
INSERT INTO metrics_timestamptz SELECT generate_series('2000-01-01'::timestamptz,'2000-02-01'::timestamptz,'1d'::interval), 3;
--create a second table to test joins with
CREATE TABLE metrics_timestamptz_2 (LIKE metrics_timestamptz);
SELECT create_hypertable('metrics_timestamptz_2','time');
         create_hypertable          
------------------------------------
 (7,public,metrics_timestamptz_2,t)

INSERT INTO metrics_timestamptz_2
SELECT * FROM metrics_timestamptz;
INSERT INTO metrics_timestamptz_2 VALUES ('2000-12-01'::timestamptz, 3);
CREATE TABLE metrics_date(time date);
SELECT create_hypertable('metrics_date','time');
     create_hypertable     
---------------------------
 (8,public,metrics_date,t)

INSERT INTO metrics_date SELECT generate_series('2000-01-01'::date,'2000-02-01'::date,'1d'::interval);
ANALYZE hyper;
ANALYZE hyper_w_space;
ANALYZE tag;
ANALYZE hyper_ts;
ANALYZE hyper_timefunc;
-- create normal table for JOIN tests
CREATE TABLE regular_timestamptz(time timestamptz);
INSERT INTO regular_timestamptz SELECT generate_series('2000-01-01'::timestamptz,'2000-02-01'::timestamptz,'1d'::interval);
\ir include/plan_expand_hypertable_query.sql
-- This file and its contents are licensed under the Apache License 2.0.
-- Please see the included NOTICE for copyright information and
-- LICENSE-APACHE for a copy of the license.
--we want to see how our logic excludes chunks
--and not how much work constraint_exclusion does
SET constraint_exclusion = 'off';
\qecho test upper bounds
test upper bounds
:PREFIX SELECT * FROM hyper WHERE time < 10 ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_1_chunk.value
   ->  Seq Scan on _hyper_1_1_chunk

:PREFIX SELECT * FROM hyper WHERE time < 11 ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper.value
   ->  Append
         ->  Seq Scan on _hyper_1_1_chunk
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: ("time" < 11)

:PREFIX SELECT * FROM hyper WHERE time = 10 ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_2_chunk.value
   ->  Seq Scan on _hyper_1_2_chunk
         Filter: ("time" = 10)

:PREFIX SELECT * FROM hyper WHERE 10 >= time ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper.value
   ->  Append
         ->  Seq Scan on _hyper_1_1_chunk
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: (10 >= "time")

\qecho test lower bounds
test lower bounds
:PREFIX SELECT * FROM hyper WHERE time >= 10 and time < 20 ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_2_chunk.value
   ->  Seq Scan on _hyper_1_2_chunk

:PREFIX SELECT * FROM hyper WHERE 10 < time and 20 >= time ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper.value
   ->  Append
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: ((10 < "time") AND (20 >= "time"))
         ->  Seq Scan on _hyper_1_3_chunk
               Filter: ((10 < "time") AND (20 >= "time"))

:PREFIX SELECT * FROM hyper WHERE time >= 9 and time < 20 ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper.value
   ->  Append
         ->  Seq Scan on _hyper_1_1_chunk
               Filter: (("time" >= 9) AND ("time" < 20))
         ->  Seq Scan on _hyper_1_2_chunk

:PREFIX SELECT * FROM hyper WHERE time > 9 and time < 20 ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_2_chunk.value
   ->  Seq Scan on _hyper_1_2_chunk

\qecho test empty result
test empty result
:PREFIX SELECT * FROM hyper WHERE time < 0;
--- QUERY PLAN ---
 Result
   One-Time Filter: false

\qecho test expression evaluation
test expression evaluation
:PREFIX SELECT * FROM hyper WHERE time < (5*2)::smallint;
--- QUERY PLAN ---
 Seq Scan on _hyper_1_1_chunk

\qecho test logic at INT64_MAX
test logic at INT64_MAX
:PREFIX SELECT * FROM hyper WHERE time = 9223372036854775807::bigint ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_102_chunk.value
   ->  Seq Scan on _hyper_1_102_chunk
         Filter: ("time" = '9223372036854775807'::bigint)

:PREFIX SELECT * FROM hyper WHERE time = 9223372036854775806::bigint ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_102_chunk.value
   ->  Seq Scan on _hyper_1_102_chunk
         Filter: ("time" = '9223372036854775806'::bigint)

:PREFIX SELECT * FROM hyper WHERE time >= 9223372036854775807::bigint ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_102_chunk.value
   ->  Seq Scan on _hyper_1_102_chunk
         Filter: ("time" >= '9223372036854775807'::bigint)

:PREFIX SELECT * FROM hyper WHERE time > 9223372036854775807::bigint ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: value
   ->  Result
         One-Time Filter: false

:PREFIX SELECT * FROM hyper WHERE time > 9223372036854775806::bigint ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_102_chunk.value
   ->  Seq Scan on _hyper_1_102_chunk
         Filter: ("time" > '9223372036854775806'::bigint)

\qecho cte
cte
:PREFIX WITH cte AS(
  SELECT * FROM hyper WHERE time < 10
)
SELECT * FROM cte ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_1_chunk.value
   ->  Seq Scan on _hyper_1_1_chunk

\qecho subquery
subquery
:PREFIX SELECT 0 = ANY (SELECT value FROM hyper WHERE time < 10);
--- QUERY PLAN ---
 Result
   SubPlan 1
     ->  Seq Scan on _hyper_1_1_chunk

\qecho no space constraint
no space constraint
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_103_chunk
               Filter: ("time" < 10)
         ->  Seq Scan on _hyper_2_104_chunk
               Filter: ("time" < 10)
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: ("time" < 10)
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: ("time" < 10)

\qecho valid space constraint
valid space constraint
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 and device_id = 'dev5' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_2_106_chunk.value
   ->  Seq Scan on _hyper_2_106_chunk
         Filter: (("time" < 10) AND (device_id = 'dev5'::text))

:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 and 'dev5' = device_id ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_2_106_chunk.value
   ->  Seq Scan on _hyper_2_106_chunk
         Filter: (("time" < 10) AND ('dev5'::text = device_id))

:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 and 'dev'||(2+3) = device_id ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_2_106_chunk.value
   ->  Seq Scan on _hyper_2_106_chunk
         Filter: (("time" < 10) AND ('dev5'::text = device_id))

\qecho only space constraint
only space constraint
:PREFIX SELECT * FROM hyper_w_space WHERE 'dev5' = device_id ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: ('dev5'::text = device_id)
         ->  Seq Scan on _hyper_2_109_chunk
               Filter: ('dev5'::text = device_id)
         ->  Seq Scan on _hyper_2_111_chunk
               Filter: ('dev5'::text = device_id)

\qecho unhandled space constraint
unhandled space constraint
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 and device_id > 'dev5' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_103_chunk
               Filter: (("time" < 10) AND (device_id > 'dev5'::text))
         ->  Seq Scan on _hyper_2_104_chunk
               Filter: (("time" < 10) AND (device_id > 'dev5'::text))
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: (("time" < 10) AND (device_id > 'dev5'::text))
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: (("time" < 10) AND (device_id > 'dev5'::text))

\qecho use of OR - does not filter chunks
use of OR - does not filter chunks
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 AND (device_id = 'dev5' or device_id = 'dev6') ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_103_chunk
               Filter: (("time" < 10) AND ((device_id = 'dev5'::text) OR (device_id = 'dev6'::text)))
         ->  Seq Scan on _hyper_2_104_chunk
               Filter: (("time" < 10) AND ((device_id = 'dev5'::text) OR (device_id = 'dev6'::text)))
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: (("time" < 10) AND ((device_id = 'dev5'::text) OR (device_id = 'dev6'::text)))
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: (("time" < 10) AND ((device_id = 'dev5'::text) OR (device_id = 'dev6'::text)))

\qecho cte
cte
:PREFIX WITH cte AS(
   SELECT * FROM hyper_w_space WHERE time < 10 and device_id = 'dev5'
)
SELECT * FROM cte ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_2_106_chunk.value
   ->  Seq Scan on _hyper_2_106_chunk
         Filter: (("time" < 10) AND (device_id = 'dev5'::text))

\qecho subquery
subquery
:PREFIX SELECT 0 = ANY (SELECT value FROM hyper_w_space WHERE time < 10 and device_id = 'dev5');
--- QUERY PLAN ---
 Result
   SubPlan 1
     ->  Seq Scan on _hyper_2_106_chunk
           Filter: (("time" < 10) AND (device_id = 'dev5'::text))

\qecho view
view
:PREFIX SELECT * FROM hyper_w_space_view WHERE time < 10 and device_id = 'dev5' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_2_106_chunk.value
   ->  Seq Scan on _hyper_2_106_chunk
         Filter: (("time" < 10) AND (device_id = 'dev5'::text))

\qecho IN statement - simple
IN statement - simple
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 AND device_id IN ('dev5') ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_2_106_chunk.value
   ->  Seq Scan on _hyper_2_106_chunk
         Filter: (("time" < 10) AND (device_id = 'dev5'::text))

\qecho IN statement - two chunks
IN statement - two chunks
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 AND device_id IN ('dev5','dev6') ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: (("time" < 10) AND (device_id = ANY ('{dev5,dev6}'::text[])))
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: (("time" < 10) AND (device_id = ANY ('{dev5,dev6}'::text[])))

\qecho IN statement - one chunk
IN statement - one chunk
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 AND device_id IN ('dev4','dev5') ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_2_106_chunk.value
   ->  Seq Scan on _hyper_2_106_chunk
         Filter: (("time" < 10) AND (device_id = ANY ('{dev4,dev5}'::text[])))

\qecho NOT IN - does not filter chunks
NOT IN - does not filter chunks
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 AND device_id NOT IN ('dev5','dev6') ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_103_chunk
               Filter: (("time" < 10) AND (device_id <> ALL ('{dev5,dev6}'::text[])))
         ->  Seq Scan on _hyper_2_104_chunk
               Filter: (("time" < 10) AND (device_id <> ALL ('{dev5,dev6}'::text[])))
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: (("time" < 10) AND (device_id <> ALL ('{dev5,dev6}'::text[])))
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: (("time" < 10) AND (device_id <> ALL ('{dev5,dev6}'::text[])))

\qecho IN statement with subquery - does not filter chunks
IN statement with subquery - does not filter chunks
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 AND device_id IN (SELECT 'dev5'::text) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_2_106_chunk.value
   ->  Seq Scan on _hyper_2_106_chunk
         Filter: (("time" < 10) AND (device_id = 'dev5'::text))

\qecho ANY
ANY
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 AND device_id = ANY(ARRAY['dev5','dev6']) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: (("time" < 10) AND (device_id = ANY ('{dev5,dev6}'::text[])))
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: (("time" < 10) AND (device_id = ANY ('{dev5,dev6}'::text[])))

\qecho ANY with intersection
ANY with intersection
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 AND device_id = ANY(ARRAY['dev5','dev6']) AND device_id = ANY(ARRAY['dev6','dev7']) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_2_105_chunk.value
   ->  Seq Scan on _hyper_2_105_chunk
         Filter: (("time" < 10) AND (device_id = ANY ('{dev5,dev6}'::text[])) AND (device_id = ANY ('{dev6,dev7}'::text[])))

\qecho ANY without intersection shouldnt scan any chunks
ANY without intersection shouldnt scan any chunks
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 AND device_id = ANY(ARRAY['dev5','dev6']) AND device_id = ANY(ARRAY['dev8','dev9']) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: value
   ->  Result
         One-Time Filter: false

\qecho ANY/IN/ALL only works for equals operator
ANY/IN/ALL only works for equals operator
:PREFIX SELECT * FROM hyper_w_space WHERE device_id < ANY(ARRAY['dev5','dev6']) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_103_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_104_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_107_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_108_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_109_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_110_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_111_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_112_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_113_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_114_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))
         ->  Seq Scan on _hyper_2_115_chunk
               Filter: (device_id < ANY ('{dev5,dev6}'::text[]))

\qecho ALL with equals and different values shouldnt scan any chunks
ALL with equals and different values shouldnt scan any chunks
:PREFIX SELECT * FROM hyper_w_space WHERE device_id = ALL(ARRAY['dev5','dev6']) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: value
   ->  Result
         One-Time Filter: false

\qecho Multi AND
Multi AND
:PREFIX SELECT * FROM hyper_w_space WHERE time < 10 AND time < 100 ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_103_chunk
               Filter: (("time" < 10) AND ("time" < 100))
         ->  Seq Scan on _hyper_2_104_chunk
               Filter: (("time" < 10) AND ("time" < 100))
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: (("time" < 10) AND ("time" < 100))
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: (("time" < 10) AND ("time" < 100))

\qecho Time dimension doesnt filter chunks when using IN/ANY with multiple arguments
Time dimension doesnt filter chunks when using IN/ANY with multiple arguments
:PREFIX SELECT * FROM hyper_w_space WHERE time < ANY(ARRAY[1,2]) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_103_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_104_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_107_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_108_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_109_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_110_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_111_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_112_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_113_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_114_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))
         ->  Seq Scan on _hyper_2_115_chunk
               Filter: ("time" < ANY ('{1,2}'::integer[]))

\qecho Time dimension chunk filtering works for ANY with single argument
Time dimension chunk filtering works for ANY with single argument
:PREFIX SELECT * FROM hyper_w_space WHERE time < ANY(ARRAY[1]) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_103_chunk
               Filter: ("time" < ANY ('{1}'::integer[]))
         ->  Seq Scan on _hyper_2_104_chunk
               Filter: ("time" < ANY ('{1}'::integer[]))
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: ("time" < ANY ('{1}'::integer[]))
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: ("time" < ANY ('{1}'::integer[]))

\qecho Time dimension chunk filtering works for ALL with single argument
Time dimension chunk filtering works for ALL with single argument
:PREFIX SELECT * FROM hyper_w_space WHERE time < ALL(ARRAY[1]) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_103_chunk
               Filter: ("time" < ALL ('{1}'::integer[]))
         ->  Seq Scan on _hyper_2_104_chunk
               Filter: ("time" < ALL ('{1}'::integer[]))
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: ("time" < ALL ('{1}'::integer[]))
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: ("time" < ALL ('{1}'::integer[]))

\qecho Time dimension chunk filtering works for ALL with multiple arguments
Time dimension chunk filtering works for ALL with multiple arguments
:PREFIX SELECT * FROM hyper_w_space WHERE time < ALL(ARRAY[1,10,20,30]) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_103_chunk
               Filter: ("time" < ALL ('{1,10,20,30}'::integer[]))
         ->  Seq Scan on _hyper_2_104_chunk
               Filter: ("time" < ALL ('{1,10,20,30}'::integer[]))
         ->  Seq Scan on _hyper_2_105_chunk
               Filter: ("time" < ALL ('{1,10,20,30}'::integer[]))
         ->  Seq Scan on _hyper_2_106_chunk
               Filter: ("time" < ALL ('{1,10,20,30}'::integer[]))

\qecho AND intersection using IN and EQUALS
AND intersection using IN and EQUALS
:PREFIX SELECT * FROM hyper_w_space WHERE device_id IN ('dev1','dev2') AND device_id = 'dev1' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_w_space.value
   ->  Append
         ->  Seq Scan on _hyper_2_103_chunk
               Filter: ((device_id = ANY ('{dev1,dev2}'::text[])) AND (device_id = 'dev1'::text))
         ->  Seq Scan on _hyper_2_110_chunk
               Filter: ((device_id = ANY ('{dev1,dev2}'::text[])) AND (device_id = 'dev1'::text))
         ->  Seq Scan on _hyper_2_114_chunk
               Filter: ((device_id = ANY ('{dev1,dev2}'::text[])) AND (device_id = 'dev1'::text))

\qecho AND with no intersection using IN and EQUALS
AND with no intersection using IN and EQUALS
:PREFIX SELECT * FROM hyper_w_space WHERE device_id IN ('dev1','dev2') AND device_id = 'dev3' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: value
   ->  Result
         One-Time Filter: false

\qecho timestamps
timestamps
\qecho these should work since they are immutable functions
these should work since they are immutable functions
:PREFIX SELECT * FROM hyper_ts WHERE time < 'Wed Dec 31 16:00:10 1969 PST'::timestamptz ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_ts.value
   ->  Append
         ->  Seq Scan on _hyper_3_116_chunk
               Filter: ("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_3_117_chunk
               Filter: ("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone)

:PREFIX SELECT * FROM hyper_ts WHERE time < to_timestamp(10) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_ts.value
   ->  Append
         ->  Seq Scan on _hyper_3_116_chunk
               Filter: ("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_3_117_chunk
               Filter: ("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone)

:PREFIX SELECT * FROM hyper_ts WHERE time < 'Wed Dec 31 16:00:10 1969'::timestamp AT TIME ZONE 'PST' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_ts.value
   ->  Append
         ->  Seq Scan on _hyper_3_116_chunk
               Filter: ("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_3_117_chunk
               Filter: ("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone)

:PREFIX SELECT * FROM hyper_ts WHERE time < to_timestamp(10) and device_id = 'dev1' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_3_116_chunk.value
   ->  Seq Scan on _hyper_3_116_chunk
         Filter: (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text))

\qecho these should not work since uses stable functions;
these should not work since uses stable functions;
:PREFIX SELECT * FROM hyper_ts WHERE time < 'Wed Dec 31 16:00:10 1969'::timestamp ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_ts.value
   ->  Custom Scan (ChunkAppend) on hyper_ts
         Chunks excluded during startup: 6
         ->  Seq Scan on _hyper_3_116_chunk
               Filter: ("time" < 'Wed Dec 31 16:00:10 1969'::timestamp without time zone)
         ->  Seq Scan on _hyper_3_117_chunk
               Filter: ("time" < 'Wed Dec 31 16:00:10 1969'::timestamp without time zone)

:PREFIX SELECT * FROM hyper_ts WHERE time < ('Wed Dec 31 16:00:10 1969'::timestamp::timestamptz) ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_ts.value
   ->  Custom Scan (ChunkAppend) on hyper_ts
         Chunks excluded during startup: 6
         ->  Seq Scan on _hyper_3_116_chunk
               Filter: ("time" < ('Wed Dec 31 16:00:10 1969'::timestamp without time zone)::timestamp with time zone)
         ->  Seq Scan on _hyper_3_117_chunk
               Filter: ("time" < ('Wed Dec 31 16:00:10 1969'::timestamp without time zone)::timestamp with time zone)

:PREFIX SELECT * FROM hyper_ts WHERE NOW() < time ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_ts.value
   ->  Custom Scan (ChunkAppend) on hyper_ts
         Chunks excluded during startup: 7
         ->  Seq Scan on _hyper_3_123_chunk
               Filter: (now() < "time")

\qecho joins
joins
:PREFIX SELECT * FROM hyper_ts WHERE tag_id IN (SELECT id FROM tag WHERE tag.id=1) and time < to_timestamp(10) and device_id = 'dev1' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_3_116_chunk.value
   ->  Nested Loop Semi Join
         ->  Seq Scan on _hyper_3_116_chunk
               Filter: (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text) AND (tag_id = 1))
         ->  Seq Scan on tag
               Filter: (id = 1)

:PREFIX SELECT * FROM hyper_ts WHERE tag_id IN (SELECT id FROM tag WHERE tag.id=1) or (time < to_timestamp(10) and device_id = 'dev1') ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_ts.value
   ->  Custom Scan (ChunkAppend) on hyper_ts
         ->  Seq Scan on _hyper_3_116_chunk
               Filter: ((hashed SubPlan 1) OR (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text)))
               SubPlan 1
                 ->  Seq Scan on tag
                       Filter: (id = 1)
         ->  Seq Scan on _hyper_3_117_chunk
               Filter: ((hashed SubPlan 1) OR (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text)))
         ->  Seq Scan on _hyper_3_118_chunk
               Filter: ((hashed SubPlan 1) OR (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text)))
         ->  Seq Scan on _hyper_3_119_chunk
               Filter: ((hashed SubPlan 1) OR (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text)))
         ->  Seq Scan on _hyper_3_120_chunk
               Filter: ((hashed SubPlan 1) OR (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text)))
         ->  Seq Scan on _hyper_3_121_chunk
               Filter: ((hashed SubPlan 1) OR (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text)))
         ->  Seq Scan on _hyper_3_122_chunk
               Filter: ((hashed SubPlan 1) OR (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text)))
         ->  Seq Scan on _hyper_3_123_chunk
               Filter: ((hashed SubPlan 1) OR (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text)))

:PREFIX SELECT * FROM hyper_ts WHERE tag_id IN (SELECT id FROM tag WHERE tag.name='tag1') and time < to_timestamp(10) and device_id = 'dev1' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_3_116_chunk.value
   ->  Nested Loop
         Join Filter: (_hyper_3_116_chunk.tag_id = tag.id)
         ->  Seq Scan on _hyper_3_116_chunk
               Filter: (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text))
         ->  Seq Scan on tag
               Filter: (name = 'tag1'::text)

:PREFIX SELECT * FROM hyper_ts JOIN tag on (hyper_ts.tag_id = tag.id ) WHERE time < to_timestamp(10) and device_id = 'dev1' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_3_116_chunk.value
   ->  Merge Join
         Merge Cond: (tag.id = _hyper_3_116_chunk.tag_id)
         ->  Index Scan using tag_pkey on tag
         ->  Sort
               Sort Key: _hyper_3_116_chunk.tag_id
               ->  Seq Scan on _hyper_3_116_chunk
                     Filter: (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text))

:PREFIX SELECT * FROM hyper_ts JOIN tag on (hyper_ts.tag_id = tag.id ) WHERE tag.name = 'tag1' and time < to_timestamp(10) and device_id = 'dev1' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_3_116_chunk.value
   ->  Nested Loop
         Join Filter: (tag.id = _hyper_3_116_chunk.tag_id)
         ->  Seq Scan on _hyper_3_116_chunk
               Filter: (("time" < 'Wed Dec 31 16:00:10 1969 PST'::timestamp with time zone) AND (device_id = 'dev1'::text))
         ->  Seq Scan on tag
               Filter: (name = 'tag1'::text)

\qecho test constraint exclusion for constraints in ON clause of JOINs
test constraint exclusion for constraints in ON clause of JOINs
\qecho should exclude chunks on m1 and propagate qual to m2 because of INNER JOIN
should exclude chunks on m1 and propagate qual to m2 because of INNER JOIN
:PREFIX SELECT m1.time,m2.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time AND m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)

\qecho should exclude chunks on m2 and propagate qual to m1 because of INNER JOIN
should exclude chunks on m2 and propagate qual to m1 because of INNER JOIN
:PREFIX SELECT m1.time,m2.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time AND m2.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)

\qecho must not exclude on m1
must not exclude on m1
:PREFIX SELECT m1.time,m2.time FROM metrics_timestamptz m1 LEFT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time AND m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Left Join
   Merge Cond: (m1."time" = m2."time")
   Join Filter: (m1."time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
         ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m1_3
         ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m1_4
         ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m1_5
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
               ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
               ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
               ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
               ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6

\qecho should exclude chunks on m2
should exclude chunks on m2
:PREFIX SELECT m1.time,m2.time FROM metrics_timestamptz m1 LEFT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time AND m2.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Left Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
         ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m1_3
         ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m1_4
         ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m1_5
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)

\qecho should exclude chunks on m1
should exclude chunks on m1
:PREFIX SELECT m1.time,m2.time FROM metrics_timestamptz m1 RIGHT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time AND m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Sort
   Sort Key: m1."time"
   ->  Merge Right Join
         Merge Cond: (m1."time" = m2."time")
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
               Order: m1."time"
               ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
                     Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
         ->  Materialize
               ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
                     Order: m2."time"
                     ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
                     ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
                     ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
                     ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6

\qecho must not exclude chunks on m2
must not exclude chunks on m2
:PREFIX SELECT m1.time,m2.time FROM metrics_timestamptz m1 RIGHT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time AND m2.time < '2000-01-10' ORDER BY m1.time, m2.time;
--- QUERY PLAN ---
 Sort
   Sort Key: m1."time", m2."time"
   ->  Merge Left Join
         Merge Cond: (m2."time" = m1."time")
         Join Filter: (m2."time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
               ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
               ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
               ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
               ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6
         ->  Materialize
               ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
                     Order: m1."time"
                     ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
                     ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
                     ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m1_3
                     ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m1_4
                     ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m1_5

\qecho time_bucket exclusion
time_bucket exclusion
:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time) < 10::bigint ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_1_chunk."time"
   ->  Seq Scan on _hyper_1_1_chunk
         Filter: (time_bucket('10'::bigint, "time") < '10'::bigint)

:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time) < 11::bigint ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper."time"
   ->  Append
         ->  Seq Scan on _hyper_1_1_chunk
               Filter: (time_bucket('10'::bigint, "time") < '11'::bigint)
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: (time_bucket('10'::bigint, "time") < '11'::bigint)
         ->  Seq Scan on _hyper_1_3_chunk
               Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time") < '11'::bigint))

:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time) <= 10::bigint ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper."time"
   ->  Append
         ->  Seq Scan on _hyper_1_1_chunk
               Filter: (time_bucket('10'::bigint, "time") <= '10'::bigint)
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: (time_bucket('10'::bigint, "time") <= '10'::bigint)
         ->  Seq Scan on _hyper_1_3_chunk
               Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time") <= '10'::bigint))

:PREFIX SELECT * FROM hyper WHERE 10::bigint > time_bucket(10, time) ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_1_chunk."time"
   ->  Seq Scan on _hyper_1_1_chunk
         Filter: ('10'::bigint > time_bucket('10'::bigint, "time"))

:PREFIX SELECT * FROM hyper WHERE 11::bigint > time_bucket(10, time) ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper."time"
   ->  Append
         ->  Seq Scan on _hyper_1_1_chunk
               Filter: ('11'::bigint > time_bucket('10'::bigint, "time"))
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: ('11'::bigint > time_bucket('10'::bigint, "time"))
         ->  Seq Scan on _hyper_1_3_chunk
               Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time")))

:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 10::bigint ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper."time"
   ->  Append
         ->  Seq Scan on _hyper_1_1_chunk
               Filter: (time_bucket('10'::bigint, "time", '5'::bigint) < '10'::bigint)
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: (time_bucket('10'::bigint, "time", '5'::bigint) < '10'::bigint)

:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) < 11::bigint ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper."time"
   ->  Append
         ->  Seq Scan on _hyper_1_1_chunk
               Filter: (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint)
         ->  Seq Scan on _hyper_1_3_chunk
               Filter: (("time" < '21'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) < '11'::bigint))

:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time, 5) <= 10::bigint ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper."time"
   ->  Append
         ->  Seq Scan on _hyper_1_1_chunk
               Filter: (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint)
         ->  Seq Scan on _hyper_1_3_chunk
               Filter: (("time" <= '20'::bigint) AND (time_bucket('10'::bigint, "time", '5'::bigint) <= '10'::bigint))

:PREFIX SELECT * FROM hyper WHERE 10::bigint > time_bucket(10, time, 5) ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper."time"
   ->  Append
         ->  Seq Scan on _hyper_1_1_chunk
               Filter: ('10'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: ('10'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))

:PREFIX SELECT * FROM hyper WHERE 11::bigint > time_bucket(10, time, 5) ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper."time"
   ->  Append
         ->  Seq Scan on _hyper_1_1_chunk
               Filter: ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint))
         ->  Seq Scan on _hyper_1_3_chunk
               Filter: (("time" < '21'::bigint) AND ('11'::bigint > time_bucket('10'::bigint, "time", '5'::bigint)))

\qecho timestamp time_bucket exclusion
timestamp time_bucket exclusion
SELECT count(DISTINCT tableoid) FROM metrics_timestamp;
 count 
-------
     5

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time) >= '2000-01-15' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk
         Index Cond: ("time" >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Sat Jan 15 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) < '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) < 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) <= '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) <= 'Wed Jan 05 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) > '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) > 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('7d',time,'2000-01-10'::timestamp) >= '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000'::timestamp without time zone) >= 'Tue Jan 25 00:00:00 2000'::timestamp without time zone)

\qecho timestamptz time_bucket exclusion
timestamptz time_bucket exclusion
SELECT count(DISTINCT tableoid) FROM metrics_timestamptz;
 count 
-------
     5

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) < '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time") < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) <= '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time") <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) > '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time") > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time) >= '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time") >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) < '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) <= '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) > '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'3d'::interval) >= '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", '@ 3 days'::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) < '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) <= '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) > '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'2000-01-10'::timestamptz) >= '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') < '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Index Cond: ("time" < 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) < 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') <= '2000-01-05' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Index Cond: ("time" <= 'Wed Jan 12 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) <= 'Wed Jan 05 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') > '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Index Cond: ("time" > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) > 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT * FROM metrics_timestamptz WHERE time_bucket('7d',time,'Europe/Berlin') >= '2000-01-25' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Index Cond: ("time" >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 7 days'::interval, "time", 'Europe/Berlin'::text, NULL::timestamp with time zone, NULL::interval) >= 'Tue Jan 25 00:00:00 2000 PST'::timestamp with time zone)

\qecho test overflow behaviour of time_bucket exclusion
test overflow behaviour of time_bucket exclusion
:PREFIX SELECT * FROM hyper WHERE time > 950 AND time_bucket(10, time) < '9223372036854775807'::bigint ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper."time"
   ->  Append
         ->  Seq Scan on _hyper_1_96_chunk
               Filter: (("time" > 950) AND (time_bucket('10'::bigint, "time") < '9223372036854775807'::bigint))
         ->  Seq Scan on _hyper_1_97_chunk
               Filter: (time_bucket('10'::bigint, "time") < '9223372036854775807'::bigint)
         ->  Seq Scan on _hyper_1_98_chunk
               Filter: (time_bucket('10'::bigint, "time") < '9223372036854775807'::bigint)
         ->  Seq Scan on _hyper_1_99_chunk
               Filter: (time_bucket('10'::bigint, "time") < '9223372036854775807'::bigint)
         ->  Seq Scan on _hyper_1_100_chunk
               Filter: (time_bucket('10'::bigint, "time") < '9223372036854775807'::bigint)
         ->  Seq Scan on _hyper_1_101_chunk
               Filter: (time_bucket('10'::bigint, "time") < '9223372036854775807'::bigint)
         ->  Seq Scan on _hyper_1_102_chunk
               Filter: (("time" > 950) AND (time_bucket('10'::bigint, "time") < '9223372036854775807'::bigint))

\qecho test timestamp upper boundary
test timestamp upper boundary
\qecho there should be no transformation if we are out of the supported (TimescaleDB-specific) range
there should be no transformation if we are out of the supported (TimescaleDB-specific) range
:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('1d',time) < '294276-01-01'::timestamp ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket('@ 1 day'::interval, "time") < 'Sat Jan 01 00:00:00 294276'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Filter: (time_bucket('@ 1 day'::interval, "time") < 'Sat Jan 01 00:00:00 294276'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk
         Filter: (time_bucket('@ 1 day'::interval, "time") < 'Sat Jan 01 00:00:00 294276'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Filter: (time_bucket('@ 1 day'::interval, "time") < 'Sat Jan 01 00:00:00 294276'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket('@ 1 day'::interval, "time") < 'Sat Jan 01 00:00:00 294276'::timestamp without time zone)

\qecho transformation would be out of range
transformation would be out of range
:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('1000d',time) < '294276-01-01'::timestamp ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket('@ 1000 days'::interval, "time") < 'Sat Jan 01 00:00:00 294276'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Filter: (time_bucket('@ 1000 days'::interval, "time") < 'Sat Jan 01 00:00:00 294276'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk
         Filter: (time_bucket('@ 1000 days'::interval, "time") < 'Sat Jan 01 00:00:00 294276'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Filter: (time_bucket('@ 1000 days'::interval, "time") < 'Sat Jan 01 00:00:00 294276'::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket('@ 1000 days'::interval, "time") < 'Sat Jan 01 00:00:00 294276'::timestamp without time zone)

\qecho test timestamptz upper boundary
test timestamptz upper boundary
\qecho there should be no transformation if we are out of the supported (TimescaleDB-specific) range
there should be no transformation if we are out of the supported (TimescaleDB-specific) range
:PREFIX SELECT time FROM metrics_timestamptz WHERE time_bucket('1d',time) < '294276-01-01'::timestamptz ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 1 day'::interval, "time") < 'Sat Jan 01 00:00:00 294276 PST'::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Filter: (time_bucket('@ 1 day'::interval, "time") < 'Sat Jan 01 00:00:00 294276 PST'::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk
         Filter: (time_bucket('@ 1 day'::interval, "time") < 'Sat Jan 01 00:00:00 294276 PST'::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Filter: (time_bucket('@ 1 day'::interval, "time") < 'Sat Jan 01 00:00:00 294276 PST'::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 1 day'::interval, "time") < 'Sat Jan 01 00:00:00 294276 PST'::timestamp with time zone)

\qecho transformation would be out of range
transformation would be out of range
:PREFIX SELECT time FROM metrics_timestamptz WHERE time_bucket('1000d',time) < '294276-01-01'::timestamptz ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 1000 days'::interval, "time") < 'Sat Jan 01 00:00:00 294276 PST'::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Filter: (time_bucket('@ 1000 days'::interval, "time") < 'Sat Jan 01 00:00:00 294276 PST'::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk
         Filter: (time_bucket('@ 1000 days'::interval, "time") < 'Sat Jan 01 00:00:00 294276 PST'::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Filter: (time_bucket('@ 1000 days'::interval, "time") < 'Sat Jan 01 00:00:00 294276 PST'::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 1000 days'::interval, "time") < 'Sat Jan 01 00:00:00 294276 PST'::timestamp with time zone)

\qecho time_bucket exclusion with run-time constants
time_bucket exclusion with run-time constants
-- These queries have a stable time_bucket expression, because the text::interval conversion is stable.
PREPARE P1(text    , text) AS SELECT * FROM metrics_timestamptz WHERE time_bucket($1::interval, time) > $2::timestamptz ORDER BY time;
PREPARE P2(text    , text) AS SELECT * FROM metrics_timestamp   WHERE time_bucket($1::interval, time) > $2::timestamptz ORDER BY time;
PREPARE P3(text    , text) AS SELECT * FROM metrics_timestamptz WHERE time_bucket($1::interval, time) > $2::timestamp   ORDER BY time;
PREPARE P4(text    , text) AS SELECT * FROM metrics_timestamp   WHERE time_bucket($1::interval, time) > $2::timestamp   ORDER BY time;
-- These queries have an immutable time_bucket expression, because the parameter is passed as interval, and no conversion is involved.
PREPARE P5(interval, text) AS SELECT * FROM metrics_timestamptz WHERE time_bucket($1::interval, time) > $2::timestamptz ORDER BY time;
PREPARE P6(interval, text) AS SELECT * FROM metrics_timestamp   WHERE time_bucket($1::interval, time) > $2::timestamptz ORDER BY time;
PREPARE P7(interval, text) AS SELECT * FROM metrics_timestamptz WHERE time_bucket($1::interval, time) > $2::timestamp   ORDER BY time;
PREPARE P8(interval, text) AS SELECT * FROM metrics_timestamp   WHERE time_bucket($1::interval, time) > $2::timestamp   ORDER BY time;
SET plan_cache_mode TO 'force_custom_plan';
:PREFIX EXECUTE P1('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P2('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P3('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P4('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P5('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P6('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P7('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P8('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P1('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 0
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)

:PREFIX EXECUTE P2('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 0
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)

:PREFIX EXECUTE P3('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 0
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)

:PREFIX EXECUTE P4('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 0
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket(('60 mins'::cstring)::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)

:PREFIX EXECUTE P5('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 0
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)

:PREFIX EXECUTE P6('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 0
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp with time zone)

:PREFIX EXECUTE P7('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 0
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)

:PREFIX EXECUTE P8('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 0
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket('@ 1 hour'::interval, "time") > ('2000-01-01 UTC'::cstring)::timestamp without time zone)

SET plan_cache_mode TO 'force_generic_plan';
:PREFIX EXECUTE P1('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P2('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P3('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P4('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P5('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P6('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P7('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P8('60 mins', '2024-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 5

:PREFIX EXECUTE P1('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 0
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp with time zone)

:PREFIX EXECUTE P2('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 0
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp with time zone)

:PREFIX EXECUTE P3('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 0
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp without time zone)

:PREFIX EXECUTE P4('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 0
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket(($1)::interval, "time") > ($2)::timestamp without time zone)

:PREFIX EXECUTE P5('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 0
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp with time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp with time zone)

:PREFIX EXECUTE P6('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 0
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp with time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp with time zone)

:PREFIX EXECUTE P7('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   Chunks excluded during startup: 0
   ->  Index Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp without time zone)
   ->  Index Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp without time zone)

:PREFIX EXECUTE P8('60 mins', '2000-01-01 UTC');
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   Chunks excluded during startup: 0
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_157_chunk_metrics_timestamp_time_idx on _hyper_5_157_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_158_chunk_metrics_timestamp_time_idx on _hyper_5_158_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp without time zone)
   ->  Index Only Scan Backward using _hyper_5_159_chunk_metrics_timestamp_time_idx on _hyper_5_159_chunk
         Filter: (time_bucket($1, "time") > ($2)::timestamp without time zone)

RESET plan_cache_mode;
DEALLOCATE P1;
DEALLOCATE P2;
DEALLOCATE P3;
DEALLOCATE P4;
DEALLOCATE P5;
DEALLOCATE P6;
DEALLOCATE P7;
DEALLOCATE P8;
:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time) > 10 AND time_bucket(10, time) < 100 ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper."time"
   ->  Append
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: (("time" > '10'::bigint) AND ("time" < '100'::bigint) AND (time_bucket('10'::bigint, "time") > 10) AND (time_bucket('10'::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_3_chunk
               Filter: ((time_bucket('10'::bigint, "time") > 10) AND (time_bucket('10'::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_4_chunk
               Filter: ((time_bucket('10'::bigint, "time") > 10) AND (time_bucket('10'::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_5_chunk
               Filter: ((time_bucket('10'::bigint, "time") > 10) AND (time_bucket('10'::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_6_chunk
               Filter: ((time_bucket('10'::bigint, "time") > 10) AND (time_bucket('10'::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_7_chunk
               Filter: ((time_bucket('10'::bigint, "time") > 10) AND (time_bucket('10'::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_8_chunk
               Filter: ((time_bucket('10'::bigint, "time") > 10) AND (time_bucket('10'::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_9_chunk
               Filter: ((time_bucket('10'::bigint, "time") > 10) AND (time_bucket('10'::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_10_chunk
               Filter: ((time_bucket('10'::bigint, "time") > 10) AND (time_bucket('10'::bigint, "time") < 100))

:PREFIX SELECT * FROM hyper WHERE time_bucket(10, time) > 10 AND time_bucket(10, time) < 20 ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_2_chunk."time"
   ->  Seq Scan on _hyper_1_2_chunk
         Filter: (("time" > '10'::bigint) AND ("time" < '20'::bigint) AND (time_bucket('10'::bigint, "time") > 10) AND (time_bucket('10'::bigint, "time") < 20))

:PREFIX SELECT * FROM hyper WHERE time_bucket(1, time) > 11 AND time_bucket(1, time) < 19 ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_2_chunk."time"
   ->  Seq Scan on _hyper_1_2_chunk
         Filter: (("time" > '11'::bigint) AND ("time" < '19'::bigint) AND (time_bucket('1'::bigint, "time") > 11) AND (time_bucket('1'::bigint, "time") < 19))

:PREFIX SELECT * FROM hyper WHERE 10 < time_bucket(10, time) AND 20 > time_bucket(10,time) ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: _hyper_1_2_chunk."time"
   ->  Seq Scan on _hyper_1_2_chunk
         Filter: (("time" > '10'::bigint) AND ("time" < '20'::bigint) AND (10 < time_bucket('10'::bigint, "time")) AND (20 > time_bucket('10'::bigint, "time")))

\qecho time_bucket exclusion with date
time_bucket exclusion with date
:PREFIX SELECT * FROM metrics_date WHERE time_bucket('1d',time) < '2000-01-03' ORDER BY time;
--- QUERY PLAN ---
 Index Only Scan Backward using _hyper_8_171_chunk_metrics_date_time_idx on _hyper_8_171_chunk
   Index Cond: ("time" < '01-03-2000'::date)
   Filter: (time_bucket('@ 1 day'::interval, "time") < '01-03-2000'::date)

:PREFIX SELECT * FROM metrics_date WHERE time_bucket('1d',time) >= '2000-01-03' AND time_bucket('1d',time) <= '2000-01-10' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_date
   Order: metrics_date."time"
   ->  Index Only Scan Backward using _hyper_8_171_chunk_metrics_date_time_idx on _hyper_8_171_chunk
         Index Cond: (("time" >= '01-03-2000'::date) AND ("time" <= '01-11-2000'::date))
         Filter: ((time_bucket('@ 1 day'::interval, "time") >= '01-03-2000'::date) AND (time_bucket('@ 1 day'::interval, "time") <= '01-10-2000'::date))
   ->  Index Only Scan Backward using _hyper_8_172_chunk_metrics_date_time_idx on _hyper_8_172_chunk
         Index Cond: (("time" >= '01-03-2000'::date) AND ("time" <= '01-11-2000'::date))
         Filter: ((time_bucket('@ 1 day'::interval, "time") >= '01-03-2000'::date) AND (time_bucket('@ 1 day'::interval, "time") <= '01-10-2000'::date))

\qecho time_bucket exclusion with timestamp
time_bucket exclusion with timestamp
:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('1d',time) < '2000-01-03' ORDER BY time;
--- QUERY PLAN ---
 Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
   Index Cond: ("time" < 'Mon Jan 03 00:00:00 2000'::timestamp without time zone)
   Filter: (time_bucket('@ 1 day'::interval, "time") < 'Mon Jan 03 00:00:00 2000'::timestamp without time zone)

:PREFIX SELECT * FROM metrics_timestamp WHERE time_bucket('1d',time) >= '2000-01-03' AND time_bucket('1d',time) <= '2000-01-10' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamp
   Order: metrics_timestamp."time"
   ->  Index Only Scan Backward using _hyper_5_155_chunk_metrics_timestamp_time_idx on _hyper_5_155_chunk
         Index Cond: (("time" >= 'Mon Jan 03 00:00:00 2000'::timestamp without time zone) AND ("time" <= 'Tue Jan 11 00:00:00 2000'::timestamp without time zone))
         Filter: ((time_bucket('@ 1 day'::interval, "time") >= 'Mon Jan 03 00:00:00 2000'::timestamp without time zone) AND (time_bucket('@ 1 day'::interval, "time") <= 'Mon Jan 10 00:00:00 2000'::timestamp without time zone))
   ->  Index Only Scan Backward using _hyper_5_156_chunk_metrics_timestamp_time_idx on _hyper_5_156_chunk
         Index Cond: (("time" >= 'Mon Jan 03 00:00:00 2000'::timestamp without time zone) AND ("time" <= 'Tue Jan 11 00:00:00 2000'::timestamp without time zone))
         Filter: ((time_bucket('@ 1 day'::interval, "time") >= 'Mon Jan 03 00:00:00 2000'::timestamp without time zone) AND (time_bucket('@ 1 day'::interval, "time") <= 'Mon Jan 10 00:00:00 2000'::timestamp without time zone))

\qecho time_bucket exclusion with timestamptz
time_bucket exclusion with timestamptz
:PREFIX SELECT time FROM metrics_timestamptz WHERE time_bucket('6h',time) < '2000-01-03' ORDER BY time;
--- QUERY PLAN ---
 Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
   Index Cond: ("time" < 'Mon Jan 03 06:00:00 2000 PST'::timestamp with time zone)
   Filter: (time_bucket('@ 6 hours'::interval, "time") < 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT time FROM metrics_timestamptz WHERE time_bucket('6h',time) >= '2000-01-03' AND time_bucket('6h',time) <= '2000-01-10' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Index Cond: (("time" >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND ("time" <= 'Mon Jan 10 06:00:00 2000 PST'::timestamp with time zone))
         Filter: ((time_bucket('@ 6 hours'::interval, "time") >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND (time_bucket('@ 6 hours'::interval, "time") <= 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Index Cond: (("time" >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND ("time" <= 'Mon Jan 10 06:00:00 2000 PST'::timestamp with time zone))
         Filter: ((time_bucket('@ 6 hours'::interval, "time") >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND (time_bucket('@ 6 hours'::interval, "time") <= 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))

\qecho time_bucket exclusion with timestamptz and day interval
time_bucket exclusion with timestamptz and day interval
:PREFIX SELECT time FROM metrics_timestamptz WHERE time_bucket('1d',time) < '2000-01-03' ORDER BY time;
--- QUERY PLAN ---
 Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
   Index Cond: ("time" < 'Tue Jan 04 00:00:00 2000 PST'::timestamp with time zone)
   Filter: (time_bucket('@ 1 day'::interval, "time") < 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT time FROM metrics_timestamptz WHERE time_bucket('1d',time) >= '2000-01-03' AND time_bucket('1d',time) <= '2000-01-10' ORDER BY time;
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_timestamptz
   Order: metrics_timestamptz."time"
   ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
         Index Cond: (("time" >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND ("time" <= 'Tue Jan 11 00:00:00 2000 PST'::timestamp with time zone))
         Filter: ((time_bucket('@ 1 day'::interval, "time") >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND (time_bucket('@ 1 day'::interval, "time") <= 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk
         Index Cond: (("time" >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND ("time" <= 'Tue Jan 11 00:00:00 2000 PST'::timestamp with time zone))
         Filter: ((time_bucket('@ 1 day'::interval, "time") >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND (time_bucket('@ 1 day'::interval, "time") <= 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))

:PREFIX SELECT time FROM metrics_timestamptz WHERE time_bucket('1d',time) >= '2000-01-03' AND time_bucket('7d',time) <= '2000-01-10' ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: metrics_timestamptz."time"
   ->  Append
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk
               Index Cond: (("time" >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND ("time" <= 'Mon Jan 17 00:00:00 2000 PST'::timestamp with time zone))
               Filter: ((time_bucket('@ 1 day'::interval, "time") >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND (time_bucket('@ 7 days'::interval, "time") <= 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Seq Scan on _hyper_6_161_chunk
               Filter: ((time_bucket('@ 1 day'::interval, "time") >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND (time_bucket('@ 7 days'::interval, "time") <= 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk
               Index Cond: (("time" >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND ("time" <= 'Mon Jan 17 00:00:00 2000 PST'::timestamp with time zone))
               Filter: ((time_bucket('@ 1 day'::interval, "time") >= 'Mon Jan 03 00:00:00 2000 PST'::timestamp with time zone) AND (time_bucket('@ 7 days'::interval, "time") <= 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))

\qecho no transformation
no transformation
:PREFIX SELECT * FROM hyper WHERE time_bucket(10 + floor(random())::int, time) > 10 AND time_bucket(10 + floor(random())::int, time) < 100 AND time < 150 ORDER BY time;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper."time"
   ->  Custom Scan (ChunkAppend) on hyper
         Chunks excluded during startup: 0
         ->  Seq Scan on _hyper_1_1_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_2_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_3_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_4_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_5_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_6_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_7_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_8_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_9_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_10_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_11_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_12_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_13_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_14_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))
         ->  Seq Scan on _hyper_1_15_chunk
               Filter: ((time_bucket(((10 + (floor(random()))::integer))::bigint, "time") > 10) AND (time_bucket(((10 + (floor(random()))::integer))::bigint, "time") < 100))

\qecho exclude chunks based on time column with partitioning function. This
exclude chunks based on time column with partitioning function. This
\qecho transparently applies the time partitioning function on the time
transparently applies the time partitioning function on the time
\qecho value to be able to exclude chunks (similar to a closed dimension).
value to be able to exclude chunks (similar to a closed dimension).
:PREFIX SELECT * FROM hyper_timefunc WHERE time < 4 ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_timefunc.value
   ->  Append
         ->  Seq Scan on _hyper_4_124_chunk
               Filter: ("time" < '4'::double precision)
         ->  Seq Scan on _hyper_4_125_chunk
               Filter: ("time" < '4'::double precision)
         ->  Seq Scan on _hyper_4_126_chunk
               Filter: ("time" < '4'::double precision)
         ->  Seq Scan on _hyper_4_127_chunk
               Filter: ("time" < '4'::double precision)

\qecho excluding based on time expression is currently unoptimized
excluding based on time expression is currently unoptimized
:PREFIX SELECT * FROM hyper_timefunc WHERE unix_to_timestamp(time) < 'Wed Dec 31 16:00:04 1969 PST' ORDER BY value;
--- QUERY PLAN ---
 Sort
   Sort Key: hyper_timefunc.value
   ->  Append
         ->  Seq Scan on _hyper_4_124_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_125_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_126_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_127_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_128_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_129_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_130_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_131_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_132_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_133_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_134_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_135_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_136_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_137_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_138_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_139_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_140_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_141_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_142_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_143_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_144_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_145_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_146_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_147_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_148_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_149_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_150_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_151_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_152_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_153_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)
         ->  Seq Scan on _hyper_4_154_chunk
               Filter: (to_timestamp("time") < 'Wed Dec 31 16:00:04 1969 PST'::timestamp with time zone)

\qecho test qual propagation for joins
test qual propagation for joins
RESET constraint_exclusion;
\qecho nothing to propagate
nothing to propagate
:PREFIX SELECT m1.time FROM metrics_timestamptz m1, metrics_timestamptz_2 m2 WHERE m1.time = m2.time ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
         ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m1_3
         ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m1_4
         ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m1_5
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
               ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
               ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
               ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
               ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
         ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m1_3
         ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m1_4
         ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m1_5
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
               ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
               ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
               ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
               ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 LEFT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Left Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
         ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m1_3
         ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m1_4
         ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m1_5
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
               ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
               ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
               ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
               ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 RIGHT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time ORDER BY m1.time;
--- QUERY PLAN ---
 Sort
   Sort Key: m1."time"
   ->  Merge Right Join
         Merge Cond: (m1."time" = m2."time")
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
               Order: m1."time"
               ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m1_3
               ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m1_4
               ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m1_5
         ->  Materialize
               ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
                     Order: m2."time"
                     ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
                     ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
                     ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
                     ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6

\qecho OR constraints should not propagate
OR constraints should not propagate
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time < '2000-01-10' OR m1.time > '2001-01-01' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Filter: (("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) OR ("time" > 'Mon Jan 01 00:00:00 2001 PST'::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Filter: (("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) OR ("time" > 'Mon Jan 01 00:00:00 2001 PST'::timestamp with time zone))
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
               ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
               ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
               ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
               ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6

\qecho test single constraint
test single constraint
\qecho constraint should be on both scans
constraint should be on both scans
\qecho these will propagate even for LEFT/RIGHT JOIN because the constraints are not in the ON clause and therefore imply a NOT NULL condition on the JOIN column
these will propagate even for LEFT/RIGHT JOIN because the constraints are not in the ON clause and therefore imply a NOT NULL condition on the JOIN column
:PREFIX SELECT m1.time FROM metrics_timestamptz m1, metrics_timestamptz_2 m2 WHERE m1.time = m2.time AND m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 LEFT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Left Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
               ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
               ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
               ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
               ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 RIGHT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)

\qecho test 2 constraints on single relation
test 2 constraints on single relation
\qecho these will propagate even for LEFT/RIGHT JOIN because the constraints are not in the ON clause and therefore imply a NOT NULL condition on the JOIN column
these will propagate even for LEFT/RIGHT JOIN because the constraints are not in the ON clause and therefore imply a NOT NULL condition on the JOIN column
:PREFIX SELECT m1.time FROM metrics_timestamptz m1, metrics_timestamptz_2 m2 WHERE m1.time = m2.time AND m1.time > '2000-01-01' AND m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time > '2000-01-01' AND m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 LEFT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time > '2000-01-01' AND m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Nested Loop Left Join
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Append
         ->  Index Only Scan using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               Index Cond: ("time" = m1."time")
         ->  Index Only Scan using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
               Index Cond: ("time" = m1."time")
         ->  Index Only Scan using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
               Index Cond: ("time" = m1."time")
         ->  Index Only Scan using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
               Index Cond: ("time" = m1."time")
         ->  Index Only Scan using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
               Index Cond: ("time" = m1."time")
         ->  Index Only Scan using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6
               Index Cond: ("time" = m1."time")

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 RIGHT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time > '2000-01-01' AND m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))

\qecho test 2 constraints with 1 constraint on each relation
test 2 constraints with 1 constraint on each relation
\qecho these will propagate even for LEFT/RIGHT JOIN because the constraints are not in the ON clause and therefore imply a NOT NULL condition on the JOIN column
these will propagate even for LEFT/RIGHT JOIN because the constraints are not in the ON clause and therefore imply a NOT NULL condition on the JOIN column
:PREFIX SELECT m1.time FROM metrics_timestamptz m1, metrics_timestamptz_2 m2 WHERE m1.time = m2.time AND m1.time > '2000-01-01' AND m2.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: (("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) AND ("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone))
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: (("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) AND ("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone))

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time > '2000-01-01' AND m2.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: (("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) AND ("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone))
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: (("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) AND ("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone))

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 LEFT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time > '2000-01-01' AND m2.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: (("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) AND ("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone))
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: (("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) AND ("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone))

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 RIGHT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time > '2000-01-01' AND m2.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: (("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) AND ("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone))
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: (("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone) AND ("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone))

\qecho test constraints in ON clause of INNER JOIN
test constraints in ON clause of INNER JOIN
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time AND m2.time > '2000-01-01' AND m2.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))

\qecho test constraints in ON clause of LEFT JOIN
test constraints in ON clause of LEFT JOIN
\qecho must not propagate
must not propagate
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 LEFT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time AND m2.time > '2000-01-01' AND m2.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Left Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
         ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m1_3
         ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m1_4
         ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m1_5
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))

\qecho test constraints in ON clause of RIGHT JOIN
test constraints in ON clause of RIGHT JOIN
\qecho must not propagate
must not propagate
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 RIGHT JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time AND m2.time > '2000-01-01' AND m2.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Gather Merge
   Workers Planned: 2
   ->  Sort
         Sort Key: m1."time"
         ->  Parallel Hash Left Join
               Hash Cond: (m2."time" = m1."time")
               Join Filter: ((m2."time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND (m2."time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
               ->  Parallel Append
                     ->  Parallel Seq Scan on _hyper_7_165_chunk m2_1
                     ->  Parallel Seq Scan on _hyper_7_166_chunk m2_2
                     ->  Parallel Seq Scan on _hyper_7_167_chunk m2_3
                     ->  Parallel Seq Scan on _hyper_7_168_chunk m2_4
                     ->  Parallel Seq Scan on _hyper_7_169_chunk m2_5
                     ->  Parallel Seq Scan on _hyper_7_170_chunk m2_6
               ->  Parallel Hash
                     ->  Parallel Append
                           ->  Parallel Seq Scan on _hyper_6_160_chunk m1_1
                           ->  Parallel Seq Scan on _hyper_6_161_chunk m1_2
                           ->  Parallel Seq Scan on _hyper_6_162_chunk m1_3
                           ->  Parallel Seq Scan on _hyper_6_163_chunk m1_4
                           ->  Parallel Seq Scan on _hyper_6_164_chunk m1_5

\qecho test equality condition not in ON clause
test equality condition not in ON clause
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON true WHERE m2.time = m1.time AND m2.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)

\qecho test constraints not joined on
test constraints not joined on
\qecho device_id constraint must not propagate
device_id constraint must not propagate
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON true WHERE m2.time = m1.time AND m2.time < '2000-01-10' AND m1.device_id = 1 ORDER BY m1.time;
--- QUERY PLAN ---
 Sort
   Sort Key: m1."time"
   ->  Nested Loop
         ->  Append
               ->  Seq Scan on _hyper_6_160_chunk m1_1
                     Filter: (device_id = 1)
               ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
                     Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
                     Filter: (device_id = 1)
         ->  Append
               ->  Index Only Scan using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: ("time" = m1."time")
               ->  Index Only Scan using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: (("time" = m1."time") AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))

\qecho test multiple join conditions
test multiple join conditions
\qecho device_id constraint should propagate
device_id constraint should propagate
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON true WHERE m2.time = m1.time AND m1.device_id = m2.device_id AND m2.time < '2000-01-10' AND m1.device_id = 1 ORDER BY m1.time;
--- QUERY PLAN ---
 Sort
   Sort Key: m1."time"
   ->  Nested Loop
         ->  Append
               ->  Seq Scan on _hyper_6_160_chunk m1_1
                     Filter: (device_id = 1)
               ->  Index Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
                     Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
                     Filter: (device_id = 1)
         ->  Append
               ->  Index Scan using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: ("time" = m1."time")
                     Filter: (device_id = 1)
               ->  Index Scan using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: (("time" = m1."time") AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
                     Filter: (device_id = 1)

\qecho test join with 3 tables
test join with 3 tables
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time INNER JOIN metrics_timestamptz m3 ON m2.time=m3.time WHERE m1.time > '2000-01-01' AND m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Nested Loop
   ->  Merge Join
         Merge Cond: (m1."time" = m2."time")
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
               Order: m1."time"
               ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
               ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
                     Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
         ->  Materialize
               ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
                     Order: m2."time"
                     ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                           Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
                     ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                           Index Cond: (("time" > 'Sat Jan 01 00:00:00 2000 PST'::timestamp with time zone) AND ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone))
   ->  Append
         ->  Index Only Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m3_1
               Index Cond: ("time" = m1."time")
         ->  Index Only Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m3_2
               Index Cond: ("time" = m1."time")
         ->  Index Only Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m3_3
               Index Cond: ("time" = m1."time")
         ->  Index Only Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m3_4
               Index Cond: ("time" = m1."time")
         ->  Index Only Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m3_5
               Index Cond: ("time" = m1."time")

\qecho test non-Const constraints
test non-Const constraints
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time < '2000-01-10'::text::timestamptz ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         Chunks excluded during startup: 3
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               Chunks excluded during startup: 4
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: ("time" < ('2000-01-10'::cstring)::timestamp with time zone)

\qecho test now()
test now()
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time < now() ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         Chunks excluded during startup: 0
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Index Cond: ("time" < now())
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: ("time" < now())
         ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m1_3
               Index Cond: ("time" < now())
         ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m1_4
               Index Cond: ("time" < now())
         ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m1_5
               Index Cond: ("time" < now())
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               Chunks excluded during startup: 0
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
                     Index Cond: ("time" < now())
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
                     Index Cond: ("time" < now())
               ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
                     Index Cond: ("time" < now())
               ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
                     Index Cond: ("time" < now())
               ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
                     Index Cond: ("time" < now())
               ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6
                     Index Cond: ("time" < now())

\qecho test volatile function
test volatile function
\qecho should not propagate
should not propagate
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m1.time < clock_timestamp() ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         Chunks excluded during startup: 0
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               Filter: ("time" < clock_timestamp())
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Filter: ("time" < clock_timestamp())
         ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m1_3
               Filter: ("time" < clock_timestamp())
         ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m1_4
               Filter: ("time" < clock_timestamp())
         ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m1_5
               Filter: ("time" < clock_timestamp())
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
               Order: m2."time"
               ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
               ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
               ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
               ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
               ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6

:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN metrics_timestamptz_2 m2 ON m1.time = m2.time WHERE m2.time < clock_timestamp() ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m2."time" = m1."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz_2 m2
         Order: m2."time"
         Chunks excluded during startup: 0
         ->  Index Only Scan Backward using _hyper_7_165_chunk_metrics_timestamptz_2_time_idx on _hyper_7_165_chunk m2_1
               Filter: ("time" < clock_timestamp())
         ->  Index Only Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk m2_2
               Filter: ("time" < clock_timestamp())
         ->  Index Only Scan Backward using _hyper_7_167_chunk_metrics_timestamptz_2_time_idx on _hyper_7_167_chunk m2_3
               Filter: ("time" < clock_timestamp())
         ->  Index Only Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk m2_4
               Filter: ("time" < clock_timestamp())
         ->  Index Only Scan Backward using _hyper_7_169_chunk_metrics_timestamptz_2_time_idx on _hyper_7_169_chunk m2_5
               Filter: ("time" < clock_timestamp())
         ->  Index Only Scan Backward using _hyper_7_170_chunk_metrics_timestamptz_2_time_idx on _hyper_7_170_chunk m2_6
               Filter: ("time" < clock_timestamp())
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
               Order: m1."time"
               ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               ->  Index Only Scan Backward using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk m1_3
               ->  Index Only Scan Backward using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk m1_4
               ->  Index Only Scan Backward using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk m1_5

\qecho test JOINs with normal table
test JOINs with normal table
\qecho will not propagate because constraints are only added to hypertables
will not propagate because constraints are only added to hypertables
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN regular_timestamptz m2 ON m1.time = m2.time WHERE m1.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m1."time" = m2."time")
   ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
         Order: m1."time"
         ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
         ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
               Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
   ->  Sort
         Sort Key: m2."time"
         ->  Seq Scan on regular_timestamptz m2

\qecho test JOINs with normal table
test JOINs with normal table
:PREFIX SELECT m1.time FROM metrics_timestamptz m1 INNER JOIN regular_timestamptz m2 ON m1.time = m2.time WHERE m2.time < '2000-01-10' ORDER BY m1.time;
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (m2."time" = m1."time")
   ->  Sort
         Sort Key: m2."time"
         ->  Seq Scan on regular_timestamptz m2
               Filter: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
   ->  Materialize
         ->  Custom Scan (ChunkAppend) on metrics_timestamptz m1
               Order: m1."time"
               ->  Index Only Scan Backward using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk m1_1
               ->  Index Only Scan Backward using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk m1_2
                     Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)

\qecho test quals are not pushed into OUTER JOIN
test quals are not pushed into OUTER JOIN
CREATE TABLE outer_join_1 (id int, name text,time timestamptz NOT NULL DEFAULT '2000-01-01');
CREATE TABLE outer_join_2 (id int, name text,time timestamptz NOT NULL DEFAULT '2000-01-01');
SELECT (SELECT table_name FROM create_hypertable(tbl, 'time')) FROM (VALUES ('outer_join_1'),('outer_join_2')) v(tbl);
  table_name  
--------------
 outer_join_1
 outer_join_2

INSERT INTO outer_join_1 VALUES(1,'a'), (2,'b');
INSERT INTO outer_join_2 VALUES(1,'a');
:PREFIX SELECT one.id, two.name FROM outer_join_1 one LEFT OUTER JOIN outer_join_2 two ON one.id=two.id WHERE one.id=2;
--- QUERY PLAN ---
 Nested Loop Left Join
   ->  Seq Scan on _hyper_9_176_chunk one
         Filter: (id = 2)
   ->  Materialize
         ->  Seq Scan on _hyper_10_177_chunk two
               Filter: (id = 2)

:PREFIX SELECT one.id, two.name FROM outer_join_2 two RIGHT OUTER JOIN outer_join_1 one ON one.id=two.id WHERE one.id=2;
--- QUERY PLAN ---
 Nested Loop Left Join
   ->  Seq Scan on _hyper_9_176_chunk one
         Filter: (id = 2)
   ->  Materialize
         ->  Seq Scan on _hyper_10_177_chunk two
               Filter: (id = 2)

DROP TABLE outer_join_1;
DROP TABLE outer_join_2;
-- test UNION between regular table and hypertable
SELECT time FROM regular_timestamptz UNION SELECT time FROM metrics_timestamptz ORDER BY 1;
             time             
------------------------------
 Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST
 Thu Jan 20 00:00:00 2000 PST
 Fri Jan 21 00:00:00 2000 PST
 Sat Jan 22 00:00:00 2000 PST
 Sun Jan 23 00:00:00 2000 PST
 Mon Jan 24 00:00:00 2000 PST
 Tue Jan 25 00:00:00 2000 PST
 Wed Jan 26 00:00:00 2000 PST
 Thu Jan 27 00:00:00 2000 PST
 Fri Jan 28 00:00:00 2000 PST
 Sat Jan 29 00:00:00 2000 PST
 Sun Jan 30 00:00:00 2000 PST
 Mon Jan 31 00:00:00 2000 PST
 Tue Feb 01 00:00:00 2000 PST

-- test UNION ALL between regular table and hypertable
SELECT time FROM regular_timestamptz UNION ALL SELECT time FROM metrics_timestamptz ORDER BY 1;
             time             
------------------------------
 Sat Jan 01 00:00:00 2000 PST
 Sat Jan 01 00:00:00 2000 PST
 Sat Jan 01 00:00:00 2000 PST
 Sat Jan 01 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST
 Sun Jan 02 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST
 Mon Jan 03 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST
 Tue Jan 04 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST
 Wed Jan 05 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST
 Thu Jan 06 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST
 Fri Jan 07 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST
 Sat Jan 08 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST
 Sun Jan 09 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST
 Mon Jan 10 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST
 Tue Jan 11 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST
 Wed Jan 12 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST
 Thu Jan 13 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST
 Fri Jan 14 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST
 Sat Jan 15 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST
 Sun Jan 16 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST
 Mon Jan 17 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST
 Tue Jan 18 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST
 Wed Jan 19 00:00:00 2000 PST
 Thu Jan 20 00:00:00 2000 PST
 Thu Jan 20 00:00:00 2000 PST
 Thu Jan 20 00:00:00 2000 PST
 Thu Jan 20 00:00:00 2000 PST
 Fri Jan 21 00:00:00 2000 PST
 Fri Jan 21 00:00:00 2000 PST
 Fri Jan 21 00:00:00 2000 PST
 Fri Jan 21 00:00:00 2000 PST
 Sat Jan 22 00:00:00 2000 PST
 Sat Jan 22 00:00:00 2000 PST
 Sat Jan 22 00:00:00 2000 PST
 Sat Jan 22 00:00:00 2000 PST
 Sun Jan 23 00:00:00 2000 PST
 Sun Jan 23 00:00:00 2000 PST
 Sun Jan 23 00:00:00 2000 PST
 Sun Jan 23 00:00:00 2000 PST
 Mon Jan 24 00:00:00 2000 PST
 Mon Jan 24 00:00:00 2000 PST
 Mon Jan 24 00:00:00 2000 PST
 Mon Jan 24 00:00:00 2000 PST
 Tue Jan 25 00:00:00 2000 PST
 Tue Jan 25 00:00:00 2000 PST
 Tue Jan 25 00:00:00 2000 PST
 Tue Jan 25 00:00:00 2000 PST
 Wed Jan 26 00:00:00 2000 PST
 Wed Jan 26 00:00:00 2000 PST
 Wed Jan 26 00:00:00 2000 PST
 Wed Jan 26 00:00:00 2000 PST
 Thu Jan 27 00:00:00 2000 PST
 Thu Jan 27 00:00:00 2000 PST
 Thu Jan 27 00:00:00 2000 PST
 Thu Jan 27 00:00:00 2000 PST
 Fri Jan 28 00:00:00 2000 PST
 Fri Jan 28 00:00:00 2000 PST
 Fri Jan 28 00:00:00 2000 PST
 Fri Jan 28 00:00:00 2000 PST
 Sat Jan 29 00:00:00 2000 PST
 Sat Jan 29 00:00:00 2000 PST
 Sat Jan 29 00:00:00 2000 PST
 Sat Jan 29 00:00:00 2000 PST
 Sun Jan 30 00:00:00 2000 PST
 Sun Jan 30 00:00:00 2000 PST
 Sun Jan 30 00:00:00 2000 PST
 Sun Jan 30 00:00:00 2000 PST
 Mon Jan 31 00:00:00 2000 PST
 Mon Jan 31 00:00:00 2000 PST
 Mon Jan 31 00:00:00 2000 PST
 Mon Jan 31 00:00:00 2000 PST
 Tue Feb 01 00:00:00 2000 PST
 Tue Feb 01 00:00:00 2000 PST
 Tue Feb 01 00:00:00 2000 PST
 Tue Feb 01 00:00:00 2000 PST

-- test nested join qual propagation
:PREFIX
SELECT * FROM (
SELECT o1_m1.time FROM metrics_timestamptz o1_m1 INNER JOIN metrics_timestamptz_2 o1_m2 ON true WHERE o1_m2.time = o1_m1.time AND o1_m1.device_id = o1_m2.device_id AND o1_m2.time < '2000-01-10' AND o1_m1.device_id = 1
) o1 FULL OUTER JOIN (
SELECT o2_m1.time FROM metrics_timestamptz o2_m1 FULL OUTER JOIN metrics_timestamptz_2 o2_m2 ON true WHERE o2_m2.time = o2_m1.time AND o2_m1.device_id = o2_m2.device_id AND o2_m2.time > '2000-01-20' AND o2_m1.device_id = 2
) o2 ON o1.time = o2.time ORDER BY 1,2;
--- QUERY PLAN ---
 Sort
   Sort Key: o1_m1."time", o2_m1."time"
   ->  Hash Full Join
         Hash Cond: (o2_m1."time" = o1_m1."time")
         ->  Nested Loop
               ->  Append
                     ->  Index Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1
                           Index Cond: ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone)
                           Filter: (device_id = 2)
                     ->  Seq Scan on _hyper_7_169_chunk o2_m2_2
                           Filter: (device_id = 2)
                     ->  Seq Scan on _hyper_7_170_chunk o2_m2_3
                           Filter: (device_id = 2)
               ->  Append
                     ->  Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o2_m1_1
                           Index Cond: ("time" = o2_m2."time")
                           Filter: (device_id = 2)
                     ->  Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o2_m1_2
                           Index Cond: ("time" = o2_m2."time")
                           Filter: (device_id = 2)
                     ->  Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o2_m1_3
                           Index Cond: ("time" = o2_m2."time")
                           Filter: (device_id = 2)
                     ->  Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o2_m1_4
                           Index Cond: ("time" = o2_m2."time")
                           Filter: (device_id = 2)
                     ->  Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o2_m1_5
                           Index Cond: ("time" = o2_m2."time")
                           Filter: (device_id = 2)
         ->  Hash
               ->  Nested Loop
                     ->  Append
                           ->  Seq Scan on _hyper_7_165_chunk o1_m2_1
                                 Filter: (device_id = 1)
                           ->  Index Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2
                                 Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
                                 Filter: (device_id = 1)
                     ->  Append
                           ->  Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o1_m1_1
                                 Index Cond: ("time" = o1_m2."time")
                                 Filter: (device_id = 1)
                           ->  Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o1_m1_2
                                 Index Cond: ("time" = o1_m2."time")
                                 Filter: (device_id = 1)
                           ->  Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o1_m1_3
                                 Index Cond: ("time" = o1_m2."time")
                                 Filter: (device_id = 1)
                           ->  Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o1_m1_4
                                 Index Cond: ("time" = o1_m2."time")
                                 Filter: (device_id = 1)
                           ->  Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o1_m1_5
                                 Index Cond: ("time" = o1_m2."time")
                                 Filter: (device_id = 1)

:PREFIX
SELECT * FROM (
SELECT o1_m1.time FROM metrics_timestamptz o1_m1 INNER JOIN metrics_timestamptz_2 o1_m2 ON o1_m2.time = o1_m1.time AND o1_m1.device_id = o1_m2.device_id WHERE o1_m2.time < '2000-01-10' AND o1_m1.device_id = 1
) o1 FULL OUTER JOIN (
SELECT o2_m1.time FROM metrics_timestamptz o2_m1 FULL OUTER JOIN metrics_timestamptz_2 o2_m2 ON o2_m2.time = o2_m1.time AND o2_m1.device_id = o2_m2.device_id WHERE o2_m2.time > '2000-01-20' AND o2_m1.device_id = 2
) o2 ON o1.time = o2.time ORDER BY 1,2;
--- QUERY PLAN ---
 Sort
   Sort Key: o1_m1."time", o2_m1."time"
   ->  Hash Full Join
         Hash Cond: (o2_m1."time" = o1_m1."time")
         ->  Nested Loop
               ->  Append
                     ->  Index Scan Backward using _hyper_7_168_chunk_metrics_timestamptz_2_time_idx on _hyper_7_168_chunk o2_m2_1
                           Index Cond: ("time" > 'Thu Jan 20 00:00:00 2000 PST'::timestamp with time zone)
                           Filter: (device_id = 2)
                     ->  Seq Scan on _hyper_7_169_chunk o2_m2_2
                           Filter: (device_id = 2)
                     ->  Seq Scan on _hyper_7_170_chunk o2_m2_3
                           Filter: (device_id = 2)
               ->  Append
                     ->  Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o2_m1_1
                           Index Cond: ("time" = o2_m2."time")
                           Filter: (device_id = 2)
                     ->  Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o2_m1_2
                           Index Cond: ("time" = o2_m2."time")
                           Filter: (device_id = 2)
                     ->  Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o2_m1_3
                           Index Cond: ("time" = o2_m2."time")
                           Filter: (device_id = 2)
                     ->  Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o2_m1_4
                           Index Cond: ("time" = o2_m2."time")
                           Filter: (device_id = 2)
                     ->  Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o2_m1_5
                           Index Cond: ("time" = o2_m2."time")
                           Filter: (device_id = 2)
         ->  Hash
               ->  Nested Loop
                     ->  Append
                           ->  Seq Scan on _hyper_7_165_chunk o1_m2_1
                                 Filter: (device_id = 1)
                           ->  Index Scan Backward using _hyper_7_166_chunk_metrics_timestamptz_2_time_idx on _hyper_7_166_chunk o1_m2_2
                                 Index Cond: ("time" < 'Mon Jan 10 00:00:00 2000 PST'::timestamp with time zone)
                                 Filter: (device_id = 1)
                     ->  Append
                           ->  Index Scan using _hyper_6_160_chunk_metrics_timestamptz_time_idx on _hyper_6_160_chunk o1_m1_1
                                 Index Cond: ("time" = o1_m2."time")
                                 Filter: (device_id = 1)
                           ->  Index Scan using _hyper_6_161_chunk_metrics_timestamptz_time_idx on _hyper_6_161_chunk o1_m1_2
                                 Index Cond: ("time" = o1_m2."time")
                                 Filter: (device_id = 1)
                           ->  Index Scan using _hyper_6_162_chunk_metrics_timestamptz_time_idx on _hyper_6_162_chunk o1_m1_3
                                 Index Cond: ("time" = o1_m2."time")
                                 Filter: (device_id = 1)
                           ->  Index Scan using _hyper_6_163_chunk_metrics_timestamptz_time_idx on _hyper_6_163_chunk o1_m1_4
                                 Index Cond: ("time" = o1_m2."time")
                                 Filter: (device_id = 1)
                           ->  Index Scan using _hyper_6_164_chunk_metrics_timestamptz_time_idx on _hyper_6_164_chunk o1_m1_5
                                 Index Cond: ("time" = o1_m2."time")
                                 Filter: (device_id = 1)

\set ECHO errors
RESET timescaledb.enable_optimizations;
CREATE TABLE t(time timestamptz NOT NULL);
SELECT table_name FROM create_hypertable('t','time');
 table_name 
------------
 t

INSERT INTO t VALUES ('2000-01-01'), ('2010-01-01'), ('2020-01-01');
EXPLAIN (buffers off, costs off) SELECT * FROM t t1 INNER JOIN t t2 ON t1.time = t2.time WHERE t1.time < timestamptz '2010-01-01';
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (t1."time" = t2."time")
   ->  Merge Append
         Sort Key: t1."time"
         ->  Index Only Scan Backward using _hyper_15_182_chunk_t_time_idx on _hyper_15_182_chunk t1_1
         ->  Index Only Scan Backward using _hyper_15_183_chunk_t_time_idx on _hyper_15_183_chunk t1_2
               Index Cond: ("time" < 'Fri Jan 01 00:00:00 2010 PST'::timestamp with time zone)
   ->  Materialize
         ->  Merge Append
               Sort Key: t2."time"
               ->  Index Only Scan Backward using _hyper_15_182_chunk_t_time_idx on _hyper_15_182_chunk t2_1
               ->  Index Only Scan Backward using _hyper_15_183_chunk_t_time_idx on _hyper_15_183_chunk t2_2
                     Index Cond: ("time" < 'Fri Jan 01 00:00:00 2010 PST'::timestamp with time zone)

SET timescaledb.enable_qual_propagation TO false;
EXPLAIN (buffers off, costs off) SELECT * FROM t t1 INNER JOIN t t2 ON t1.time = t2.time WHERE t1.time < timestamptz '2010-01-01';
--- QUERY PLAN ---
 Merge Join
   Merge Cond: (t1."time" = t2."time")
   ->  Merge Append
         Sort Key: t1."time"
         ->  Index Only Scan Backward using _hyper_15_182_chunk_t_time_idx on _hyper_15_182_chunk t1_1
         ->  Index Only Scan Backward using _hyper_15_183_chunk_t_time_idx on _hyper_15_183_chunk t1_2
               Index Cond: ("time" < 'Fri Jan 01 00:00:00 2010 PST'::timestamp with time zone)
   ->  Materialize
         ->  Merge Append
               Sort Key: t2."time"
               ->  Index Only Scan Backward using _hyper_15_182_chunk_t_time_idx on _hyper_15_182_chunk t2_1
               ->  Index Only Scan Backward using _hyper_15_183_chunk_t_time_idx on _hyper_15_183_chunk t2_2
               ->  Index Only Scan Backward using _hyper_15_184_chunk_t_time_idx on _hyper_15_184_chunk t2_3

RESET timescaledb.enable_qual_propagation;
CREATE TABLE test (a int, time timestamptz NOT NULL);
SELECT table_name FROM create_hypertable('public.test', 'time');
 table_name 
------------
 test

INSERT INTO test SELECT i, '2020-04-01'::date-10-i from generate_series(1,20) i;
CREATE OR REPLACE FUNCTION test_f(_ts timestamptz)
RETURNS SETOF test LANGUAGE SQL STABLE PARALLEL SAFE
AS $f$
   SELECT DISTINCT ON (a) * FROM test WHERE time >= _ts ORDER BY a, time DESC
$f$;
EXPLAIN (buffers off, costs off) SELECT * FROM test_f(now());
--- QUERY PLAN ---
 Unique
   ->  Sort
         Sort Key: test.a, test."time" DESC
         ->  Custom Scan (ChunkAppend) on test
               Chunks excluded during startup: 4

EXPLAIN (buffers off, costs off) SELECT * FROM test_f(now());
--- QUERY PLAN ---
 Unique
   ->  Sort
         Sort Key: test.a, test."time" DESC
         ->  Custom Scan (ChunkAppend) on test
               Chunks excluded during startup: 4

CREATE TABLE t1 (a int, b int NOT NULL);
SELECT create_hypertable('t1', 'b', chunk_time_interval=>10);
 create_hypertable 
-------------------
 (17,public,t1,t)

CREATE TABLE t2 (a int, b int NOT NULL);
SELECT create_hypertable('t2', 'b', chunk_time_interval=>10);
 create_hypertable 
-------------------
 (18,public,t2,t)

CREATE OR REPLACE FUNCTION f_t1(_a int, _b int)
 RETURNS SETOF t1
 LANGUAGE SQL
 STABLE PARALLEL SAFE
AS $function$
   SELECT DISTINCT ON (a) * FROM t1 WHERE a = _a and b = _b ORDER BY a, b DESC
$function$
;
CREATE OR REPLACE FUNCTION f_t2(_a int, _b int) RETURNS SETOF t2 LANGUAGE sql STABLE PARALLEL SAFE
AS $function$
   SELECT DISTINCT ON (j.a) j.*
   FROM
      f_t1(_a, _b) sc,
      t2 j
   WHERE
      j.b = _b AND
      j.a = _a
   ORDER BY j.a, j.b DESC
$function$
;
CREATE OR REPLACE FUNCTION f_t1_2(_b int) RETURNS SETOF t1 LANGUAGE SQL STABLE PARALLEL SAFE
AS $function$
   SELECT DISTINCT ON (j.a) jt.* FROM t1 j, f_t1(j.a, _b) jt
$function$;
EXPLAIN (buffers off, costs off) SELECT * FROM f_t1_2(10);
--- QUERY PLAN ---
 Subquery Scan on f_t1_2
   ->  Unique
         ->  Sort
               Sort Key: j.a
               ->  Nested Loop
                     ->  Seq Scan on t1 j
                     ->  Limit
                           ->  Index Scan using t1_b_idx on t1
                                 Index Cond: (b = 10)
                                 Filter: (a = j.a)

EXPLAIN (buffers off, costs off) SELECT * FROM f_t1_2(10) sc, f_t2(sc.a, 10);
--- QUERY PLAN ---
 Nested Loop
   ->  Unique
         ->  Sort
               Sort Key: j.a
               ->  Nested Loop
                     ->  Seq Scan on t1 j
                     ->  Limit
                           ->  Index Scan using t1_b_idx on t1
                                 Index Cond: (b = 10)
                                 Filter: (a = j.a)
   ->  Limit
         ->  Nested Loop
               ->  Limit
                     ->  Index Scan using t1_b_idx on t1 t1_1
                           Index Cond: (b = 10)
                           Filter: (a = t1.a)
               ->  Index Scan using t2_b_idx on t2 j_1
                     Index Cond: (b = 10)
                     Filter: (a = t1.a)

CREATE TABLE metrics_int1(time int, device text, value float) WITH (tsdb.hypertable,tsdb.partition_column='time',tsdb.chunk_interval=1);
INSERT INTO metrics_int1 SELECT i, i::text, i FROM generate_series(3,7) i;
SELECT tableoid::regclass, time FROM metrics_int1 ORDER BY time;
                 tableoid                  | time 
-------------------------------------------+------
 _timescaledb_internal._hyper_19_189_chunk |    3
 _timescaledb_internal._hyper_19_190_chunk |    4
 _timescaledb_internal._hyper_19_191_chunk |    5
 _timescaledb_internal._hyper_19_192_chunk |    6
 _timescaledb_internal._hyper_19_193_chunk |    7

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_int1 WHERE time >= 2;
--- QUERY PLAN ---
 Append (actual rows=5.00 loops=1)
   ->  Seq Scan on _hyper_19_189_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_190_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_191_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_192_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_193_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_int1 WHERE time >= 1 AND time >= 2;
--- QUERY PLAN ---
 Append (actual rows=5.00 loops=1)
   ->  Seq Scan on _hyper_19_189_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_190_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_191_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_192_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_193_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_int1 WHERE time >= 4;
--- QUERY PLAN ---
 Append (actual rows=4.00 loops=1)
   ->  Seq Scan on _hyper_19_190_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_191_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_192_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_193_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_int1 WHERE time > 4 AND time < 6;
--- QUERY PLAN ---
 Seq Scan on _hyper_19_191_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_int1 WHERE time > 4 AND time <= 6;
--- QUERY PLAN ---
 Append (actual rows=2.00 loops=1)
   ->  Seq Scan on _hyper_19_191_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_192_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_int1 WHERE time >= 4 AND time < 6;
--- QUERY PLAN ---
 Append (actual rows=2.00 loops=1)
   ->  Seq Scan on _hyper_19_190_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_191_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_int1 WHERE time >= 4 AND time <= 6;
--- QUERY PLAN ---
 Append (actual rows=3.00 loops=1)
   ->  Seq Scan on _hyper_19_190_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_191_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_192_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_int1 WHERE time BETWEEN 4 AND 5;
--- QUERY PLAN ---
 Append (actual rows=2.00 loops=1)
   ->  Seq Scan on _hyper_19_190_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_19_191_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_int1 WHERE time = 5;
--- QUERY PLAN ---
 Seq Scan on _hyper_19_191_chunk (actual rows=1.00 loops=1)

SET TIMEZONE='UTC';
CREATE TABLE metrics_tstz(time timestamptz, device text, value float) WITH (tsdb.hypertable,tsdb.partition_column='time',tsdb.chunk_interval='1day');
INSERT INTO metrics_tstz SELECT '2000-01-01'::timestamptz + format('%s day',i)::interval, i::text, i FROM generate_series(2,6) i;
SELECT tableoid::regclass, time FROM metrics_tstz ORDER BY time;
                 tableoid                  |             time             
-------------------------------------------+------------------------------
 _timescaledb_internal._hyper_20_194_chunk | Mon Jan 03 00:00:00 2000 UTC
 _timescaledb_internal._hyper_20_195_chunk | Tue Jan 04 00:00:00 2000 UTC
 _timescaledb_internal._hyper_20_196_chunk | Wed Jan 05 00:00:00 2000 UTC
 _timescaledb_internal._hyper_20_197_chunk | Thu Jan 06 00:00:00 2000 UTC
 _timescaledb_internal._hyper_20_198_chunk | Fri Jan 07 00:00:00 2000 UTC

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time >= '2000-01-02';
--- QUERY PLAN ---
 Append (actual rows=5.00 loops=1)
   ->  Seq Scan on _hyper_20_194_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_195_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_196_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_197_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_198_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time >= '2000-01-01' AND time >= '2000-01-02';
--- QUERY PLAN ---
 Append (actual rows=5.00 loops=1)
   ->  Seq Scan on _hyper_20_194_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_195_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_196_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_197_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_198_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time >= '2000-01-04';
--- QUERY PLAN ---
 Append (actual rows=4.00 loops=1)
   ->  Seq Scan on _hyper_20_195_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_196_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_197_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_198_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time > '2000-01-04' AND time < '2000-01-06';
--- QUERY PLAN ---
 Append (actual rows=1.00 loops=1)
   ->  Index Scan using _hyper_20_195_chunk_metrics_tstz_time_idx on _hyper_20_195_chunk (actual rows=0.00 loops=1)
         Index Cond: (("time" > 'Tue Jan 04 00:00:00 2000 UTC'::timestamp with time zone) AND ("time" < 'Thu Jan 06 00:00:00 2000 UTC'::timestamp with time zone))
   ->  Seq Scan on _hyper_20_196_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time > '2000-01-04' AND time <= '2000-01-06';
--- QUERY PLAN ---
 Append (actual rows=2.00 loops=1)
   ->  Index Scan using _hyper_20_195_chunk_metrics_tstz_time_idx on _hyper_20_195_chunk (actual rows=0.00 loops=1)
         Index Cond: (("time" > 'Tue Jan 04 00:00:00 2000 UTC'::timestamp with time zone) AND ("time" <= 'Thu Jan 06 00:00:00 2000 UTC'::timestamp with time zone))
   ->  Seq Scan on _hyper_20_196_chunk (actual rows=1.00 loops=1)
   ->  Index Scan using _hyper_20_197_chunk_metrics_tstz_time_idx on _hyper_20_197_chunk (actual rows=1.00 loops=1)
         Index Cond: (("time" > 'Tue Jan 04 00:00:00 2000 UTC'::timestamp with time zone) AND ("time" <= 'Thu Jan 06 00:00:00 2000 UTC'::timestamp with time zone))

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time >= '2000-01-04' AND time < '2000-01-06';
--- QUERY PLAN ---
 Append (actual rows=2.00 loops=1)
   ->  Seq Scan on _hyper_20_195_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_196_chunk (actual rows=1.00 loops=1)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time >= '2000-01-04' AND time <= '2000-01-06';
--- QUERY PLAN ---
 Append (actual rows=3.00 loops=1)
   ->  Seq Scan on _hyper_20_195_chunk (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_196_chunk (actual rows=1.00 loops=1)
   ->  Index Scan using _hyper_20_197_chunk_metrics_tstz_time_idx on _hyper_20_197_chunk (actual rows=1.00 loops=1)
         Index Cond: (("time" >= 'Tue Jan 04 00:00:00 2000 UTC'::timestamp with time zone) AND ("time" <= 'Thu Jan 06 00:00:00 2000 UTC'::timestamp with time zone))

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time BETWEEN '2000-01-04' AND '2000-01-05';
--- QUERY PLAN ---
 Append (actual rows=2.00 loops=1)
   ->  Seq Scan on _hyper_20_195_chunk (actual rows=1.00 loops=1)
   ->  Index Scan using _hyper_20_196_chunk_metrics_tstz_time_idx on _hyper_20_196_chunk (actual rows=1.00 loops=1)
         Index Cond: (("time" >= 'Tue Jan 04 00:00:00 2000 UTC'::timestamp with time zone) AND ("time" <= 'Wed Jan 05 00:00:00 2000 UTC'::timestamp with time zone))

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time = '2000-01-05';
--- QUERY PLAN ---
 Index Scan using _hyper_20_196_chunk_metrics_tstz_time_idx on _hyper_20_196_chunk (actual rows=1.00 loops=1)
   Index Cond: ("time" = 'Wed Jan 05 00:00:00 2000 UTC'::timestamp with time zone)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time >= '2000-01-04' AND time <= '2000-01-06' AND device = '5';
--- QUERY PLAN ---
 Append (actual rows=1.00 loops=1)
   ->  Seq Scan on _hyper_20_195_chunk (actual rows=0.00 loops=1)
         Filter: (device = '5'::text)
         Rows Removed by Filter: 1
   ->  Seq Scan on _hyper_20_196_chunk (actual rows=0.00 loops=1)
         Filter: (device = '5'::text)
         Rows Removed by Filter: 1
   ->  Index Scan using _hyper_20_197_chunk_metrics_tstz_time_idx on _hyper_20_197_chunk (actual rows=1.00 loops=1)
         Index Cond: (("time" >= 'Tue Jan 04 00:00:00 2000 UTC'::timestamp with time zone) AND ("time" <= 'Thu Jan 06 00:00:00 2000 UTC'::timestamp with time zone))
         Filter: (device = '5'::text)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time >= '2000-01-04' AND time <= '2000-01-06' AND device IS NOT NULL;
--- QUERY PLAN ---
 Append (actual rows=3.00 loops=1)
   ->  Seq Scan on _hyper_20_195_chunk (actual rows=1.00 loops=1)
         Filter: (device IS NOT NULL)
   ->  Seq Scan on _hyper_20_196_chunk (actual rows=1.00 loops=1)
         Filter: (device IS NOT NULL)
   ->  Index Scan using _hyper_20_197_chunk_metrics_tstz_time_idx on _hyper_20_197_chunk (actual rows=1.00 loops=1)
         Index Cond: (("time" >= 'Tue Jan 04 00:00:00 2000 UTC'::timestamp with time zone) AND ("time" <= 'Thu Jan 06 00:00:00 2000 UTC'::timestamp with time zone))
         Filter: (device IS NOT NULL)

EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_tstz WHERE time >= '2000-01-04' AND time <= '2000-01-06' AND time < now();
--- QUERY PLAN ---
 Custom Scan (ChunkAppend) on metrics_tstz (actual rows=3.00 loops=1)
   Chunks excluded during startup: 0
   ->  Index Scan using _hyper_20_195_chunk_metrics_tstz_time_idx on _hyper_20_195_chunk (actual rows=1.00 loops=1)
         Index Cond: ("time" < now())
   ->  Index Scan using _hyper_20_196_chunk_metrics_tstz_time_idx on _hyper_20_196_chunk (actual rows=1.00 loops=1)
         Index Cond: ("time" < now())
   ->  Index Scan using _hyper_20_197_chunk_metrics_tstz_time_idx on _hyper_20_197_chunk (actual rows=1.00 loops=1)
         Index Cond: (("time" >= 'Tue Jan 04 00:00:00 2000 UTC'::timestamp with time zone) AND ("time" <= 'Thu Jan 06 00:00:00 2000 UTC'::timestamp with time zone) AND ("time" < now()))

CREATE TABLE metrics_space(time timestamptz, device text, value float) WITH (tsdb.hypertable,tsdb.partition_column='time',tsdb.chunk_interval='1day');
SELECT add_dimension('metrics_space', 'device', 4);
           add_dimension            
------------------------------------
 (25,public,metrics_space,device,t)

INSERT INTO metrics_space SELECT '2000-01-01'::timestamptz + format('%s day',i)::interval, i::text, i FROM generate_series(2,6) i;
EXPLAIN (buffers off, costs off, timing off, summary off, analyze) SELECT * FROM metrics_space WHERE time >= '2000-01-02';
--- QUERY PLAN ---
 Append (actual rows=5.00 loops=1)
   ->  Index Scan using _hyper_21_199_chunk_metrics_space_time_idx on _hyper_21_199_chunk (actual rows=1.00 loops=1)
         Index Cond: ("time" >= 'Sun Jan 02 00:00:00 2000 UTC'::timestamp with time zone)
   ->  Index Scan using _hyper_21_200_chunk_metrics_space_time_idx on _hyper_21_200_chunk (actual rows=1.00 loops=1)
         Index Cond: ("time" >= 'Sun Jan 02 00:00:00 2000 UTC'::timestamp with time zone)
   ->  Index Scan using _hyper_21_201_chunk_metrics_space_time_idx on _hyper_21_201_chunk (actual rows=1.00 loops=1)
         Index Cond: ("time" >= 'Sun Jan 02 00:00:00 2000 UTC'::timestamp with time zone)
   ->  Index Scan using _hyper_21_202_chunk_metrics_space_time_idx on _hyper_21_202_chunk (actual rows=1.00 loops=1)
         Index Cond: ("time" >= 'Sun Jan 02 00:00:00 2000 UTC'::timestamp with time zone)
   ->  Index Scan using _hyper_21_203_chunk_metrics_space_time_idx on _hyper_21_203_chunk (actual rows=1.00 loops=1)
         Index Cond: ("time" >= 'Sun Jan 02 00:00:00 2000 UTC'::timestamp with time zone)

--TEST END--
