From 503d57bcfba7be0c2dee0a841cc61080d5cbc846 Mon Sep 17 00:00:00 2001 From: pdobacz <5735525+pdobacz@users.noreply.github.com> Date: Wed, 5 Jan 2022 12:40:28 +0100 Subject: [PATCH] Refactor and clarify the count and count_distinct code a bit --- pg_diffix--0.0.1.sql | 42 +++++++-------- pg_diffix/aggregation/count.h | 2 +- pg_diffix/query/oid_cache.h | 10 ++-- src/aggregation/count.c | 40 +++++++------- src/aggregation/count_distinct.c | 92 ++++++++++++++++---------------- src/aggregation/lcf.c | 22 ++++---- src/query/relation.c | 6 +-- src/query/rewrite.c | 38 ++++++------- src/query/validation.c | 6 +-- 9 files changed, 130 insertions(+), 128 deletions(-) diff --git a/pg_diffix--0.0.1.sql b/pg_diffix--0.0.1.sql index ea885cbd..572590b7 100644 --- a/pg_diffix--0.0.1.sql +++ b/pg_diffix--0.0.1.sql @@ -39,29 +39,29 @@ $$; * ---------------------------------------------------------------- */ -CREATE FUNCTION diffix.lcf_transfn(internal, variadic "any") +CREATE FUNCTION diffix.lcf_transfn(internal, variadic aids "any") RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE FUNCTION diffix.lcf_finalfn(internal, variadic "any") +CREATE FUNCTION diffix.lcf_finalfn(internal, variadic aids "any") RETURNS boolean AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE FUNCTION diffix.lcf_explain_finalfn(internal, variadic "any") +CREATE FUNCTION diffix.lcf_explain_finalfn(internal, variadic aids "any") RETURNS text AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE AGGREGATE diffix.lcf(variadic "any") ( +CREATE AGGREGATE diffix.lcf(variadic aids "any") ( sfunc = diffix.lcf_transfn, stype = internal, finalfunc = diffix.lcf_finalfn, finalfunc_extra ); -CREATE AGGREGATE diffix.explain_lcf(variadic "any") ( +CREATE AGGREGATE diffix.explain_lcf(variadic aids "any") ( sfunc = diffix.lcf_transfn, stype = internal, finalfunc = diffix.lcf_explain_finalfn, @@ -73,29 +73,29 @@ CREATE AGGREGATE diffix.explain_lcf(variadic "any") ( * ---------------------------------------------------------------- */ -CREATE FUNCTION diffix.anon_count_distinct_transfn(internal, "any", variadic "any") +CREATE FUNCTION diffix.anon_count_distinct_transfn(internal, value "any", variadic aids "any") RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE FUNCTION diffix.anon_count_distinct_finalfn(internal, "any", variadic "any") +CREATE FUNCTION diffix.anon_count_distinct_finalfn(internal, value "any", variadic aids "any") RETURNS int8 AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE FUNCTION diffix.anon_count_distinct_explain_finalfn(internal, "any", variadic "any") +CREATE FUNCTION diffix.anon_count_distinct_explain_finalfn(internal, value "any", variadic aids "any") RETURNS text AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE AGGREGATE diffix.anon_count_distinct("any", variadic "any") ( +CREATE AGGREGATE diffix.anon_count_distinct(value "any", variadic aids "any") ( sfunc = diffix.anon_count_distinct_transfn, stype = internal, finalfunc = diffix.anon_count_distinct_finalfn, finalfunc_extra ); -CREATE AGGREGATE diffix.explain_anon_count_distinct("any", variadic "any") ( +CREATE AGGREGATE diffix.explain_anon_count_distinct(value "any", variadic aids "any") ( sfunc = diffix.anon_count_distinct_transfn, stype = internal, finalfunc = diffix.anon_count_distinct_explain_finalfn, @@ -107,29 +107,29 @@ CREATE AGGREGATE diffix.explain_anon_count_distinct("any", variadic "any") ( * ---------------------------------------------------------------- */ -CREATE FUNCTION diffix.anon_count_transfn(internal, variadic "any") +CREATE FUNCTION diffix.anon_count_transfn(internal, variadic aids "any") RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE FUNCTION diffix.anon_count_finalfn(internal, variadic "any") +CREATE FUNCTION diffix.anon_count_finalfn(internal, variadic aids "any") RETURNS int8 AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE FUNCTION diffix.anon_count_explain_finalfn(internal, variadic "any") +CREATE FUNCTION diffix.anon_count_explain_finalfn(internal, variadic aids "any") RETURNS text AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE AGGREGATE diffix.anon_count(variadic "any") ( +CREATE AGGREGATE diffix.anon_count(variadic aids "any") ( sfunc = diffix.anon_count_transfn, stype = internal, finalfunc = diffix.anon_count_finalfn, finalfunc_extra ); -CREATE AGGREGATE diffix.explain_anon_count(variadic "any") ( +CREATE AGGREGATE diffix.explain_anon_count(variadic aids "any") ( sfunc = diffix.anon_count_transfn, stype = internal, finalfunc = diffix.anon_count_explain_finalfn, @@ -137,33 +137,33 @@ CREATE AGGREGATE diffix.explain_anon_count(variadic "any") ( ); /* ---------------------------------------------------------------- - * anon_count(any, aids...) + * anon_count_any(any, aids...) * ---------------------------------------------------------------- */ -CREATE FUNCTION diffix.anon_count_any_transfn(internal, "any", variadic "any") +CREATE FUNCTION diffix.anon_count_any_transfn(internal, value "any", variadic aids "any") RETURNS internal AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE FUNCTION diffix.anon_count_any_finalfn(internal, "any", variadic "any") +CREATE FUNCTION diffix.anon_count_any_finalfn(internal, value "any", variadic aids "any") RETURNS int8 AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE FUNCTION diffix.anon_count_any_explain_finalfn(internal, "any", variadic "any") +CREATE FUNCTION diffix.anon_count_any_explain_finalfn(internal, value "any", variadic aids "any") RETURNS text AS 'MODULE_PATHNAME' LANGUAGE C STABLE; -CREATE AGGREGATE diffix.anon_count_any("any", variadic "any") ( +CREATE AGGREGATE diffix.anon_count_any(value "any", variadic aids "any") ( sfunc = diffix.anon_count_any_transfn, stype = internal, finalfunc = diffix.anon_count_any_finalfn, finalfunc_extra ); -CREATE AGGREGATE diffix.explain_anon_count_any("any", variadic "any") ( +CREATE AGGREGATE diffix.explain_anon_count_any(value "any", variadic aids "any") ( sfunc = diffix.anon_count_any_transfn, stype = internal, finalfunc = diffix.anon_count_any_explain_finalfn, diff --git a/pg_diffix/aggregation/count.h b/pg_diffix/aggregation/count.h index 0e4e39e6..4087e770 100644 --- a/pg_diffix/aggregation/count.h +++ b/pg_diffix/aggregation/count.h @@ -31,7 +31,7 @@ extern CountResult aggregate_count_contributions( typedef struct CountResultAccumulator { int64 max_flattening; - int64 max_flattened_count; + int64 max_flattened_count_with_max_flattening; double max_noise_sigma; int64 noise_with_max_sigma; } CountResultAccumulator; diff --git a/pg_diffix/query/oid_cache.h b/pg_diffix/query/oid_cache.h index 7b945f71..b4bf2ba6 100644 --- a/pg_diffix/query/oid_cache.h +++ b/pg_diffix/query/oid_cache.h @@ -10,11 +10,11 @@ typedef struct Oids { Oid count; /* count(*) */ Oid count_any; /* count(any) */ - Oid lcf; /* lcf(aid) */ - Oid anon_count_distinct; /* anon_count_distinct(aid) */ - Oid anon_count; /* anon_count(aid) */ - Oid anon_count_any; /* anon_count(aid, any) */ - Oid generate_series; /* generate_series(aid, any) */ + Oid lcf; /* lcf(aids...) */ + Oid anon_count_distinct; /* anon_count_distinct(any, aids...) */ + Oid anon_count; /* anon_count(aids...) */ + Oid anon_count_any; /* anon_count_any(any, aids...) */ + Oid generate_series; /* generate_series(start, stop) */ } Oids; /* diff --git a/src/aggregation/count.c b/src/aggregation/count.c index 62034111..a2587704 100644 --- a/src/aggregation/count.c +++ b/src/aggregation/count.c @@ -38,6 +38,7 @@ const ContributionDescriptor count_descriptor = { static const int COUNT_AIDS_OFFSET = 1; static const int COUNT_ANY_AIDS_OFFSET = 2; +static const int VALUE_INDEX = 1; PG_FUNCTION_INFO_V1(anon_count_transfn); PG_FUNCTION_INFO_V1(anon_count_finalfn); @@ -53,13 +54,13 @@ Datum anon_count_transfn(PG_FUNCTION_ARGS) Assert(PG_NARGS() == list_length(trackers) + COUNT_AIDS_OFFSET); - ListCell *lc; - foreach (lc, trackers) + ListCell *cell; + foreach (cell, trackers) { - int aid_index = foreach_current_index(lc) + COUNT_AIDS_OFFSET; + int aid_index = foreach_current_index(cell) + COUNT_AIDS_OFFSET; if (!PG_ARGISNULL(aid_index)) { - ContributionTrackerState *tracker = (ContributionTrackerState *)lfirst(lc); + ContributionTrackerState *tracker = (ContributionTrackerState *)lfirst(cell); aid_t aid = tracker->aid_descriptor.make_aid(PG_GETARG_DATUM(aid_index)); contribution_tracker_update_contribution(tracker, aid, one_contribution); } @@ -74,15 +75,16 @@ Datum anon_count_any_transfn(PG_FUNCTION_ARGS) Assert(PG_NARGS() == list_length(trackers) + COUNT_ANY_AIDS_OFFSET); - ListCell *lc; - foreach (lc, trackers) + ListCell *cell; + foreach (cell, trackers) { - int aid_index = foreach_current_index(lc) + COUNT_ANY_AIDS_OFFSET; + int aid_index = foreach_current_index(cell) + COUNT_ANY_AIDS_OFFSET; if (!PG_ARGISNULL(aid_index)) { - ContributionTrackerState *tracker = (ContributionTrackerState *)lfirst(lc); + ContributionTrackerState *tracker = (ContributionTrackerState *)lfirst(cell); aid_t aid = tracker->aid_descriptor.make_aid(PG_GETARG_DATUM(aid_index)); - if (PG_ARGISNULL(1)) + if (PG_ARGISNULL(VALUE_INDEX)) + /* count argument is NULL, so no contribution, only keep track of the AID value */ contribution_tracker_update_aid(tracker, aid); else contribution_tracker_update_contribution(tracker, aid, one_contribution); @@ -148,13 +150,13 @@ static Datum explain_count_trackers(List *trackers) StringInfoData string; initStringInfo(&string); - ListCell *lc; - foreach (lc, trackers) + ListCell *cell; + foreach (cell, trackers) { - if (foreach_current_index(lc) > 0) + if (foreach_current_index(cell) > 0) appendStringInfo(&string, " \n"); - ContributionTrackerState *tracker = (ContributionTrackerState *)lfirst(lc); + ContributionTrackerState *tracker = (ContributionTrackerState *)lfirst(cell); append_tracker_info(&string, tracker); } @@ -240,8 +242,8 @@ void accumulate_count_result(CountResultAccumulator *accumulator, const CountRes if (flattening >= accumulator->max_flattening) { accumulator->max_flattening = flattening; - /* Get the largest flattened count from the ones with the maximum flattening. */ - accumulator->max_flattened_count = Max(accumulator->max_flattened_count, result->flattened_count); + accumulator->max_flattened_count_with_max_flattening = Max(accumulator->max_flattened_count_with_max_flattening, + result->flattened_count); } if (result->noise_sigma > accumulator->max_noise_sigma) @@ -253,17 +255,17 @@ void accumulate_count_result(CountResultAccumulator *accumulator, const CountRes int64 finalize_count_result(const CountResultAccumulator *accumulator) { - return Max(accumulator->max_flattened_count + accumulator->noise_with_max_sigma, 0); + return Max(accumulator->max_flattened_count_with_max_flattening + accumulator->noise_with_max_sigma, 0); } static Datum count_calculate_final(PG_FUNCTION_ARGS, List *trackers) { CountResultAccumulator result_accumulator = {0}; - ListCell *lc; - foreach (lc, trackers) + ListCell *cell; + foreach (cell, trackers) { - ContributionTrackerState *tracker = (ContributionTrackerState *)lfirst(lc); + ContributionTrackerState *tracker = (ContributionTrackerState *)lfirst(cell); CountResult result = count_calculate_aid_result(tracker); if (result.low_count) diff --git a/src/aggregation/count_distinct.c b/src/aggregation/count_distinct.c index 23757600..ff67d094 100644 --- a/src/aggregation/count_distinct.c +++ b/src/aggregation/count_distinct.c @@ -40,7 +40,7 @@ static uint32 hash_datum(Datum value, bool typbyval, int16 typlen) typedef struct DistinctTrackerHashEntry { Datum value; /* Unique value */ - List *aidvs; /* AID value sets for the unique value */ + List *aidvs; /* List of (hashes of) AID value lists, one for each AID instance */ char status; /* Required for hash table */ } DistinctTrackerHashEntry; @@ -68,7 +68,7 @@ typedef struct DistinctTrackerData static const int STATE_INDEX = 0; static const int VALUE_INDEX = 1; -static const int AIDS_INDEX = 2; +static const int COUNT_DISTINCT_AIDS_OFFSET = 2; static DistinctTracker_hash *get_distinct_tracker(PG_FUNCTION_ARGS) { @@ -83,7 +83,7 @@ static DistinctTracker_hash *get_distinct_tracker(PG_FUNCTION_ARGS) } static DistinctTrackerHashEntry * -get_distinct_tracker_entry(DistinctTracker_hash *tracker, Datum value, int aidvs_count) +get_distinct_tracker_entry(DistinctTracker_hash *tracker, Datum value, int aids_count) { bool found = false; DistinctTrackerHashEntry *entry = DistinctTracker_insert(tracker, value, &found); @@ -91,7 +91,7 @@ get_distinct_tracker_entry(DistinctTracker_hash *tracker, Datum value, int aidvs { entry->aidvs = NIL; entry->value = value; - for (int i = 0; i < aidvs_count; i++) + for (int i = 0; i < aids_count; i++) { entry->aidvs = lappend(entry->aidvs, NIL); } @@ -99,7 +99,7 @@ get_distinct_tracker_entry(DistinctTracker_hash *tracker, Datum value, int aidvs return entry; } -static List *add_aid_to_set(List *aidv, aid_t aid) +static List *add_aidv_to_set(List *aidv, aid_t aid) { int max_size = g_config.minimum_allowed_aid_values + LCF_RANGE + 1; if (list_length(aidv) == max_size) // set is full, value is not low-count @@ -120,22 +120,22 @@ Datum anon_count_distinct_transfn(PG_FUNCTION_ARGS) if (!PG_ARGISNULL(VALUE_INDEX)) { - Assert(PG_NARGS() > AIDS_INDEX); + Assert(PG_NARGS() > COUNT_DISTINCT_AIDS_OFFSET); Datum value = PG_GETARG_DATUM(VALUE_INDEX); - int aidvs_count = PG_NARGS() - AIDS_INDEX; - DistinctTrackerHashEntry *entry = get_distinct_tracker_entry(tracker, value, aidvs_count); + int aids_count = PG_NARGS() - COUNT_DISTINCT_AIDS_OFFSET; + DistinctTrackerHashEntry *entry = get_distinct_tracker_entry(tracker, value, aids_count); - ListCell *lc; - foreach (lc, entry->aidvs) + ListCell *cell; + foreach (cell, entry->aidvs) { - int aid_index = foreach_current_index(lc) + AIDS_INDEX; + int aid_index = foreach_current_index(cell) + COUNT_DISTINCT_AIDS_OFFSET; if (!PG_ARGISNULL(aid_index)) { Oid aid_type = get_fn_expr_argtype(fcinfo->flinfo, aid_index); aid_t aid = get_aid_descriptor(aid_type).make_aid(PG_GETARG_DATUM(aid_index)); - List **aidv = (List **)&lfirst(lc); // pointer to the set of AID values - *aidv = add_aid_to_set(*aidv, aid); + List **aidv = (List **)&lfirst(cell); // pointer to the set of AID values + *aidv = add_aidv_to_set(*aidv, aid); } } } @@ -152,7 +152,7 @@ typedef struct CountDistinctResult int64 noisy_count; } CountDistinctResult; -static CountDistinctResult count_distinct_calculate_final(DistinctTracker_hash *state, int aidvs_count); +static CountDistinctResult count_distinct_calculate_final(DistinctTracker_hash *state, int aids_count); Datum anon_count_distinct_finalfn(PG_FUNCTION_ARGS) { @@ -160,7 +160,7 @@ Datum anon_count_distinct_finalfn(PG_FUNCTION_ARGS) MemoryContext old_context = switch_to_aggregation_context(fcinfo); DistinctTracker_hash *tracker = get_distinct_tracker(fcinfo); - CountDistinctResult result = count_distinct_calculate_final(tracker, PG_NARGS() - AIDS_INDEX); + CountDistinctResult result = count_distinct_calculate_final(tracker, PG_NARGS() - COUNT_DISTINCT_AIDS_OFFSET); MemoryContextSwitchTo(old_context); @@ -176,7 +176,7 @@ Datum anon_count_distinct_explain_finalfn(PG_FUNCTION_ARGS) MemoryContext old_context = switch_to_aggregation_context(fcinfo); DistinctTracker_hash *tracker = get_distinct_tracker(fcinfo); - CountDistinctResult result = count_distinct_calculate_final(tracker, PG_NARGS() - AIDS_INDEX); + CountDistinctResult result = count_distinct_calculate_final(tracker, PG_NARGS() - COUNT_DISTINCT_AIDS_OFFSET); MemoryContextSwitchTo(old_context); @@ -189,36 +189,36 @@ Datum anon_count_distinct_explain_finalfn(PG_FUNCTION_ARGS) PG_RETURN_TEXT_P(cstring_to_text(string.data)); } -static uint64 seed_from_aidv(const List *aidv) +static uint64 seed_from_aidv(const List *aidvs) { uint64 seed = 0; - ListCell *lc; - foreach (lc, aidv) + ListCell *cell; + foreach (cell, aidvs) { - aid_t aid = (aid_t)lfirst(lc); + aid_t aid = (aid_t)lfirst(cell); seed ^= aid; } return make_seed(seed); } -static bool aid_set_is_high_count(const List *aidv) +static bool aid_set_is_high_count(const List *aidvs) { - if (list_length(aidv) < g_config.minimum_allowed_aid_values) + if (list_length(aidvs) < g_config.minimum_allowed_aid_values) return false; /* Less AID values than minimum threshold, value is low-count. */ int max_size = g_config.minimum_allowed_aid_values + LCF_RANGE + 1; - if (list_length(aidv) == max_size) + if (list_length(aidvs) == max_size) return true; /* More AID values than maximum threshold, value is high-count. */ - uint64 seed = seed_from_aidv(aidv); + uint64 seed = seed_from_aidv(aidvs); int threshold = generate_lcf_threshold(&seed); - return list_length(aidv) >= threshold; + return list_length(aidvs) >= threshold; } static bool aid_sets_are_high_count(const List *aidvs) { - ListCell *lc; - foreach (lc, aidvs) + ListCell *cell; + foreach (cell, aidvs) { - const List *aidv = (const List *)lfirst(lc); + const List *aidv = (const List *)lfirst(cell); if (!aid_set_is_high_count(aidv)) return false; } @@ -314,7 +314,7 @@ static List *associate_value_with_aid(List *per_aid_values, aid_t aid, Datum val } /* Maps values per-AID given the list of low-count tracker entries and an AID values set index. */ -static List *transpose_lc_values_per_aid(List *lc_entries, int aidvs_index, uint32 *lc_values_true_count) +static List *transpose_lc_values_per_aid(List *lc_entries, int aid_index, uint32 *lc_values_true_count) { List *per_aid_values = NIL; *lc_values_true_count = 0; @@ -323,15 +323,15 @@ static List *transpose_lc_values_per_aid(List *lc_entries, int aidvs_index, uint foreach (lc_entry_cell, lc_entries) { const DistinctTrackerHashEntry *entry = (const DistinctTrackerHashEntry *)lfirst(lc_entry_cell); - const List *aids = (const List *)list_nth(entry->aidvs, aidvs_index); + const List *aidvs = (const List *)list_nth(entry->aidvs, aid_index); - if (aids != NIL) /* Count unique value only if it has at least one associated AID value. */ + if (aidvs != NIL) /* Count unique value only if it has at least one associated AID value. */ (*lc_values_true_count)++; - ListCell *aid_cell; - foreach (aid_cell, aids) + ListCell *aidv_cell; + foreach (aidv_cell, aidvs) { - aid_t aid = (aid_t)lfirst(aid_cell); + aid_t aid = (aid_t)lfirst(aidv_cell); per_aid_values = associate_value_with_aid(per_aid_values, aid, entry->value); } } @@ -362,10 +362,10 @@ static int compare_per_aid_values_entries(const ListCell *a, const ListCell *b) static void delete_value(List *per_aid_values, Datum value) { - ListCell *lc; - foreach (lc, per_aid_values) + ListCell *cell; + foreach (cell, per_aid_values) { - PerAidValuesEntry *entry = (PerAidValuesEntry *)lfirst(lc); + PerAidValuesEntry *entry = (PerAidValuesEntry *)lfirst(cell); /* Since values are unique at this point, we can use simple pointer equality even for reference types. */ entry->values = list_delete_ptr(entry->values, (void *)value); } @@ -382,10 +382,10 @@ static void distribute_lc_values(List *per_aid_values, uint32 values_count) while (values_count > 0) { - ListCell *lc; - foreach (lc, per_aid_values) + ListCell *cell; + foreach (cell, per_aid_values) { - PerAidValuesEntry *entry = (PerAidValuesEntry *)lfirst(lc); + PerAidValuesEntry *entry = (PerAidValuesEntry *)lfirst(cell); if (entry->values != NIL) { values_count--; @@ -404,10 +404,10 @@ static void process_lc_values_contributions( *contributors_count = 0; *seed = 0; - ListCell *lc; - foreach (lc, per_aid_values) + ListCell *cell; + foreach (cell, per_aid_values) { - PerAidValuesEntry *entry = (PerAidValuesEntry *)lfirst(lc); + PerAidValuesEntry *entry = (PerAidValuesEntry *)lfirst(cell); *seed ^= entry->aid; if (entry->contributions > 0) { @@ -422,7 +422,7 @@ static void process_lc_values_contributions( * The number of high count values is safe to be shown directly, without any extra noise. * The number of low count values has to be anonymized. */ -static CountDistinctResult count_distinct_calculate_final(DistinctTracker_hash *tracker, int aidvs_count) +static CountDistinctResult count_distinct_calculate_final(DistinctTracker_hash *tracker, int aids_count) { List *lc_entries = filter_lc_entries(tracker); sort_tracker_entries_by_value(lc_entries, DATA(tracker)); /* Needed to ensure determinism. */ @@ -436,10 +436,10 @@ static CountDistinctResult count_distinct_calculate_final(DistinctTracker_hash * bool insufficient_data = false; CountResultAccumulator result_accumulator = {0}; - for (int aidvs_index = 0; aidvs_index < aidvs_count; aidvs_index++) + for (int aid_index = 0; aid_index < aids_count; aid_index++) { uint32 lc_values_true_count = 0; - List *per_aid_values = transpose_lc_values_per_aid(lc_entries, aidvs_index, &lc_values_true_count); + List *per_aid_values = transpose_lc_values_per_aid(lc_entries, aid_index, &lc_values_true_count); distribute_lc_values(per_aid_values, lc_values_true_count); diff --git a/src/aggregation/lcf.c b/src/aggregation/lcf.c index f5fc60b5..66e381b1 100644 --- a/src/aggregation/lcf.c +++ b/src/aggregation/lcf.c @@ -29,13 +29,13 @@ Datum lcf_transfn(PG_FUNCTION_ARGS) Assert(PG_NARGS() == list_length(trackers) + LCF_AIDS_OFFSET); - ListCell *lc; - foreach (lc, trackers) + ListCell *cell; + foreach (cell, trackers) { - int aid_index = foreach_current_index(lc) + LCF_AIDS_OFFSET; + int aid_index = foreach_current_index(cell) + LCF_AIDS_OFFSET; if (!PG_ARGISNULL(aid_index)) { - AidTrackerState *tracker = (AidTrackerState *)lfirst(lc); + AidTrackerState *tracker = (AidTrackerState *)lfirst(cell); aid_t aid = tracker->aid_descriptor.make_aid(PG_GETARG_DATUM(aid_index)); aid_tracker_update(tracker, aid); } @@ -49,10 +49,10 @@ Datum lcf_finalfn(PG_FUNCTION_ARGS) bool passes_lcf = true; List *trackers = get_aggregate_aid_trackers(fcinfo, LCF_AIDS_OFFSET); - ListCell *lc; - foreach (lc, trackers) + ListCell *cell; + foreach (cell, trackers) { - AidTrackerState *tracker = (AidTrackerState *)lfirst(lc); + AidTrackerState *tracker = (AidTrackerState *)lfirst(cell); LcfResult result = lcf_calculate_final(tracker); passes_lcf = passes_lcf && result.passes_lcf; } @@ -84,13 +84,13 @@ Datum lcf_explain_finalfn(PG_FUNCTION_ARGS) List *trackers = get_aggregate_aid_trackers(fcinfo, LCF_AIDS_OFFSET); - ListCell *lc; - foreach (lc, trackers) + ListCell *cell; + foreach (cell, trackers) { - if (foreach_current_index(lc) > 0) + if (foreach_current_index(cell) > 0) appendStringInfo(&string, " \n"); - AidTrackerState *tracker = (AidTrackerState *)lfirst(lc); + AidTrackerState *tracker = (AidTrackerState *)lfirst(cell); append_tracker_info(&string, tracker); } diff --git a/src/query/relation.c b/src/query/relation.c index 8ecfd298..0fa468d8 100644 --- a/src/query/relation.c +++ b/src/query/relation.c @@ -43,10 +43,10 @@ static SensitiveRelation *create_sensitive_relation(Oid rel_oid, Oid namespace_o static bool has_relation(List *relations, Oid rel_oid) { - ListCell *lc; - foreach (lc, relations) + ListCell *cell; + foreach (cell, relations) { - SensitiveRelation *rel = (SensitiveRelation *)lfirst(lc); + SensitiveRelation *rel = (SensitiveRelation *)lfirst(cell); if (rel->oid == rel_oid) return true; } diff --git a/src/query/rewrite.c b/src/query/rewrite.c index 76d40259..7d5bb1a9 100644 --- a/src/query/rewrite.c +++ b/src/query/rewrite.c @@ -63,10 +63,10 @@ void rewrite_query(Query *query, List *sensitive_relations) static void group_implicit_buckets(Query *query) { - ListCell *lc = NULL; - foreach (lc, query->targetList) + ListCell *cell = NULL; + foreach (cell, query->targetList) { - TargetEntry *tle = lfirst_node(TargetEntry, lc); + TargetEntry *tle = lfirst_node(TargetEntry, cell); Oid type = exprType((const Node *)tle->expr); Assert(type != UNKNOWNOID); @@ -251,10 +251,10 @@ static TargetEntry *make_aid_target(AidReference *ref, AttrNumber resno, bool re static SensitiveRelation *find_relation(Oid rel_oid, List *relations) { - ListCell *lc; - foreach (lc, relations) + ListCell *cell; + foreach (cell, relations) { - SensitiveRelation *relation = (SensitiveRelation *)lfirst(lc); + SensitiveRelation *relation = (SensitiveRelation *)lfirst(cell); if (relation->oid == rel_oid) return relation; } @@ -271,10 +271,10 @@ static void gather_relation_aids( RangeTblEntry *rte, List **aid_references) { - ListCell *lc; - foreach (lc, relation->aid_columns) + ListCell *cell; + foreach (cell, relation->aid_columns) { - AidColumn *aid_col = (AidColumn *)lfirst(lc); + AidColumn *aid_col = (AidColumn *)lfirst(cell); AidReference *aid_ref = palloc(sizeof(AidReference)); aid_ref->relation = relation; @@ -302,10 +302,10 @@ static void gather_subquery_aids( Query *subquery = child_context->query; AttrNumber next_attnum = list_length(subquery->targetList) + 1; - ListCell *lc; - foreach (lc, child_context->aid_references) + ListCell *cell; + foreach (cell, child_context->aid_references) { - AidReference *child_aid_ref = (AidReference *)lfirst(lc); + AidReference *child_aid_ref = (AidReference *)lfirst(cell); /* Export AID from subquery */ AttrNumber attnum = next_attnum++; @@ -333,11 +333,11 @@ static QueryContext *build_context(Query *query, List *relations) List *aid_references = NIL; List *child_contexts = NIL; - ListCell *lc; - foreach (lc, query->rtable) + ListCell *cell; + foreach (cell, query->rtable) { - RangeTblEntry *rte = (RangeTblEntry *)lfirst(lc); - Index rte_index = foreach_current_index(lc) + 1; + RangeTblEntry *rte = (RangeTblEntry *)lfirst(cell); + Index rte_index = foreach_current_index(cell) + 1; if (rte->rtekind == RTE_RELATION) { @@ -364,10 +364,10 @@ static void append_aid_args(Aggref *aggref, QueryContext *context) { bool found_any = false; - ListCell *lc; - foreach (lc, context->aid_references) + ListCell *cell; + foreach (cell, context->aid_references) { - AidReference *aid_ref = (AidReference *)lfirst(lc); + AidReference *aid_ref = (AidReference *)lfirst(cell); TargetEntry *aid_entry = make_aid_target(aid_ref, list_length(aggref->args) + 1, false); /* Append the AID argument to function's arguments. */ diff --git a/src/query/validation.c b/src/query/validation.c index df66aa4a..1f28e55b 100644 --- a/src/query/validation.c +++ b/src/query/validation.c @@ -44,10 +44,10 @@ static void verify_subquery(Query *query) static void verify_rtable(Query *query) { - ListCell *lc = NULL; - foreach (lc, query->rtable) + ListCell *cell = NULL; + foreach (cell, query->rtable) { - RangeTblEntry *range_table = lfirst_node(RangeTblEntry, lc); + RangeTblEntry *range_table = lfirst_node(RangeTblEntry, cell); if (range_table->rtekind == RTE_SUBQUERY) verify_subquery(range_table->subquery); else if (range_table->rtekind != RTE_RELATION && range_table->rtekind != RTE_JOIN)