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

Commitc90c165

Browse files
committed
Fix some incorrect preprocessor tests in tuplesort specializations
6974924 added 3 new quicksort specialization functions for commondatatypes.That commit was not very consistent in how it would determine if we'recompiling for 32-bit or 64-bit machines. It would sometimes useUSE_FLOAT8_BYVAL and at other times check if SIZEOF_DATUM == 8. Thiscould cause theoretical problems due to the way USE_FLOAT8_BYVAL is nowdefined based on SIZEOF_VOID_P >= 8. If pointers for some reason wereever larger than 8-bytes then we'd end up doing 32-bit comparisonsmistakenly. Let's just always check SIZEOF_DATUM >= 8.It also seems that ssup_datum_signed_cmp is just never used on 32-bitbuilds, so let's just ifdef that out to make sure we never accidentallyuse that comparison function on such machines. This also allows us toifdef out 1 of the 3 new specialization quicksort functions in 32-bitbuilds which seems to shrink down the binary by over 4KB on my machine.In passing, also add the missing DatumGetInt32() / DatumGetInt64() macrosin the comparison functions.Discussion:https://postgr.es/m/CAApHDvqcQExRhtRa9hJrJB_5egs3SUfOcutP3m+3HO8A+fZTPA@mail.gmail.comReviewed-by: John Naylor
1 parentaff45c8 commitc90c165

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

‎src/backend/access/nbtree/nbtcompare.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ btint8cmp(PG_FUNCTION_ARGS)
142142
PG_RETURN_INT32(A_LESS_THAN_B);
143143
}
144144

145-
#ifndefUSE_FLOAT8_BYVAL
145+
#ifSIZEOF_DATUM<8
146146
staticint
147147
btint8fastcmp(Datumx,Datumy,SortSupportssup)
148148
{
@@ -163,7 +163,7 @@ btint8sortsupport(PG_FUNCTION_ARGS)
163163
{
164164
SortSupportssup= (SortSupport)PG_GETARG_POINTER(0);
165165

166-
#ifdefUSE_FLOAT8_BYVAL
166+
#ifSIZEOF_DATUM >=8
167167
ssup->comparator=ssup_datum_signed_cmp;
168168
#else
169169
ssup->comparator=btint8fastcmp;

‎src/backend/utils/adt/timestamp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,7 @@ timestamp_cmp(PG_FUNCTION_ARGS)
21762176
PG_RETURN_INT32(timestamp_cmp_internal(dt1,dt2));
21772177
}
21782178

2179-
#ifndefUSE_FLOAT8_BYVAL
2179+
#ifSIZEOF_DATUM<8
21802180
/* note: this is used for timestamptz also */
21812181
staticint
21822182
timestamp_fastcmp(Datumx,Datumy,SortSupportssup)
@@ -2193,7 +2193,7 @@ timestamp_sortsupport(PG_FUNCTION_ARGS)
21932193
{
21942194
SortSupportssup= (SortSupport)PG_GETARG_POINTER(0);
21952195

2196-
#ifdefUSE_FLOAT8_BYVAL
2196+
#ifSIZEOF_DATUM >=8
21972197
/*
21982198
* If this build has pass-by-value timestamps, then we can use a standard
21992199
* comparator function.

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ qsort_tuple_unsigned_compare(SortTuple *a, SortTuple *b, Tuplesortstate *state)
715715
returnstate->comparetup(a,b,state);
716716
}
717717

718+
#ifSIZEOF_DATUM >=8
718719
/* Used if first key's comparator is ssup_datum_signed_compare */
719720
staticpg_attribute_always_inlineint
720721
qsort_tuple_signed_compare(SortTuple*a,SortTuple*b,Tuplesortstate*state)
@@ -737,6 +738,7 @@ qsort_tuple_signed_compare(SortTuple *a, SortTuple *b, Tuplesortstate *state)
737738

738739
returnstate->comparetup(a,b,state);
739740
}
741+
#endif
740742

741743
/* Used if first key's comparator is ssup_datum_int32_compare */
742744
staticpg_attribute_always_inlineint
@@ -779,6 +781,7 @@ qsort_tuple_int32_compare(SortTuple *a, SortTuple *b, Tuplesortstate *state)
779781
#defineST_DEFINE
780782
#include"lib/sort_template.h"
781783

784+
#ifSIZEOF_DATUM >=8
782785
#defineST_SORT qsort_tuple_signed
783786
#defineST_ELEMENT_TYPE SortTuple
784787
#defineST_COMPARE(a,b,state) qsort_tuple_signed_compare(a, b, state)
@@ -787,6 +790,7 @@ qsort_tuple_int32_compare(SortTuple *a, SortTuple *b, Tuplesortstate *state)
787790
#defineST_SCOPE static
788791
#defineST_DEFINE
789792
#include"lib/sort_template.h"
793+
#endif
790794

791795
#defineST_SORT qsort_tuple_int32
792796
#defineST_ELEMENT_TYPE SortTuple
@@ -3666,6 +3670,7 @@ tuplesort_sort_memtuples(Tuplesortstate *state)
36663670
state);
36673671
return;
36683672
}
3673+
#ifSIZEOF_DATUM >=8
36693674
elseif (state->sortKeys[0].comparator==ssup_datum_signed_cmp)
36703675
{
36713676
elog(DEBUG1,"qsort_tuple_signed");
@@ -3674,6 +3679,7 @@ tuplesort_sort_memtuples(Tuplesortstate *state)
36743679
state);
36753680
return;
36763681
}
3682+
#endif
36773683
elseif (state->sortKeys[0].comparator==ssup_datum_int32_cmp)
36783684
{
36793685
elog(DEBUG1,"qsort_tuple_int32");
@@ -4905,16 +4911,12 @@ ssup_datum_unsigned_cmp(Datum x, Datum y, SortSupport ssup)
49054911
return0;
49064912
}
49074913

4914+
#ifSIZEOF_DATUM >=8
49084915
int
49094916
ssup_datum_signed_cmp(Datumx,Datumy,SortSupportssup)
49104917
{
4911-
#ifSIZEOF_DATUM==8
4912-
int64xx= (int64)x;
4913-
int64yy= (int64)y;
4914-
#else
4915-
int32xx= (int32)x;
4916-
int32yy= (int32)y;
4917-
#endif
4918+
int64xx=DatumGetInt64(x);
4919+
int64yy=DatumGetInt64(y);
49184920

49194921
if (xx<yy)
49204922
return-1;
@@ -4923,12 +4925,13 @@ ssup_datum_signed_cmp(Datum x, Datum y, SortSupport ssup)
49234925
else
49244926
return0;
49254927
}
4928+
#endif
49264929

49274930
int
49284931
ssup_datum_int32_cmp(Datumx,Datumy,SortSupportssup)
49294932
{
4930-
int32xx=(int32)x;
4931-
int32yy=(int32)y;
4933+
int32xx=DatumGetInt32(x);
4934+
int32yy=DatumGetInt32(y);
49324935

49334936
if (xx<yy)
49344937
return-1;

‎src/include/utils/sortsupport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ ApplySortAbbrevFullComparator(Datum datum1, bool isNull1,
379379
* are eligible for faster sorting.
380380
*/
381381
externintssup_datum_unsigned_cmp(Datumx,Datumy,SortSupportssup);
382+
#ifSIZEOF_DATUM >=8
382383
externintssup_datum_signed_cmp(Datumx,Datumy,SortSupportssup);
384+
#endif
383385
externintssup_datum_int32_cmp(Datumx,Datumy,SortSupportssup);
384386

385387
/* Other functions in utils/sort/sortsupport.c */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp