diff --git a/tsl/src/nodes/decompress_chunk/qual_pushdown.c b/tsl/src/nodes/decompress_chunk/qual_pushdown.c index 9b919e9b1f2..30eced0dcda 100644 --- a/tsl/src/nodes/decompress_chunk/qual_pushdown.c +++ b/tsl/src/nodes/decompress_chunk/qual_pushdown.c @@ -63,7 +63,10 @@ pushdown_quals(PlannerInfo *root, RelOptInfo *chunk_rel, RelOptInfo *compressed_ /* pushdown is not safe for volatile expressions */ if (contain_volatile_functions((Node *) ri->clause)) + { + decompress_clauses = lappend(decompress_clauses, ri); continue; + } context.can_pushdown = true; context.needs_recheck = false; diff --git a/tsl/test/expected/transparent_decompression_queries.out b/tsl/test/expected/transparent_decompression_queries.out index 921551650f0..7c0d89bfc31 100644 --- a/tsl/test/expected/transparent_decompression_queries.out +++ b/tsl/test/expected/transparent_decompression_queries.out @@ -163,3 +163,40 @@ GROUP BY 2, 3; (27 rows) RESET enable_hashagg; +-- test if volatile function quals are applied to compressed chunks +CREATE FUNCTION check_equal_228( intval INTEGER) RETURNS BOOL +LANGUAGE PLPGSQL AS +$BODY$ +DECLARE + retval BOOL; +BEGIN + IF intval = 228 THEN RETURN TRUE; + ELSE RETURN FALSE; + END IF; +END; +$BODY$; +SELECT * from test_chartab +WHERE check_equal_228(rtt) ORDER BY ts; + job_run_id | mac_id | rtt | ts +------------+------------------+-----+------------------------------ + 8864 | 001407000001DD2E | 228 | Sat Dec 14 02:52:05.863 2019 + 8890 | 001407000001DD2E | 228 | Fri Dec 20 02:52:05.863 2019 +(2 rows) + +EXPLAIN (analyze,costs off,timing off,summary off) +SELECT * from test_chartab +WHERE check_equal_228(rtt) and ts < '2019-12-15 00:00:00' order by ts; + QUERY PLAN +----------------------------------------------------------------------------------------------------------------- + Sort (actual rows=1 loops=1) + Sort Key: test_chartab.ts + Sort Method: quicksort + -> Custom Scan (ChunkAppend) on test_chartab (actual rows=1 loops=1) + Chunks excluded during startup: 0 + -> Custom Scan (DecompressChunk) on _hyper_1_1_chunk (actual rows=1 loops=1) + Filter: ((ts < 'Sun Dec 15 00:00:00 2019'::timestamp without time zone) AND check_equal_228(rtt)) + Rows Removed by Filter: 2 + -> Seq Scan on compress_hyper_2_3_chunk (actual rows=3 loops=1) + Filter: (_ts_meta_min_1 < 'Sun Dec 15 00:00:00 2019'::timestamp without time zone) +(10 rows) + diff --git a/tsl/test/sql/transparent_decompression_queries.sql b/tsl/test/sql/transparent_decompression_queries.sql index b51bfd2119d..6540546eb87 100644 --- a/tsl/test/sql/transparent_decompression_queries.sql +++ b/tsl/test/sql/transparent_decompression_queries.sql @@ -67,3 +67,22 @@ GROUP BY 2, 3; RESET enable_hashagg; +-- test if volatile function quals are applied to compressed chunks +CREATE FUNCTION check_equal_228( intval INTEGER) RETURNS BOOL +LANGUAGE PLPGSQL AS +$BODY$ +DECLARE + retval BOOL; +BEGIN + IF intval = 228 THEN RETURN TRUE; + ELSE RETURN FALSE; + END IF; +END; +$BODY$; + +SELECT * from test_chartab +WHERE check_equal_228(rtt) ORDER BY ts; + +EXPLAIN (analyze,costs off,timing off,summary off) +SELECT * from test_chartab +WHERE check_equal_228(rtt) and ts < '2019-12-15 00:00:00' order by ts;