Skip to content

Commit fe52376

Browse files
committed
Fixes to rejecting select/group by AID after review
1 parent f84fdb8 commit fe52376

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

src/query/anonymization.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "postgres.h"
22

33
#include "catalog/pg_aggregate.h"
4+
#include "catalog/pg_class.h"
45
#include "catalog/pg_type.h"
56
#include "common/shortest_dec.h"
67
#include "nodes/makefuncs.h"
@@ -14,6 +15,7 @@
1415

1516
#include "pg_diffix/aggregation/bucket_scan.h"
1617
#include "pg_diffix/aggregation/common.h"
18+
#include "pg_diffix/auth.h"
1719
#include "pg_diffix/oid_cache.h"
1820
#include "pg_diffix/query/allowed_objects.h"
1921
#include "pg_diffix/query/anonymization.h"
@@ -270,24 +272,21 @@ static List *gather_aid_refs(Query *query, List *relations)
270272
return aid_refs;
271273
}
272274

273-
static void reject_aid_grouping(Query *query, List *aid_refs)
275+
static void reject_aid_grouping(Query *query)
274276
{
275-
ListCell *cell;
276277
List *grouping_exprs = get_sortgrouplist_exprs(query->groupClause, query->targetList);
278+
279+
ListCell *cell;
277280
foreach (cell, grouping_exprs)
278281
{
279282
Node *group_expr = (Node *)lfirst(cell);
280283
if (IsA(group_expr, Var))
281284
{
282285
Var *var = (Var *)group_expr;
286+
RangeTblEntry *rte = rt_fetch(var->varno, query->rtable);
283287

284-
ListCell *aid_ref_cell;
285-
foreach (aid_ref_cell, aid_refs)
286-
{
287-
AidRef *aid_ref = (AidRef *)lfirst(aid_ref_cell);
288-
if (aid_ref->aid_attnum == var->varattno)
289-
FAILWITH_LOCATION(var->location, "Selecting AID without generalization cannot yield any results - rejecting.");
290-
}
288+
if (rte->relkind == RELKIND_RELATION && is_aid_column(rte->relid, var->varattno))
289+
FAILWITH_LOCATION(var->location, "Selecting or grouping by an AID column will result in a fully censored output.");
291290
}
292291
}
293292
}
@@ -493,8 +492,6 @@ static AnonymizationContext *make_query_anonymizing(Query *query, List *personal
493492
anon_context->expand_buckets = true;
494493
}
495494

496-
reject_aid_grouping(query, aid_refs);
497-
498495
query_tree_mutator(
499496
query,
500497
aggregate_expression_mutator,
@@ -608,6 +605,8 @@ static void compile_anonymizing_query(Query *query, List *personal_relations, An
608605

609606
AnonymizationContext *anon_context = make_query_anonymizing(query, personal_relations);
610607

608+
reject_aid_grouping(query);
609+
611610
verify_bucket_expressions(query);
612611

613612
anon_context->sql_seed = prepare_bucket_seeds(query);

test/expected/validation.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,15 @@ LINE 1: SELECT count(distinct tableoid) FROM test_validation;
492492
^
493493
-- Get rejected because of selecting AID columns
494494
SELECT id FROM test_validation;
495-
ERROR: [PG_DIFFIX] Selecting AID without generalization cannot yield any results - rejecting.
495+
ERROR: [PG_DIFFIX] Selecting or grouping by an AID column will result in a fully censored output.
496496
LINE 1: SELECT id FROM test_validation;
497497
^
498498
SELECT 1 FROM test_validation GROUP BY id;
499-
ERROR: [PG_DIFFIX] Selecting AID without generalization cannot yield any results - rejecting.
499+
ERROR: [PG_DIFFIX] Selecting or grouping by an AID column will result in a fully censored output.
500500
LINE 1: SELECT 1 FROM test_validation GROUP BY id;
501501
^
502502
SELECT * FROM (SELECT id FROM test_validation) z;
503-
ERROR: [PG_DIFFIX] Selecting AID without generalization cannot yield any results - rejecting.
503+
ERROR: [PG_DIFFIX] Selecting or grouping by an AID column will result in a fully censored output.
504504
LINE 1: SELECT * FROM (SELECT id FROM test_validation) z;
505505
^
506506
-- Get accepted because of selecting AID with generalization

0 commit comments

Comments
 (0)