Skip to content

Commit

Permalink
Block OR BoolExpr from pushdown
Browse files Browse the repository at this point in the history
RestrictInfo with OR need special handling which we currently do
not do which can lead to segfaults in planner if unhandled.

(cherry picked from commit 01924c7)
  • Loading branch information
svenklemm authored and fabriziomello committed May 25, 2024
1 parent f3a0973 commit a2bc419
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 48 deletions.
10 changes: 10 additions & 0 deletions tsl/src/nodes/decompress_chunk/qual_pushdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -329,6 +330,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:
Expand Down
18 changes: 15 additions & 3 deletions tsl/test/expected/compression_qualpushdown.out
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)

19 changes: 6 additions & 13 deletions tsl/test/expected/transparent_decompression-14.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -4954,23 +4952,20 @@ 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
-> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=1068 loops=1)
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
-> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=356 loops=1)
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)
Expand Down Expand Up @@ -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
Expand Down
19 changes: 6 additions & 13 deletions tsl/test/expected/transparent_decompression-15.out
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -4928,23 +4926,20 @@ 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
-> Custom Scan (DecompressChunk) on _hyper_2_5_chunk (actual rows=1068 loops=1)
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
-> Custom Scan (DecompressChunk) on _hyper_2_6_chunk (actual rows=356 loops=1)
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)
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit a2bc419

Please sign in to comment.