Skip to content

Commit ef2e078

Browse files
Fixed handling of IN (subquery) expressions.
1 parent e6f734e commit ef2e078

File tree

8 files changed

+23
-1
lines changed

8 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- Allow casts between `int4` and `int8`.
55
- Allow more metadata discovery queries.
66
- Allow more statement types.
7+
- Fixed handling of `IN (subquery)` expressions.
78

89
## Version 1.0.1
910
- Fixed some docs links.

pg_diffix/query/anonymization.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ typedef struct AnonQueryLinks AnonQueryLinks;
1818
*/
1919
extern AnonQueryLinks *compile_query(Query *query, List *personal_relations);
2020

21+
/*
22+
* Calls `rewrite_plan` for each item in a list of Plan nodes.
23+
*/
24+
extern void rewrite_plan_list(List *plans, AnonQueryLinks *links);
25+
2126
/*
2227
* Wraps anonymizing Agg nodes with BucketScan nodes. Does nothing if links is NULL.
2328
* Frees memory associated with links after rewriting.

src/hooks.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static PlannedStmt *pg_diffix_planner(
9494
PlannedStmt *plan = planner(query, query_string, cursorOptions, boundParams);
9595

9696
plan->planTree = rewrite_plan(plan->planTree, links);
97+
rewrite_plan_list(plan->subplans, links);
9798

9899
return plan;
99100
}

src/query/anonymization.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ static void unwrap_having_qual(Plan *plan)
734734
plan->qual = make_ands_implicit(having_qual);
735735
}
736736

737-
static void rewrite_plan_list(List *plans, AnonQueryLinks *links)
737+
void rewrite_plan_list(List *plans, AnonQueryLinks *links)
738738
{
739739
ListCell *cell;
740740
foreach (cell, plans)

test/expected/misc.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ HAVING age IS NULL OR age > 40;
5151
64 | 2
5252
(3 rows)
5353

54+
SELECT 'London' IN (SELECT city FROM test_customers);
55+
?column?
56+
----------
57+
f
58+
(1 row)
59+
5460
-- Prevent post-processing filters from being pushed down
5561
EXPLAIN SELECT age, count(*)
5662
FROM test_patients

test/expected/validation.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ SELECT 1 WHERE EXISTS (SELECT city FROM test_validation);
156156
----------
157157
(0 rows)
158158

159+
SELECT 'London' IN (SELECT city FROM test_validation);
160+
?column?
161+
----------
162+
f
163+
(1 row)
164+
159165
-- Anonymizing leaf subqueries are supported.
160166
SELECT * FROM ( SELECT COUNT(*) FROM test_validation ) x;
161167
count

test/sql/misc.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ FROM test_patients
3535
GROUP BY age
3636
HAVING age IS NULL OR age > 40;
3737

38+
SELECT 'London' IN (SELECT city FROM test_customers);
39+
3840
-- Prevent post-processing filters from being pushed down
3941
EXPLAIN SELECT age, count(*)
4042
FROM test_patients

test/sql/validation.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ SELECT city FROM test_validation UNION SELECT city FROM test_validation;
101101
-- Anonymizing sublinks are supported.
102102
SELECT EXISTS (SELECT city FROM test_validation);
103103
SELECT 1 WHERE EXISTS (SELECT city FROM test_validation);
104+
SELECT 'London' IN (SELECT city FROM test_validation);
104105

105106
-- Anonymizing leaf subqueries are supported.
106107
SELECT * FROM ( SELECT COUNT(*) FROM test_validation ) x;

0 commit comments

Comments
 (0)