|
1 | 1 | #include "postgres.h" |
2 | 2 |
|
3 | 3 | #include "catalog/pg_aggregate.h" |
| 4 | +#include "catalog/pg_class.h" |
4 | 5 | #include "catalog/pg_type.h" |
5 | 6 | #include "common/shortest_dec.h" |
6 | 7 | #include "nodes/makefuncs.h" |
|
14 | 15 |
|
15 | 16 | #include "pg_diffix/aggregation/bucket_scan.h" |
16 | 17 | #include "pg_diffix/aggregation/common.h" |
| 18 | +#include "pg_diffix/auth.h" |
17 | 19 | #include "pg_diffix/oid_cache.h" |
18 | 20 | #include "pg_diffix/query/allowed_objects.h" |
19 | 21 | #include "pg_diffix/query/anonymization.h" |
@@ -270,24 +272,21 @@ static List *gather_aid_refs(Query *query, List *relations) |
270 | 272 | return aid_refs; |
271 | 273 | } |
272 | 274 |
|
273 | | -static void reject_aid_grouping(Query *query, List *aid_refs) |
| 275 | +static void reject_aid_grouping(Query *query) |
274 | 276 | { |
275 | | - ListCell *cell; |
276 | 277 | List *grouping_exprs = get_sortgrouplist_exprs(query->groupClause, query->targetList); |
| 278 | + |
| 279 | + ListCell *cell; |
277 | 280 | foreach (cell, grouping_exprs) |
278 | 281 | { |
279 | 282 | Node *group_expr = (Node *)lfirst(cell); |
280 | 283 | if (IsA(group_expr, Var)) |
281 | 284 | { |
282 | 285 | Var *var = (Var *)group_expr; |
| 286 | + RangeTblEntry *rte = rt_fetch(var->varno, query->rtable); |
283 | 287 |
|
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."); |
291 | 290 | } |
292 | 291 | } |
293 | 292 | } |
@@ -493,8 +492,6 @@ static AnonymizationContext *make_query_anonymizing(Query *query, List *personal |
493 | 492 | anon_context->expand_buckets = true; |
494 | 493 | } |
495 | 494 |
|
496 | | - reject_aid_grouping(query, aid_refs); |
497 | | - |
498 | 495 | query_tree_mutator( |
499 | 496 | query, |
500 | 497 | aggregate_expression_mutator, |
@@ -608,6 +605,8 @@ static void compile_anonymizing_query(Query *query, List *personal_relations, An |
608 | 605 |
|
609 | 606 | AnonymizationContext *anon_context = make_query_anonymizing(query, personal_relations); |
610 | 607 |
|
| 608 | + reject_aid_grouping(query); |
| 609 | + |
611 | 610 | verify_bucket_expressions(query); |
612 | 611 |
|
613 | 612 | anon_context->sql_seed = prepare_bucket_seeds(query); |
|
0 commit comments