Block OR BoolExpr from pushdown

RestrictInfo with OR need special handling which we currently do
not do which can lead to segfaults in planner if unhandled.
This commit is contained in:
Sven Klemm 2024-05-14 12:38:50 +02:00 committed by Sven Klemm
parent f7255f0202
commit 01924c75d8
9 changed files with 56 additions and 48 deletions

View File

@ -13,6 +13,7 @@
#include <utils/builtins.h>
#include <utils/typcache.h>
#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:

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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