Skip to content

Commit

Permalink
Apply volatile function quals at decompresschunk
Browse files Browse the repository at this point in the history
Volatile functions that are in chunk's baserestrictinfo
list were not correctly handled when we inserted a
DecompressChunk node. This PR adds these quals as a filter
to the DecompressChunk node.

Fixes #2864
  • Loading branch information
gayyappan committed Jan 26, 2021
1 parent b1dc030 commit c320646
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tsl/src/nodes/decompress_chunk/qual_pushdown.c
Expand Up @@ -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;
Expand Down
37 changes: 37 additions & 0 deletions tsl/test/expected/transparent_decompression_queries.out
Expand Up @@ -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)

19 changes: 19 additions & 0 deletions tsl/test/sql/transparent_decompression_queries.sql
Expand Up @@ -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;

0 comments on commit c320646

Please sign in to comment.