Skip to content

Commit

Permalink
Add debug output for running no_gaps numeric test
Browse files Browse the repository at this point in the history
The tests don't pass, and I need to see the state during execution
to find the bug in no_gaps.
  • Loading branch information
jhf committed Nov 7, 2023
1 parent 60d73f3 commit 78bf5d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
21 changes: 15 additions & 6 deletions no_gaps.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ 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);
state->covered_to.infinite = true;
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);
Expand Down Expand Up @@ -142,8 +142,8 @@ Datum no_gaps_transfn(PG_FUNCTION_ARGS)

range_deserialize(typcache, current_range, &current_start, &current_end, &current_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
Expand Down Expand Up @@ -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, &current_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;
}

Expand All @@ -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);
}

Expand Down
3 changes: 3 additions & 0 deletions sql/33_no_gaps_numeric_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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');
Expand Down

0 comments on commit 78bf5d6

Please sign in to comment.