Skip to content

Commit f605204

Browse files
authored
Merge pull request #395 from diffix/edon/refactor
Simplify noise dummy aggs
2 parents fabba24 + 28638f4 commit f605204

File tree

2 files changed

+35
-78
lines changed

2 files changed

+35
-78
lines changed

pg_diffix--1.0.0.sql

Lines changed: 35 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@ DO $$ BEGIN
1111
EXECUTE 'ALTER DATABASE ' || current_database() || ' SET pg_diffix.salt TO ''' || gen_random_uuid() || '''';
1212
END $$ LANGUAGE plpgsql;
1313

14+
/* ----------------------------------------------------------------
15+
* Internal functions
16+
* ----------------------------------------------------------------
17+
*/
18+
19+
CREATE FUNCTION placeholder_func(anyelement)
20+
RETURNS anyelement
21+
AS 'MODULE_PATHNAME'
22+
LANGUAGE C IMMUTABLE STRICT
23+
SECURITY INVOKER SET search_path = '';
24+
25+
CREATE FUNCTION placeholder_func(anyelement, "any")
26+
RETURNS anyelement
27+
AS 'MODULE_PATHNAME'
28+
LANGUAGE C IMMUTABLE STRICT
29+
SECURITY INVOKER SET search_path = '';
30+
31+
CREATE FUNCTION internal_qual_wrapper(boolean)
32+
RETURNS boolean
33+
AS 'MODULE_PATHNAME'
34+
LANGUAGE C VOLATILE
35+
SECURITY INVOKER SET search_path = '';
36+
1437
/* ----------------------------------------------------------------
1538
* Utilities
1639
* ----------------------------------------------------------------
@@ -159,71 +182,33 @@ AS 'MODULE_PATHNAME'
159182
LANGUAGE C STABLE
160183
SECURITY INVOKER SET search_path = '';
161184

162-
163185
/* ----------------------------------------------------------------
164186
* Non-anonymizing aggregators
165187
* ----------------------------------------------------------------
166188
*/
167189

168-
/*
169-
* Present here only to provide the proper signatures for the aggregators available
170-
* to the non-direct access users.
171-
*/
172-
173-
CREATE FUNCTION dummy_agg_noise_transfn(AnonAggState)
174-
RETURNS AnonAggState
175-
AS 'MODULE_PATHNAME'
176-
LANGUAGE C STABLE
177-
SECURITY INVOKER SET search_path = '';
178-
179-
CREATE FUNCTION dummy_agg_noise_transfn(AnonAggState, value "any")
180-
RETURNS AnonAggState
181-
AS 'MODULE_PATHNAME'
182-
LANGUAGE C STABLE
183-
SECURITY INVOKER SET search_path = '';
184-
185-
CREATE FUNCTION dummy_agg_noise_finalfn(AnonAggState)
186-
RETURNS float8
187-
AS 'MODULE_PATHNAME'
188-
LANGUAGE C STABLE
189-
SECURITY INVOKER SET search_path = '';
190-
191-
CREATE FUNCTION dummy_agg_noise_finalfn(AnonAggState, value "any")
192-
RETURNS float8
193-
AS 'MODULE_PATHNAME'
194-
LANGUAGE C STABLE
195-
SECURITY INVOKER SET search_path = '';
196-
197190
CREATE AGGREGATE count_noise(*) (
198-
sfunc = dummy_agg_noise_transfn,
199-
stype = AnonAggState,
200-
finalfunc = dummy_agg_noise_finalfn,
201-
finalfunc_extra = true,
202-
finalfunc_modify = read_write
191+
sfunc = placeholder_func,
192+
stype = float8,
193+
initcond = 0.0
203194
);
204195

205196
CREATE AGGREGATE count_noise(value "any") (
206-
sfunc = dummy_agg_noise_transfn,
207-
stype = AnonAggState,
208-
finalfunc = dummy_agg_noise_finalfn,
209-
finalfunc_extra = true,
210-
finalfunc_modify = read_write
197+
sfunc = placeholder_func,
198+
stype = float8,
199+
initcond = 0.0
211200
);
212201

213202
CREATE AGGREGATE sum_noise(value "any") (
214-
sfunc = dummy_agg_noise_transfn,
215-
stype = AnonAggState,
216-
finalfunc = dummy_agg_noise_finalfn,
217-
finalfunc_extra = true,
218-
finalfunc_modify = read_write
203+
sfunc = placeholder_func,
204+
stype = float8,
205+
initcond = 0.0
219206
);
220207

221208
CREATE AGGREGATE avg_noise(value "any") (
222-
sfunc = dummy_agg_noise_transfn,
223-
stype = AnonAggState,
224-
finalfunc = dummy_agg_noise_finalfn,
225-
finalfunc_extra = true,
226-
finalfunc_modify = read_write
209+
sfunc = placeholder_func,
210+
stype = float8,
211+
initcond = 0.0
227212
);
228213

229214
/* ----------------------------------------------------------------
@@ -314,24 +299,12 @@ CREATE AGGREGATE anon_sum_noise(value "any", variadic aids "any") (
314299
* ----------------------------------------------------------------
315300
*/
316301

317-
CREATE FUNCTION placeholder_func(anyelement)
318-
RETURNS anyelement
319-
AS 'MODULE_PATHNAME'
320-
LANGUAGE C IMMUTABLE STRICT
321-
SECURITY INVOKER SET search_path = '';
322-
323302
CREATE AGGREGATE is_suppress_bin(*) (
324303
sfunc = placeholder_func,
325304
stype = boolean,
326305
initcond = false
327306
);
328307

329-
CREATE FUNCTION internal_qual_wrapper(boolean)
330-
RETURNS boolean
331-
AS 'MODULE_PATHNAME'
332-
LANGUAGE C VOLATILE
333-
SECURITY INVOKER SET search_path = '';
334-
335308
/* ----------------------------------------------------------------
336309
* Scalar functions
337310
* ----------------------------------------------------------------

src/aggregation/common.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ PG_FUNCTION_INFO_V1(anon_agg_state_input);
2121
PG_FUNCTION_INFO_V1(anon_agg_state_output);
2222
PG_FUNCTION_INFO_V1(anon_agg_state_transfn);
2323
PG_FUNCTION_INFO_V1(anon_agg_state_finalfn);
24-
PG_FUNCTION_INFO_V1(dummy_agg_noise_transfn);
25-
PG_FUNCTION_INFO_V1(dummy_agg_noise_finalfn);
2624

2725
const AnonAggFuncs *find_agg_funcs(Oid oid)
2826
{
@@ -144,20 +142,6 @@ Datum anon_agg_state_finalfn(PG_FUNCTION_ARGS)
144142
PG_RETURN_AGG_STATE(state);
145143
}
146144

147-
/*
148-
* These functions should never be called except in `direct` access level. Non-anonymized `_noise` aggregators are to be
149-
* always rewritten to their anonymized versions. In `direct`, they return the true result: 0.0 noise.
150-
*/
151-
Datum dummy_agg_noise_transfn(PG_FUNCTION_ARGS)
152-
{
153-
PG_RETURN_AGG_STATE(0);
154-
}
155-
156-
Datum dummy_agg_noise_finalfn(PG_FUNCTION_ARGS)
157-
{
158-
PG_RETURN_AGG_STATE(0);
159-
}
160-
161145
bool all_aids_null(NullableDatum *args, int aids_offset, int aids_count)
162146
{
163147
for (int aid_index = aids_offset; aid_index < aids_offset + aids_count; aid_index++)

0 commit comments

Comments
 (0)