diff --git a/tsl/src/nodes/decompress_chunk/qual_pushdown.c b/tsl/src/nodes/decompress_chunk/qual_pushdown.c index 3da9cab6f..0469401fc 100644 --- a/tsl/src/nodes/decompress_chunk/qual_pushdown.c +++ b/tsl/src/nodes/decompress_chunk/qual_pushdown.c @@ -13,6 +13,7 @@ #include #include +#include "annotations.h" #include "decompress_chunk.h" #include "qual_pushdown.h" #include "ts_catalog/array_utils.h" @@ -328,6 +329,15 @@ modify_expression(Node *node, QualPushdownContext *context) break; } case T_BoolExpr: + { + if (castNode(BoolExpr, node)->boolop == OR_EXPR) + { + /* ORs are not pushable */ + context->can_pushdown = false; + return NULL; + } + TS_FALLTHROUGH; + } case T_CoerceViaIO: case T_RelabelType: case T_ScalarArrayOpExpr: diff --git a/tsl/test/expected/compression_qualpushdown.out b/tsl/test/expected/compression_qualpushdown.out index e1e33a754..af6dd7375 100644 --- a/tsl/test/expected/compression_qualpushdown.out +++ b/tsl/test/expected/compression_qualpushdown.out @@ -490,13 +490,13 @@ EXPLAIN (costs off) SELECT * FROM svf_pushdown WHERE c_name = SESSION_USER; (5 rows) EXPLAIN (costs off) SELECT * FROM svf_pushdown WHERE c_name = CURRENT_USER OR c_name = SESSION_USER; - QUERY PLAN ----------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------- Custom Scan (ChunkAppend) on svf_pushdown Chunks excluded during startup: 0 -> Custom Scan (DecompressChunk) on _hyper_11_12_chunk + Filter: ((c_name = CURRENT_USER) OR (c_name = SESSION_USER)) -> Seq Scan on compress_hyper_12_13_chunk - Filter: ((c_name = CURRENT_USER) OR (c_name = SESSION_USER)) (5 rows) EXPLAIN (costs off) SELECT * FROM svf_pushdown WHERE c_name = CURRENT_CATALOG; @@ -562,3 +562,15 @@ EXPLAIN (costs off) SELECT * FROM svf_pushdown WHERE c_name = current_query(); -> Seq Scan on compress_hyper_12_13_chunk (5 rows) +-- test or constraints in lateral query #6912 +SELECT FROM svf_pushdown m1, +LATERAL( + SELECT FROM svf_pushdown m2 + WHERE + m1.time = m2.time AND + EXISTS (SELECT random()) OR + EXISTS (SELECT FROM meta) LIMIT 1 +) l; +-- +(1 row) + diff --git a/tsl/test/expected/transparent_decompression-14.out b/tsl/test/expected/transparent_decompression-14.out index 88351ab5f..077c64210 100644 --- a/tsl/test/expected/transparent_decompression-14.out +++ b/tsl/test/expected/transparent_decompression-14.out @@ -1141,8 +1141,8 @@ WHERE time > '2000-01-01 1:00:00+0' ORDER BY time, device_id LIMIT 10; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) -> Custom Scan (ChunkAppend) on metrics (actual rows=10 loops=1) Order: metrics."time", metrics.device_id @@ -1153,7 +1153,6 @@ LIMIT 10; Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) Rows Removed by Filter: 16 -> Seq Scan on compress_hyper_5_15_chunk (actual rows=5 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (never executed) Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id -> Seq Scan on _hyper_1_2_chunk (never executed) @@ -1163,8 +1162,7 @@ LIMIT 10; -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_5_16_chunk (never executed) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -(21 rows) +(19 rows) --functions not yet optimized :PREFIX @@ -4941,8 +4939,8 @@ WHERE time > '2000-01-01 1:00:00+0' ORDER BY time, device_id LIMIT 10; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) -> Custom Scan (ChunkAppend) on metrics_space (actual rows=10 loops=1) Order: metrics_space."time", metrics_space.device_id @@ -4954,7 +4952,6 @@ LIMIT 10; -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=360 loops=1) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_6_17_chunk (actual rows=1 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (actual rows=4 loops=1) Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id Sort Method: top-N heapsort @@ -4962,7 +4959,6 @@ LIMIT 10; Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) Rows Removed by Filter: 12 -> Seq Scan on compress_hyper_6_18_chunk (actual rows=3 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (actual rows=2 loops=1) Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id Sort Method: top-N heapsort @@ -4970,7 +4966,6 @@ LIMIT 10; Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) Rows Removed by Filter: 4 -> Seq Scan on compress_hyper_6_19_chunk (actual rows=1 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Merge Append (never executed) Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id -> Sort (never executed) @@ -4998,20 +4993,18 @@ LIMIT 10; -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_6_20_chunk (never executed) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (never executed) Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_6_21_chunk (never executed) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (never executed) Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id -> Sort (never executed) Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id -> Seq Scan on _hyper_2_12_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -(68 rows) +(63 rows) --functions not yet optimized :PREFIX diff --git a/tsl/test/expected/transparent_decompression-15.out b/tsl/test/expected/transparent_decompression-15.out index d0bb01ee3..e90d5143a 100644 --- a/tsl/test/expected/transparent_decompression-15.out +++ b/tsl/test/expected/transparent_decompression-15.out @@ -1142,8 +1142,8 @@ WHERE time > '2000-01-01 1:00:00+0' ORDER BY time, device_id LIMIT 10; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) -> Custom Scan (ChunkAppend) on metrics (actual rows=10 loops=1) Order: metrics."time", metrics.device_id @@ -1154,7 +1154,6 @@ LIMIT 10; Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) Rows Removed by Filter: 16 -> Seq Scan on compress_hyper_5_15_chunk (actual rows=5 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (never executed) Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id -> Seq Scan on _hyper_1_2_chunk (never executed) @@ -1164,8 +1163,7 @@ LIMIT 10; -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_5_16_chunk (never executed) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -(21 rows) +(19 rows) --functions not yet optimized :PREFIX @@ -4915,8 +4913,8 @@ WHERE time > '2000-01-01 1:00:00+0' ORDER BY time, device_id LIMIT 10; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) -> Custom Scan (ChunkAppend) on metrics_space (actual rows=10 loops=1) Order: metrics_space."time", metrics_space.device_id @@ -4928,7 +4926,6 @@ LIMIT 10; -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=360 loops=1) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_6_17_chunk (actual rows=1 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (actual rows=4 loops=1) Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id Sort Method: top-N heapsort @@ -4936,7 +4933,6 @@ LIMIT 10; Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) Rows Removed by Filter: 12 -> Seq Scan on compress_hyper_6_18_chunk (actual rows=3 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (actual rows=2 loops=1) Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id Sort Method: top-N heapsort @@ -4944,7 +4940,6 @@ LIMIT 10; Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) Rows Removed by Filter: 4 -> Seq Scan on compress_hyper_6_19_chunk (actual rows=1 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Merge Append (never executed) Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id -> Sort (never executed) @@ -4972,20 +4967,18 @@ LIMIT 10; -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_6_20_chunk (never executed) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (never executed) Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_6_21_chunk (never executed) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (never executed) Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id -> Sort (never executed) Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id -> Seq Scan on _hyper_2_12_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -(68 rows) +(63 rows) --functions not yet optimized :PREFIX diff --git a/tsl/test/expected/transparent_decompression-16.out b/tsl/test/expected/transparent_decompression-16.out index 9d14ff7b9..0e56618f5 100644 --- a/tsl/test/expected/transparent_decompression-16.out +++ b/tsl/test/expected/transparent_decompression-16.out @@ -1142,8 +1142,8 @@ WHERE time > '2000-01-01 1:00:00+0' ORDER BY time, device_id LIMIT 10; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) -> Custom Scan (ChunkAppend) on metrics (actual rows=10 loops=1) Order: metrics."time", metrics.device_id @@ -1154,7 +1154,6 @@ LIMIT 10; Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) Rows Removed by Filter: 16 -> Seq Scan on compress_hyper_5_15_chunk (actual rows=5 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (never executed) Sort Key: _hyper_1_2_chunk."time", _hyper_1_2_chunk.device_id -> Seq Scan on _hyper_1_2_chunk (never executed) @@ -1164,8 +1163,7 @@ LIMIT 10; -> Custom Scan (DecompressChunk) on _hyper_1_3_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_5_16_chunk (never executed) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -(21 rows) +(19 rows) --functions not yet optimized :PREFIX @@ -4915,8 +4913,8 @@ WHERE time > '2000-01-01 1:00:00+0' ORDER BY time, device_id LIMIT 10; - QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------- + QUERY PLAN +---------------------------------------------------------------------------------------------------------------------------------- Limit (actual rows=10 loops=1) -> Custom Scan (ChunkAppend) on metrics_space (actual rows=10 loops=1) Order: metrics_space."time", metrics_space.device_id @@ -4928,7 +4926,6 @@ LIMIT 10; -> Custom Scan (DecompressChunk) on _hyper_2_4_chunk (actual rows=360 loops=1) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_6_17_chunk (actual rows=1 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (actual rows=4 loops=1) Sort Key: _hyper_2_5_chunk."time", _hyper_2_5_chunk.device_id Sort Method: top-N heapsort @@ -4936,7 +4933,6 @@ LIMIT 10; Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) Rows Removed by Filter: 12 -> Seq Scan on compress_hyper_6_18_chunk (actual rows=3 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (actual rows=2 loops=1) Sort Key: _hyper_2_6_chunk."time", _hyper_2_6_chunk.device_id Sort Method: top-N heapsort @@ -4944,7 +4940,6 @@ LIMIT 10; Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) Rows Removed by Filter: 4 -> Seq Scan on compress_hyper_6_19_chunk (actual rows=1 loops=1) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Merge Append (never executed) Sort Key: _hyper_2_7_chunk."time", _hyper_2_7_chunk.device_id -> Sort (never executed) @@ -4972,20 +4967,18 @@ LIMIT 10; -> Custom Scan (DecompressChunk) on _hyper_2_10_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_6_20_chunk (never executed) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (never executed) Sort Key: _hyper_2_11_chunk."time", _hyper_2_11_chunk.device_id -> Custom Scan (DecompressChunk) on _hyper_2_11_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Seq Scan on compress_hyper_6_21_chunk (never executed) - Filter: ((_ts_meta_max_3 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Sort (never executed) Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id -> Sort (never executed) Sort Key: _hyper_2_12_chunk."time", _hyper_2_12_chunk.device_id -> Seq Scan on _hyper_2_12_chunk (never executed) Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -(68 rows) +(63 rows) --functions not yet optimized :PREFIX diff --git a/tsl/test/shared/expected/transparent_decompress_chunk-14.out b/tsl/test/shared/expected/transparent_decompress_chunk-14.out index e69fc4d0f..7e0490780 100644 --- a/tsl/test/shared/expected/transparent_decompress_chunk-14.out +++ b/tsl/test/shared/expected/transparent_decompress_chunk-14.out @@ -398,8 +398,7 @@ QUERY PLAN -> Custom Scan (DecompressChunk) on _hyper_X_X_chunk Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Parallel Seq Scan on compress_hyper_X_X_chunk - Filter: ((_ts_meta_max_1 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -(9 rows) +(8 rows) --functions not yet optimized :PREFIX_NO_VERBOSE SELECT * FROM :TEST_TABLE WHERE time < now() ORDER BY time, device_id LIMIT 10; diff --git a/tsl/test/shared/expected/transparent_decompress_chunk-15.out b/tsl/test/shared/expected/transparent_decompress_chunk-15.out index b964e8363..2dc36113a 100644 --- a/tsl/test/shared/expected/transparent_decompress_chunk-15.out +++ b/tsl/test/shared/expected/transparent_decompress_chunk-15.out @@ -400,8 +400,7 @@ QUERY PLAN -> Custom Scan (DecompressChunk) on _hyper_X_X_chunk Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Parallel Seq Scan on compress_hyper_X_X_chunk - Filter: ((_ts_meta_max_1 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -(9 rows) +(8 rows) --functions not yet optimized :PREFIX_NO_VERBOSE SELECT * FROM :TEST_TABLE WHERE time < now() ORDER BY time, device_id LIMIT 10; diff --git a/tsl/test/shared/expected/transparent_decompress_chunk-16.out b/tsl/test/shared/expected/transparent_decompress_chunk-16.out index 7f650ca53..8fc41af35 100644 --- a/tsl/test/shared/expected/transparent_decompress_chunk-16.out +++ b/tsl/test/shared/expected/transparent_decompress_chunk-16.out @@ -400,8 +400,7 @@ QUERY PLAN -> Custom Scan (DecompressChunk) on _hyper_X_X_chunk Filter: (("time" > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -> Parallel Seq Scan on compress_hyper_X_X_chunk - Filter: ((_ts_meta_max_1 > 'Fri Dec 31 17:00:00 1999 PST'::timestamp with time zone) OR (device_id = 1)) -(9 rows) +(8 rows) --functions not yet optimized :PREFIX_NO_VERBOSE SELECT * FROM :TEST_TABLE WHERE time < now() ORDER BY time, device_id LIMIT 10; diff --git a/tsl/test/sql/compression_qualpushdown.sql b/tsl/test/sql/compression_qualpushdown.sql index a98e9a63e..c2c9d8c04 100644 --- a/tsl/test/sql/compression_qualpushdown.sql +++ b/tsl/test/sql/compression_qualpushdown.sql @@ -186,3 +186,13 @@ EXPLAIN (costs off) SELECT * FROM svf_pushdown WHERE NOT c_bool; -- current_query() is not a sqlvaluefunction and volatile so should not be pushed down EXPLAIN (costs off) SELECT * FROM svf_pushdown WHERE c_name = current_query(); +-- test or constraints in lateral query #6912 +SELECT FROM svf_pushdown m1, +LATERAL( + SELECT FROM svf_pushdown m2 + WHERE + m1.time = m2.time AND + EXISTS (SELECT random()) OR + EXISTS (SELECT FROM meta) LIMIT 1 +) l; +