|
20 | 20 | #include <catalog/pg_operator.h> |
21 | 21 | #include <catalog/pg_type.h> |
22 | 22 | #include <commands/explain.h> |
23 | | -#include <commands/explain_format.h> |
24 | 23 | #include <executor/executor.h> |
25 | 24 | #include <executor/tuptable.h> |
26 | 25 | #include <nodes/bitmapset.h> |
|
48 | 47 | #include <utils/typcache.h> |
49 | 48 |
|
50 | 49 | #include "compat/compat.h" |
| 50 | +#if PG18_GE |
| 51 | +#include <commands/explain_format.h> |
| 52 | +#endif |
51 | 53 | #include "chunk.h" |
52 | 54 | #include "dimension.h" |
53 | 55 | #include "dimension_slice.h" |
@@ -814,41 +816,50 @@ deferred_chunk_scan_chunk_sql(DeferredChunkScanState *state, Oid reloid) |
814 | 816 | static Oid |
815 | 817 | next_chunk_reloid_ordered(DeferredChunkScanState *state) |
816 | 818 | { |
817 | | - StrategyNumber start_strategy = InvalidStrategy; |
818 | | - int64 start_value = 0; |
819 | | - if (state->have_last) |
| 819 | + /* A slice's chunk may have been dropped since the slice was read; skip such |
| 820 | + * slices and keep going so a mid-scan drop can't truncate the result. Only |
| 821 | + * return InvalidOid once the slices are exhausted. */ |
| 822 | + for (;;) |
820 | 823 | { |
821 | | - start_strategy = state->descending ? BTLessStrategyNumber : BTGreaterStrategyNumber; |
822 | | - start_value = state->last_range_start; |
823 | | - } |
| 824 | + StrategyNumber start_strategy = InvalidStrategy; |
| 825 | + int64 start_value = 0; |
| 826 | + if (state->have_last) |
| 827 | + { |
| 828 | + start_strategy = state->descending ? BTLessStrategyNumber : BTGreaterStrategyNumber; |
| 829 | + start_value = state->last_range_start; |
| 830 | + } |
824 | 831 |
|
825 | | - ScanIterator it = ts_dimension_slice_scan_iterator_create(NULL, CurrentMemoryContext); |
826 | | - ts_dimension_slice_scan_iterator_set_range(&it, |
827 | | - state->primary_dimension_id, |
828 | | - start_strategy, |
829 | | - start_value, |
830 | | - InvalidStrategy, |
831 | | - 0); |
832 | | - it.ctx.scandirection = state->descending ? BackwardScanDirection : ForwardScanDirection; |
833 | | - ts_scan_iterator_start_scan(&it); |
| 832 | + ScanIterator it = ts_dimension_slice_scan_iterator_create(NULL, CurrentMemoryContext); |
| 833 | + ts_dimension_slice_scan_iterator_set_range(&it, |
| 834 | + state->primary_dimension_id, |
| 835 | + start_strategy, |
| 836 | + start_value, |
| 837 | + InvalidStrategy, |
| 838 | + 0); |
| 839 | + it.ctx.scandirection = state->descending ? BackwardScanDirection : ForwardScanDirection; |
| 840 | + ts_scan_iterator_start_scan(&it); |
| 841 | + |
| 842 | + TupleInfo *ti = ts_scan_iterator_next(&it); |
| 843 | + if (ti == NULL) |
| 844 | + { |
| 845 | + ts_scan_iterator_close(&it); |
| 846 | + return InvalidOid; |
| 847 | + } |
834 | 848 |
|
835 | | - TupleInfo *ti = ts_scan_iterator_next(&it); |
836 | | - if (ti == NULL) |
837 | | - { |
| 849 | + bool isnull; |
| 850 | + int32 chunk_id = |
| 851 | + DatumGetInt32(slot_getattr(ti->slot, Anum_dimension_slice_chunk_id, &isnull)); |
| 852 | + state->last_range_start = |
| 853 | + DatumGetInt64(slot_getattr(ti->slot, Anum_dimension_slice_range_start, &isnull)); |
| 854 | + state->have_last = true; |
838 | 855 | ts_scan_iterator_close(&it); |
839 | | - return InvalidOid; |
840 | | - } |
841 | 856 |
|
842 | | - bool isnull; |
843 | | - int32 chunk_id = DatumGetInt32(slot_getattr(ti->slot, Anum_dimension_slice_chunk_id, &isnull)); |
844 | | - state->last_range_start = |
845 | | - DatumGetInt64(slot_getattr(ti->slot, Anum_dimension_slice_range_start, &isnull)); |
846 | | - state->have_last = true; |
847 | | - ts_scan_iterator_close(&it); |
848 | | - |
849 | | - /* The chunk may have been dropped since the slice was read; open_next_chunk |
850 | | - * skips an InvalidOid. */ |
851 | | - return ts_chunk_get_relid(chunk_id, /* missing_ok = */ true); |
| 857 | + Oid reloid = ts_chunk_get_relid(chunk_id, /* missing_ok = */ true); |
| 858 | + if (OidIsValid(reloid)) |
| 859 | + { |
| 860 | + return reloid; |
| 861 | + } |
| 862 | + } |
852 | 863 | } |
853 | 864 |
|
854 | 865 | /* |
|
0 commit comments