Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0ba3f3b

Browse files
committed
Comment improvements for abbreviated keys.
Peter Geoghegan and Robert Haas
1 parentccd8f97 commit0ba3f3b

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

‎src/backend/utils/sort/tuplesort.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,14 @@ tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation,
930930
state->sortKeys->ssup_collation=sortCollation;
931931
state->sortKeys->ssup_nulls_first=nullsFirstFlag;
932932

933-
/* abbreviation is possible here only for by-reference types */
933+
/*
934+
* Abbreviation is possible here only for by-reference types. In theory,
935+
* a pass-by-value datatype could have an abbreviated form that is cheaper
936+
* to compare. In a tuple sort, we could support that, because we can
937+
* always extract the original datum from the tuple is needed. Here, we
938+
* can't, because a datum sort only stores a single copy of the datum;
939+
* the "tuple" field of each sortTuple is NULL.
940+
*/
934941
state->sortKeys->abbreviate= !typbyval;
935942

936943
PrepareSortSupportFromOrderingOp(sortOperator,state->sortKeys);
@@ -1271,7 +1278,7 @@ tuplesort_putindextuplevalues(Tuplesortstate *state, Relation rel,
12711278
* Store ordinary Datum representation, or NULL value. If there is a
12721279
* converter it won't expect NULL values, and cost model is not
12731280
* required to account for NULL, so in that case we avoid calling
1274-
* converter and just set datum1 to"void" representation (to be
1281+
* converter and just set datum1 tozeroed representation (to be
12751282
* consistent).
12761283
*/
12771284
stup.datum1=original;
@@ -3155,7 +3162,7 @@ copytup_heap(Tuplesortstate *state, SortTuple *stup, void *tup)
31553162
* Store ordinary Datum representation, or NULL value. If there is a
31563163
* converter it won't expect NULL values, and cost model is not
31573164
* required to account for NULL, so in that case we avoid calling
3158-
* converter and just set datum1 to"void" representation (to be
3165+
* converter and just set datum1 tozeroed representation (to be
31593166
* consistent).
31603167
*/
31613168
stup->datum1=original;
@@ -3397,7 +3404,7 @@ copytup_cluster(Tuplesortstate *state, SortTuple *stup, void *tup)
33973404
* Store ordinary Datum representation, or NULL value. If there is a
33983405
* converter it won't expect NULL values, and cost model is not
33993406
* required to account for NULL, so in that case we avoid calling
3400-
* converter and just set datum1 to"void" representation (to be
3407+
* converter and just set datum1 tozeroed representation (to be
34013408
* consistent).
34023409
*/
34033410
stup->datum1=original;
@@ -3701,7 +3708,7 @@ copytup_index(Tuplesortstate *state, SortTuple *stup, void *tup)
37013708
* Store ordinary Datum representation, or NULL value. If there is a
37023709
* converter it won't expect NULL values, and cost model is not
37033710
* required to account for NULL, so in that case we avoid calling
3704-
* converter and just set datum1 to"void" representation (to be
3711+
* converter and just set datum1 tozeroed representation (to be
37053712
* consistent).
37063713
*/
37073714
stup->datum1=original;

‎src/include/utils/sortsupport.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,25 @@ typedef struct SortSupportData
116116
*
117117
* This allows opclass authors to supply a conversion routine, used to
118118
* create an alternative representation of the underlying type (an
119-
* "abbreviated key"). Typically, this representation is an ad-hoc,
120-
* pass-by-value Datum format that only the opclass has knowledge of. An
121-
* alternative comparator, used only with this alternative representation
122-
* must also be provided (which is assigned to "comparator"). This
123-
* representation is a simple approximation of the original Datum. It
124-
* must be possible to compare datums of this representation with each
125-
* other using the supplied alternative comparator, and have any non-zero
126-
* return value be a reliable proxy for what a proper comparison would
127-
* indicate. Returning zero from the alternative comparator does not
128-
* indicate equality, as with a conventional support routine 1, though --
129-
* it indicates that it wasn't possible to determine how the two
130-
* abbreviated values compared. A proper comparison, using
131-
* "abbrev_full_comparator"/ ApplySortAbbrevFullComparator() is therefore
132-
* required. In many cases this results in most or all comparisons only
133-
* using the cheap alternative comparison func, which is typically
134-
* implemented as code that compiles to just a few CPU instructions. CPU
135-
* cache miss penalties are expensive; to get good overall performance,
136-
* sort infrastructure must heavily weigh cache performance.
119+
* "abbreviated key"). This representation must be pass-by-value and
120+
* typically will use some ad-hoc format that only the opclass has
121+
* knowledge of. An alternative comparator, used only with this
122+
* alternative representation must also be provided (which is assigned to
123+
* "comparator"). This representation is a simple approximation of the
124+
* original Datum. It must be possible to compare datums of this
125+
* representation with each other using the supplied alternative
126+
* comparator, and have any non-zero return value be a reliable proxy for
127+
* what a proper comparison would indicate. Returning zero from the
128+
* alternative comparator does not indicate equality, as with a
129+
* conventional support routine 1, though -- it indicates that it wasn't
130+
* possible to determine how the two abbreviated values compared. A
131+
* proper comparison, using "abbrev_full_comparator"/
132+
* ApplySortAbbrevFullComparator() is therefore required. In many cases
133+
* this results in most or all comparisons only using the cheap
134+
* alternative comparison func, which is typically implemented as code
135+
* that compiles to just a few CPU instructions. CPU cache miss penalties
136+
* are expensive; to get good overall performance, sort infrastructure
137+
* must heavily weigh cache performance.
137138
*
138139
* Opclass authors must consider the final cardinality of abbreviated keys
139140
* when devising an encoding scheme. It's possible for a strategy to work

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp