Skip to content

Commit

Permalink
Fix assert in dimension slice lookup
Browse files Browse the repository at this point in the history
Calling ts_scan_iterator_next will advance internal scanner data
structures. It is therefore not safe to use the iterator after
ts_scan_iterator_next returned NULL and expect to be able to access
the previous tuple. Under certain circumstances this may point the
iterator to tuples not normally visible.
  • Loading branch information
svenklemm committed Sep 24, 2023
1 parent 8c41757 commit f332495
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/dimension_slice.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,13 +811,20 @@ ts_dimension_slice_scan_iterator_get_by_id(ScanIterator *it, int32 slice_id,
const ScanTupLock *tuplock)
{
TupleInfo *ti;
DimensionSlice *slice = NULL;

ts_dimension_slice_scan_iterator_set_slice_id(it, slice_id, tuplock);
ts_scan_iterator_start_or_restart_scan(it);
ti = ts_scan_iterator_next(it);
Assert(ti);
Assert(ts_scan_iterator_next(it) == NULL); /* This is a heavy call, consider removing it */
return ti ? ts_dimension_slice_from_tuple(ti) : NULL;

if (ti)
{
slice = ts_dimension_slice_from_tuple(ti);
Assert(ts_scan_iterator_next(it) == NULL);
}

return slice;
}

DimensionSlice *
Expand Down

0 comments on commit f332495

Please sign in to comment.