Skip to content

Commit c499b6f

Browse files
Fix explain table JOIN test.
1 parent 5c1d87b commit c499b6f

File tree

4 files changed

+27
-28
lines changed

4 files changed

+27
-28
lines changed

src/hooks.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static AnonQueryLinks *prepare_query(Query *query, ParamListInfo bound_params)
5959
return NULL;
6060

6161
/* At this point we have an anonymizing query. */
62-
DEBUG_LOG("Anonymizing query (Query ID=%lu) (User ID=%u) %s", query->queryId, GetSessionUserId(), nodeToString(query));
62+
DEBUG_LOG("Anonymizing query (User ID=%u) %s", GetSessionUserId(), nodeToString(query));
6363

6464
/* We load OIDs lazily because experimentation shows that UDFs may return INVALIDOID (0) during _PG_init. */
6565
oid_cache_init();
@@ -72,7 +72,7 @@ static AnonQueryLinks *prepare_query(Query *query, ParamListInfo bound_params)
7272

7373
AnonQueryLinks *links = compile_query(query, personal_relations, bound_params);
7474

75-
DEBUG_LOG("Compiled query (Query ID=%lu) (User ID=%u) %s", query->queryId, GetSessionUserId(), nodeToString(query));
75+
DEBUG_LOG("Compiled query (User ID=%u) %s", GetSessionUserId(), nodeToString(query));
7676

7777
return links;
7878
}
@@ -83,10 +83,7 @@ static PlannedStmt *pg_diffix_planner(
8383
int cursorOptions,
8484
ParamListInfo boundParams)
8585
{
86-
static uint64 next_query_id = 1;
87-
query->queryId = next_query_id++;
88-
89-
DEBUG_LOG("Statement (Query ID=%lu) (User ID=%u): %s", query->queryId, GetSessionUserId(), query_string);
86+
DEBUG_LOG("Statement (User ID=%u): %s", GetSessionUserId(), query_string);
9087

9188
AnonQueryLinks *links = prepare_query(query, boundParams);
9289

src/query/anonymization.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ static AnonymizationContext *make_query_anonymizing(Query *query, List *personal
731731
/* Only simple select queries require implicit grouping. */
732732
if (!initial_has_aggs && !initial_has_group_clause)
733733
{
734-
DEBUG_LOG("Rewriting query to group and expand implicit buckets (Query ID=%lu).", query->queryId);
734+
DEBUG_LOG("Rewriting query to group and expand implicit buckets.");
735735
group_implicit_buckets(query);
736736
add_junk_count_star(query);
737737
anon_context->expand_buckets = true;

test/expected/misc.out

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,26 @@ SELECT id FROM test_customers WHERE NULL = NULL;
212212
----
213213
(0 rows)
214214

215+
-- JOIN between personal tables produces multiple AIDs
216+
EXPLAIN VERBOSE SELECT COUNT(*) FROM test_customers c JOIN test_purchases pur ON c.id = cid;
217+
QUERY PLAN
218+
-------------------------------------------------------------
219+
Custom Scan (BucketScan)
220+
Output: (diffix.anon_count_star(c.id, pur.cid))
221+
-> Aggregate
222+
Output: diffix.anon_count_star(c.id, pur.cid)
223+
-> Hash Join
224+
Output: c.id, pur.cid
225+
Inner Unique: true
226+
Hash Cond: (pur.cid = c.id)
227+
-> Seq Scan on public.test_purchases pur
228+
Output: pur.cid, pur.pid
229+
-> Hash
230+
Output: c.id
231+
-> Seq Scan on public.test_customers c
232+
Output: c.id
233+
(14 rows)
234+
215235
-- Tolerate `diffix.agg_noise` in direct access level
216236
SET pg_diffix.session_access_level = 'direct';
217237
SELECT diffix.sum_noise(discount), diffix.count_noise(*) FROM test_customers;
@@ -231,21 +251,3 @@ ERROR: Column `id` is already marked as an AID.
231251
CONTEXT: PL/pgSQL function diffix.assert_column_is_not_aid(text,text) line 20 at RAISE
232252
SQL statement "CALL diffix.assert_column_is_not_aid(table_name, column_name)"
233253
PL/pgSQL function diffix.mark_filterable(text,text) line 3 at CALL
234-
-- JOIN between personal tables produces multiple AIDs
235-
EXPLAIN VERBOSE SELECT COUNT(*) FROM test_customers c JOIN test_purchases pur ON c.id = cid;
236-
QUERY PLAN
237-
--------------------------------------------------------------------------------------------
238-
Aggregate (cost=72.44..72.45 rows=1 width=8)
239-
Output: count(*)
240-
-> Hash Join (cost=28.23..66.79 rows=2260 width=0)
241-
Inner Unique: true
242-
Hash Cond: (pur.cid = c.id)
243-
-> Seq Scan on public.test_purchases pur (cost=0.00..32.60 rows=2260 width=4)
244-
Output: pur.cid, pur.pid
245-
-> Hash (cost=18.10..18.10 rows=810 width=4)
246-
Output: c.id
247-
-> Seq Scan on public.test_customers c (cost=0.00..18.10 rows=810 width=4)
248-
Output: c.id
249-
Query Identifier: 31
250-
(12 rows)
251-

test/sql/misc.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ SELECT FROM test_customers WHERE FALSE;
101101
SELECT TRUE AS "_" FROM test_customers WHERE 1 <> 1 LIMIT 0;
102102
SELECT id FROM test_customers WHERE NULL = NULL;
103103

104+
-- JOIN between personal tables produces multiple AIDs
105+
EXPLAIN VERBOSE SELECT COUNT(*) FROM test_customers c JOIN test_purchases pur ON c.id = cid;
106+
104107
-- Tolerate `diffix.agg_noise` in direct access level
105108
SET pg_diffix.session_access_level = 'direct';
106109
SELECT diffix.sum_noise(discount), diffix.count_noise(*) FROM test_customers;
107110

108111
-- Rejects marking an AID column.
109112
CALL diffix.mark_not_filterable('test_customers', 'id');
110113
CALL diffix.mark_filterable('test_customers', 'id');
111-
112-
-- JOIN between personal tables produces multiple AIDs
113-
EXPLAIN VERBOSE SELECT COUNT(*) FROM test_customers c JOIN test_purchases pur ON c.id = cid;

0 commit comments

Comments
 (0)