diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 08b646d..962fc7a 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -3087,7 +3087,7 @@ validate_index_heapscan(Relation heapRelation, } tuplesort_empty = !tuplesort_getdatum(state->tuplesort, true, - &ts_val, &ts_isnull, NULL); + &ts_val, &ts_isnull); Assert(tuplesort_empty || !ts_isnull); if (!tuplesort_empty) { diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index ce2fc28..89da5ae 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -586,8 +586,7 @@ fetch_input_tuple(AggState *aggstate) if (aggstate->sort_in) { - if (!tuplesort_gettupleslot(aggstate->sort_in, true, aggstate->sort_slot, - NULL)) + if (!tuplesort_gettupleslot(aggstate->sort_in, true, aggstate->sort_slot)) return NULL; slot = aggstate->sort_slot; } @@ -1124,8 +1123,6 @@ process_ordered_aggregate_single(AggState *aggstate, MemoryContext workcontext = aggstate->tmpcontext->ecxt_per_tuple_memory; MemoryContext oldContext; bool isDistinct = (pertrans->numDistinctCols > 0); - Datum newAbbrevVal = (Datum) 0; - Datum oldAbbrevVal = (Datum) 0; FunctionCallInfo fcinfo = &pertrans->transfn_fcinfo; Datum *newVal; bool *isNull; @@ -1145,7 +1142,7 @@ process_ordered_aggregate_single(AggState *aggstate, */ while (tuplesort_getdatum(pertrans->sortstates[aggstate->current_set], - true, newVal, isNull, &newAbbrevVal)) + true, newVal, isNull)) { /* * Clear and select the working context for evaluation of the equality @@ -1163,7 +1160,6 @@ process_ordered_aggregate_single(AggState *aggstate, haveOldVal && ((oldIsNull && *isNull) || (!oldIsNull && !*isNull && - oldAbbrevVal == newAbbrevVal && DatumGetBool(FunctionCall2(&pertrans->equalfns[0], oldVal, *newVal))))) { @@ -1179,7 +1175,6 @@ process_ordered_aggregate_single(AggState *aggstate, pfree(DatumGetPointer(oldVal)); /* and remember the new one for subsequent equality checks */ oldVal = *newVal; - oldAbbrevVal = newAbbrevVal; oldIsNull = *isNull; haveOldVal = true; } @@ -1217,8 +1212,6 @@ process_ordered_aggregate_multi(AggState *aggstate, TupleTableSlot *slot2 = pertrans->uniqslot; int numTransInputs = pertrans->numTransInputs; int numDistinctCols = pertrans->numDistinctCols; - Datum newAbbrevVal = (Datum) 0; - Datum oldAbbrevVal = (Datum) 0; bool haveOldValue = false; int i; @@ -1229,7 +1222,7 @@ process_ordered_aggregate_multi(AggState *aggstate, ExecClearTuple(slot2); while (tuplesort_gettupleslot(pertrans->sortstates[aggstate->current_set], - true, slot1, &newAbbrevVal)) + true, slot1)) { /* * Extract the first numTransInputs columns as datums to pass to the @@ -1240,7 +1233,6 @@ process_ordered_aggregate_multi(AggState *aggstate, if (numDistinctCols == 0 || !haveOldValue || - newAbbrevVal != oldAbbrevVal || !execTuplesMatch(slot1, slot2, numDistinctCols, pertrans->sortColIdx, @@ -1264,8 +1256,6 @@ process_ordered_aggregate_multi(AggState *aggstate, slot2 = slot1; slot1 = tmpslot; - /* avoid execTuplesMatch() calls by reusing abbreviated keys */ - oldAbbrevVal = newAbbrevVal; haveOldValue = true; } } diff --git a/src/backend/executor/nodeSort.c b/src/backend/executor/nodeSort.c index a34dcc5..102dbdf 100644 --- a/src/backend/executor/nodeSort.c +++ b/src/backend/executor/nodeSort.c @@ -137,7 +137,7 @@ ExecSort(SortState *node) slot = node->ss.ps.ps_ResultTupleSlot; (void) tuplesort_gettupleslot(tuplesortstate, ScanDirectionIsForward(dir), - slot, NULL); + slot); return slot; } diff --git a/src/backend/utils/adt/orderedsetaggs.c b/src/backend/utils/adt/orderedsetaggs.c index fe44d56..57201fd 100644 --- a/src/backend/utils/adt/orderedsetaggs.c +++ b/src/backend/utils/adt/orderedsetaggs.c @@ -453,7 +453,7 @@ percentile_disc_final(PG_FUNCTION_ARGS) elog(ERROR, "missing row in percentile_disc"); } - if (!tuplesort_getdatum(osastate->sortstate, true, &val, &isnull, NULL)) + if (!tuplesort_getdatum(osastate->sortstate, true, &val, &isnull)) elog(ERROR, "missing row in percentile_disc"); /* @@ -553,7 +553,7 @@ percentile_cont_final_common(FunctionCallInfo fcinfo, if (!tuplesort_skiptuples(osastate->sortstate, first_row, true)) elog(ERROR, "missing row in percentile_cont"); - if (!tuplesort_getdatum(osastate->sortstate, true, &first_val, &isnull, NULL)) + if (!tuplesort_getdatum(osastate->sortstate, true, &first_val, &isnull)) elog(ERROR, "missing row in percentile_cont"); if (isnull) PG_RETURN_NULL(); @@ -564,7 +564,7 @@ percentile_cont_final_common(FunctionCallInfo fcinfo, } else { - if (!tuplesort_getdatum(osastate->sortstate, true, &second_val, &isnull, NULL)) + if (!tuplesort_getdatum(osastate->sortstate, true, &second_val, &isnull)) elog(ERROR, "missing row in percentile_cont"); if (isnull) @@ -792,7 +792,7 @@ percentile_disc_multi_final(PG_FUNCTION_ARGS) if (!tuplesort_skiptuples(osastate->sortstate, target_row - rownum - 1, true)) elog(ERROR, "missing row in percentile_disc"); - if (!tuplesort_getdatum(osastate->sortstate, true, &val, &isnull, NULL)) + if (!tuplesort_getdatum(osastate->sortstate, true, &val, &isnull)) elog(ERROR, "missing row in percentile_disc"); rownum = target_row; @@ -921,8 +921,7 @@ percentile_cont_multi_final_common(FunctionCallInfo fcinfo, if (!tuplesort_skiptuples(osastate->sortstate, first_row - rownum - 1, true)) elog(ERROR, "missing row in percentile_cont"); - if (!tuplesort_getdatum(osastate->sortstate, true, &first_val, - &isnull, NULL) || isnull) + if (!tuplesort_getdatum(osastate->sortstate, true, &first_val, &isnull) || isnull) elog(ERROR, "missing row in percentile_cont"); rownum = first_row; @@ -942,8 +941,7 @@ percentile_cont_multi_final_common(FunctionCallInfo fcinfo, /* Fetch second_row if needed */ if (second_row > rownum) { - if (!tuplesort_getdatum(osastate->sortstate, true, &second_val, - &isnull, NULL) || isnull) + if (!tuplesort_getdatum(osastate->sortstate, true, &second_val, &isnull) || isnull) elog(ERROR, "missing row in percentile_cont"); rownum++; } @@ -1018,8 +1016,6 @@ mode_final(PG_FUNCTION_ARGS) int64 last_val_freq = 0; bool last_val_is_mode = false; FmgrInfo *equalfn; - Datum abbrev_val = (Datum) 0; - Datum last_abbrev_val = (Datum) 0; bool shouldfree; Assert(AggCheckCallContext(fcinfo, NULL) == AGG_CONTEXT_AGGREGATE); @@ -1046,7 +1042,7 @@ mode_final(PG_FUNCTION_ARGS) tuplesort_performsort(osastate->sortstate); /* Scan tuples and count frequencies */ - while (tuplesort_getdatum(osastate->sortstate, true, &val, &isnull, &abbrev_val)) + while (tuplesort_getdatum(osastate->sortstate, true, &val, &isnull)) { /* we don't expect any nulls, but ignore them if found */ if (isnull) @@ -1058,10 +1054,8 @@ mode_final(PG_FUNCTION_ARGS) mode_val = last_val = val; mode_freq = last_val_freq = 1; last_val_is_mode = true; - last_abbrev_val = abbrev_val; } - else if (abbrev_val == last_abbrev_val && - DatumGetBool(FunctionCall2(equalfn, val, last_val))) + else if (DatumGetBool(FunctionCall2(equalfn, val, last_val))) { /* value equal to previous value, count it */ if (last_val_is_mode) @@ -1084,8 +1078,6 @@ mode_final(PG_FUNCTION_ARGS) if (shouldfree && !last_val_is_mode) pfree(DatumGetPointer(last_val)); last_val = val; - /* avoid equality function calls by reusing abbreviated keys */ - last_abbrev_val = abbrev_val; last_val_freq = 1; last_val_is_mode = false; } @@ -1189,7 +1181,7 @@ hypothetical_rank_common(FunctionCallInfo fcinfo, int flag, tuplesort_performsort(osastate->sortstate); /* iterate till we find the hypothetical row */ - while (tuplesort_gettupleslot(osastate->sortstate, true, slot, NULL)) + while (tuplesort_gettupleslot(osastate->sortstate, true, slot)) { bool isnull; Datum d = slot_getattr(slot, nargs + 1, &isnull); @@ -1274,8 +1266,6 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS) int64 duplicate_count = 0; OSAPerGroupState *osastate; int numDistinctCols; - Datum abbrevVal = (Datum) 0; - Datum abbrevOld = (Datum) 0; AttrNumber *sortColIdx; FmgrInfo *equalfns; TupleTableSlot *slot; @@ -1352,7 +1342,7 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS) slot2 = extraslot; /* iterate till we find the hypothetical row */ - while (tuplesort_gettupleslot(osastate->sortstate, true, slot, &abbrevVal)) + while (tuplesort_gettupleslot(osastate->sortstate, true, slot)) { bool isnull; Datum d = slot_getattr(slot, nargs + 1, &isnull); @@ -1363,7 +1353,6 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS) /* count non-distinct tuples */ if (!TupIsNull(slot2) && - abbrevVal == abbrevOld && execTuplesMatch(slot, slot2, numDistinctCols, sortColIdx, @@ -1374,8 +1363,6 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS) tmpslot = slot2; slot2 = slot; slot = tmpslot; - /* avoid execTuplesMatch() calls by reusing abbreviated keys */ - abbrevOld = abbrevVal; rank++; diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index 16ceb30..6b29776 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -1406,8 +1406,7 @@ tuplesort_putindextuplevalues(Tuplesortstate *state, Relation rel, * converter it won't expect NULL values, and cost model is not * required to account for NULL, so in that case we avoid calling * converter and just set datum1 to zeroed representation (to be - * consistent, and to support cheap inequality tests for NULL - * abbreviated keys). + * consistent). */ stup.datum1 = original; } @@ -1475,11 +1474,7 @@ tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull) if (isNull || !state->tuples) { - /* - * Set datum1 to zeroed representation for NULLs (to be consistent, - * and to support cheap inequality tests for NULL abbreviated keys). - */ - stup.datum1 = !isNull ? val : (Datum) 0; + stup.datum1 = val; stup.isnull1 = isNull; stup.tuple = NULL; /* no separate storage */ MemoryContextSwitchTo(state->sortcontext); @@ -2047,17 +2042,10 @@ tuplesort_gettuple_common(Tuplesortstate *state, bool forward, * Fetch the next tuple in either forward or back direction. * If successful, put tuple in slot and return TRUE; else, clear the slot * and return FALSE. - * - * Caller may optionally be passed back abbreviated value (on TRUE return - * value) when abbreviation was used, which can be used to cheaply avoid - * equality checks that might otherwise be required. Caller can safely make a - * determination of "non-equal tuple" based on simple binary inequality. A - * NULL value in leading attribute will set abbreviated value to zeroed - * representation, which caller may rely on in abbreviated inequality check. */ bool tuplesort_gettupleslot(Tuplesortstate *state, bool forward, - TupleTableSlot *slot, Datum *abbrev) + TupleTableSlot *slot) { MemoryContext oldcontext = MemoryContextSwitchTo(state->sortcontext); SortTuple stup; @@ -2070,10 +2058,6 @@ tuplesort_gettupleslot(Tuplesortstate *state, bool forward, if (stup.tuple) { - /* Record abbreviated key for caller */ - if (state->sortKeys->abbrev_converter && abbrev) - *abbrev = stup.datum1; - ExecStoreMinimalTuple((MinimalTuple) stup.tuple, slot, should_free); return true; } @@ -2133,17 +2117,10 @@ tuplesort_getindextuple(Tuplesortstate *state, bool forward, * * If the Datum is pass-by-ref type, the returned value is freshly palloc'd * and is now owned by the caller. - * - * Caller may optionally be passed back abbreviated value (on TRUE return - * value) when abbreviation was used, which can be used to cheaply avoid - * equality checks that might otherwise be required. Caller can safely make a - * determination of "non-equal tuple" based on simple binary inequality. A - * NULL value will have a zeroed abbreviated value representation, which caller - * may rely on in abbreviated inequality check. */ bool tuplesort_getdatum(Tuplesortstate *state, bool forward, - Datum *val, bool *isNull, Datum *abbrev) + Datum *val, bool *isNull) { MemoryContext oldcontext = MemoryContextSwitchTo(state->sortcontext); SortTuple stup; @@ -2155,10 +2132,6 @@ tuplesort_getdatum(Tuplesortstate *state, bool forward, return false; } - /* Record abbreviated key for caller */ - if (state->sortKeys->abbrev_converter && abbrev) - *abbrev = stup.datum1; - if (stup.isnull1 || !state->tuples) { *val = stup.datum1; @@ -4037,8 +4010,7 @@ copytup_heap(Tuplesortstate *state, SortTuple *stup, void *tup) * converter it won't expect NULL values, and cost model is not * required to account for NULL, so in that case we avoid calling * converter and just set datum1 to zeroed representation (to be - * consistent, and to support cheap inequality tests for NULL - * abbreviated keys). + * consistent). */ stup->datum1 = original; } @@ -4287,8 +4259,7 @@ copytup_cluster(Tuplesortstate *state, SortTuple *stup, void *tup) * converter it won't expect NULL values, and cost model is not * required to account for NULL, so in that case we avoid calling * converter and just set datum1 to zeroed representation (to be - * consistent, and to support cheap inequality tests for NULL - * abbreviated keys). + * consistent). */ stup->datum1 = original; } diff --git a/src/include/utils/tuplesort.h b/src/include/utils/tuplesort.h index 5cecd6d..d31d9945 100644 --- a/src/include/utils/tuplesort.h +++ b/src/include/utils/tuplesort.h @@ -93,13 +93,13 @@ extern void tuplesort_putdatum(Tuplesortstate *state, Datum val, extern void tuplesort_performsort(Tuplesortstate *state); extern bool tuplesort_gettupleslot(Tuplesortstate *state, bool forward, - TupleTableSlot *slot, Datum *abbrev); + TupleTableSlot *slot); extern HeapTuple tuplesort_getheaptuple(Tuplesortstate *state, bool forward, bool *should_free); extern IndexTuple tuplesort_getindextuple(Tuplesortstate *state, bool forward, bool *should_free); extern bool tuplesort_getdatum(Tuplesortstate *state, bool forward, - Datum *val, bool *isNull, Datum *abbrev); + Datum *val, bool *isNull); extern bool tuplesort_skiptuples(Tuplesortstate *state, int64 ntuples, bool forward);