Skip to content

Commit 6ee3b5f

Browse files
committed
Use int64 instead of long in incremental sort code
Windows 64bit has 4-byte long values which is not suitable for tracking disk space usage in the incremental sort code. Let's just make all these fields int64s. Author: James Coleman Discussion: https://postgr.es/m/CAApHDvpky%2BUhof8mryPf5i%3D6e6fib2dxHqBrhp0Qhu0NeBhLJw%40mail.gmail.com Backpatch-through: 13, where the incremental sort code was added
1 parent cd5e822 commit 6ee3b5f

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/backend/commands/explain.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2676,7 +2676,7 @@ show_sort_info(SortState *sortstate, ExplainState *es)
26762676
TuplesortInstrumentation stats;
26772677
const char *sortMethod;
26782678
const char *spaceType;
2679-
long spaceUsed;
2679+
int64 spaceUsed;
26802680

26812681
tuplesort_get_stats(state, &stats);
26822682
sortMethod = tuplesort_method_name(stats.sortMethod);
@@ -2686,7 +2686,7 @@ show_sort_info(SortState *sortstate, ExplainState *es)
26862686
if (es->format == EXPLAIN_FORMAT_TEXT)
26872687
{
26882688
ExplainIndentText(es);
2689-
appendStringInfo(es->str, "Sort Method: %s %s: %ldkB\n",
2689+
appendStringInfo(es->str, "Sort Method: %s %s: " INT64_FORMAT "kB\n",
26902690
sortMethod, spaceType, spaceUsed);
26912691
}
26922692
else
@@ -2715,7 +2715,7 @@ show_sort_info(SortState *sortstate, ExplainState *es)
27152715
TuplesortInstrumentation *sinstrument;
27162716
const char *sortMethod;
27172717
const char *spaceType;
2718-
long spaceUsed;
2718+
int64 spaceUsed;
27192719

27202720
sinstrument = &sortstate->shared_info->sinstrument[n];
27212721
if (sinstrument->sortMethod == SORT_TYPE_STILL_IN_PROGRESS)
@@ -2731,7 +2731,7 @@ show_sort_info(SortState *sortstate, ExplainState *es)
27312731
{
27322732
ExplainIndentText(es);
27332733
appendStringInfo(es->str,
2734-
"Sort Method: %s %s: %ldkB\n",
2734+
"Sort Method: %s %s: " INT64_FORMAT "kB\n",
27352735
sortMethod, spaceType, spaceUsed);
27362736
}
27372737
else
@@ -2795,23 +2795,23 @@ show_incremental_sort_group_info(IncrementalSortGroupInfo *groupInfo,
27952795

27962796
if (groupInfo->maxMemorySpaceUsed > 0)
27972797
{
2798-
long avgSpace = groupInfo->totalMemorySpaceUsed / groupInfo->groupCount;
2798+
int64 avgSpace = groupInfo->totalMemorySpaceUsed / groupInfo->groupCount;
27992799
const char *spaceTypeName;
28002800

28012801
spaceTypeName = tuplesort_space_type_name(SORT_SPACE_TYPE_MEMORY);
2802-
appendStringInfo(es->str, " Average %s: %ldkB Peak %s: %ldkB",
2802+
appendStringInfo(es->str, " Average %s: " INT64_FORMAT "kB Peak %s: " INT64_FORMAT "kB",
28032803
spaceTypeName, avgSpace,
28042804
spaceTypeName, groupInfo->maxMemorySpaceUsed);
28052805
}
28062806

28072807
if (groupInfo->maxDiskSpaceUsed > 0)
28082808
{
2809-
long avgSpace = groupInfo->totalDiskSpaceUsed / groupInfo->groupCount;
2809+
int64 avgSpace = groupInfo->totalDiskSpaceUsed / groupInfo->groupCount;
28102810

28112811
const char *spaceTypeName;
28122812

28132813
spaceTypeName = tuplesort_space_type_name(SORT_SPACE_TYPE_DISK);
2814-
appendStringInfo(es->str, " Average %s: %ldkB Peak %s: %ldkB",
2814+
appendStringInfo(es->str, " Average %s: " INT64_FORMAT "kB Peak %s: " INT64_FORMAT "kB",
28152815
spaceTypeName, avgSpace,
28162816
spaceTypeName, groupInfo->maxDiskSpaceUsed);
28172817
}
@@ -2829,7 +2829,7 @@ show_incremental_sort_group_info(IncrementalSortGroupInfo *groupInfo,
28292829

28302830
if (groupInfo->maxMemorySpaceUsed > 0)
28312831
{
2832-
long avgSpace = groupInfo->totalMemorySpaceUsed / groupInfo->groupCount;
2832+
int64 avgSpace = groupInfo->totalMemorySpaceUsed / groupInfo->groupCount;
28332833
const char *spaceTypeName;
28342834
StringInfoData memoryName;
28352835

@@ -2846,7 +2846,7 @@ show_incremental_sort_group_info(IncrementalSortGroupInfo *groupInfo,
28462846
}
28472847
if (groupInfo->maxDiskSpaceUsed > 0)
28482848
{
2849-
long avgSpace = groupInfo->totalDiskSpaceUsed / groupInfo->groupCount;
2849+
int64 avgSpace = groupInfo->totalDiskSpaceUsed / groupInfo->groupCount;
28502850
const char *spaceTypeName;
28512851
StringInfoData diskName;
28522852

src/include/nodes/execnodes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,10 +2032,10 @@ typedef struct SortState
20322032
typedef struct IncrementalSortGroupInfo
20332033
{
20342034
int64 groupCount;
2035-
long maxDiskSpaceUsed;
2036-
long totalDiskSpaceUsed;
2037-
long maxMemorySpaceUsed;
2038-
long totalMemorySpaceUsed;
2035+
int64 maxDiskSpaceUsed;
2036+
int64 totalDiskSpaceUsed;
2037+
int64 maxMemorySpaceUsed;
2038+
int64 totalMemorySpaceUsed;
20392039
bits32 sortMethods; /* bitmask of TuplesortMethod */
20402040
} IncrementalSortGroupInfo;
20412041

src/include/utils/tuplesort.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ typedef struct TuplesortInstrumentation
9090
{
9191
TuplesortMethod sortMethod; /* sort algorithm used */
9292
TuplesortSpaceType spaceType; /* type of space spaceUsed represents */
93-
long spaceUsed; /* space consumption, in kB */
93+
int64 spaceUsed; /* space consumption, in kB */
9494
} TuplesortInstrumentation;
9595

9696

0 commit comments

Comments
 (0)