From 78bf5d611f34fc1fb8daa0861eeb518ee7a198d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20H=2E=20Fjeld?= Date: Tue, 7 Nov 2023 15:53:38 +0100 Subject: [PATCH] Add debug output for running no_gaps numeric test The tests don't pass, and I need to see the state during execution to find the bug in no_gaps. --- no_gaps.c | 21 +++++++++++++++------ sql/33_no_gaps_numeric_test.sql | 3 +++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/no_gaps.c b/no_gaps.c index 59253bf..a3d99ca 100644 --- a/no_gaps.c +++ b/no_gaps.c @@ -104,7 +104,7 @@ Datum no_gaps_transfn(PG_FUNCTION_ARGS) typcache = range_get_typcache(fcinfo, RangeTypeGetOid(state->target)); range_deserialize(typcache, state->target, &state->target_start, &state->target_end, &state->target_empty); - //ereport(NOTICE, (errmsg("target is [%ld, %ld)", DatumGet(typcache, state->target_start), DatumGet(typcache, state->target_end)))); + ereport(DEBUG1, (errmsg("target is [%ld, %ld)", DatumGet(typcache, state->target_start), DatumGet(typcache, state->target_end)))); // Initialize covered_to to negative infinity bound state->covered_to.val = DatumNegativeInfinity(typcache); @@ -112,7 +112,7 @@ Datum no_gaps_transfn(PG_FUNCTION_ARGS) state->covered_to.inclusive = true; state->covered_to.lower = true; - //ereport(NOTICE, (errmsg("initial covered_to is %ld", DatumGet(typcache, state->covered_to)))); + ereport(DEBUG1, (errmsg("initial covered_to is %ld", DatumGet(typcache, state->covered_to)))); } else { // ereport(NOTICE, (errmsg("looking up state...."))); state = (no_gaps_state *)PG_GETARG_POINTER(0); @@ -142,8 +142,8 @@ Datum no_gaps_transfn(PG_FUNCTION_ARGS) range_deserialize(typcache, current_range, ¤t_start, ¤t_end, ¤t_empty); - //ereport(NOTICE, (errmsg("current is [%ld, %ld)", DatumGet(typcache, current_start), DatumGet(typcache, current_end)))); - //ereport(NOTICE, (errmsg("pre state->covered_to is %ld", DatumGet(typcache, state->covered_to)))); + ereport(DEBUG1, (errmsg("current is [%ld, %ld)", DatumGet(typcache, current_start), DatumGet(typcache, current_end)))); + ereport(DEBUG1, (errmsg("pre state->covered_to is %ld", DatumGet(typcache, state->covered_to)))); if (first_time) { // If the target range start is unbounded, but the current range start is not, then we cannot have full coverage @@ -182,7 +182,16 @@ Datum no_gaps_transfn(PG_FUNCTION_ARGS) // Update the covered range if the current range extends beyond it if (range_cmp_bounds(typcache, ¤t_end, &state->covered_to) > 0) { state->covered_to = current_end; - // Notice that the previous non inclusive end is included in the next start. + + //if (!typcache->typbyval && typcache->typlen == -1) { + // Size datumSize = VARSIZE_ANY(DatumGetPointer(current_end.val)); + // MemoryContext oldContext = MemoryContextSwitchTo(aggContext); + // state->covered_to.val = PointerGetDatum(palloc(datumSize)); + // memcpy(DatumGetPointer(state->covered_to.val), DatumGetPointer(current_end.val), datumSize); + // MemoryContextSwitchTo(oldContext); + //} + + // Notice that the previous non-inclusive end is included in the next start. state->covered_to.inclusive = true; } @@ -191,7 +200,7 @@ Datum no_gaps_transfn(PG_FUNCTION_ARGS) state->no_gaps = true; state->finished = true; } - //ereport(NOTICE, (errmsg("post state->covered_to is %ld", DatumGet(typcache, state->covered_to)))); + ereport(DEBUG1, (errmsg("post state->covered_to is %ld", DatumGet(typcache, state->covered_to)))); PG_RETURN_POINTER(state); } diff --git a/sql/33_no_gaps_numeric_test.sql b/sql/33_no_gaps_numeric_test.sql index 902c7d4..fca5e60 100644 --- a/sql/33_no_gaps_numeric_test.sql +++ b/sql/33_no_gaps_numeric_test.sql @@ -20,6 +20,8 @@ INSERT INTO numeric_shifts(job_id, worker_id, valid_from, valid_to) VALUES TABLE numeric_shifts; +SET client_min_messages TO DEBUG1; + -- This test checks for an exact match with one range -- Expected: TRUE SELECT sql_saga.no_gaps(numrange(valid_from, valid_to), numrange(1.5, 6.5)) @@ -68,6 +70,7 @@ SELECT sql_saga.no_gaps(numrange(valid_from, valid_to), numrange(1.5, 15.5)) FROM numeric_shifts WHERE job_id = 1; +SET client_min_messages TO NOTICE; SELECT sql_saga.drop_unique_key('numeric_shifts', 'numeric_shifts_job_id_worker_id_valid'); SELECT sql_saga.drop_era('numeric_shifts');