Skip to content

Commit 8114a67

Browse files
committed
prevent extra-copy of RumSortItem
1 parent d29c6b9 commit 8114a67

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

rumget.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,7 +2216,9 @@ insertScanItem(RumScanOpaque so, bool recheck)
22162216
RumSortItem *item;
22172217
int i, j;
22182218

2219-
item = (RumSortItem *)palloc(RumSortItemSize(so->norderbys));
2219+
item = (RumSortItem *)
2220+
MemoryContextAlloc(rum_tuplesort_get_memorycontext(so->sortstate),
2221+
RumSortItemSize(so->norderbys));
22202222
item->iptr = so->iptr;
22212223
item->recheck = recheck;
22222224

@@ -2264,7 +2266,6 @@ insertScanItem(RumScanOpaque so, bool recheck)
22642266
j++;
22652267
}
22662268
rum_tuplesort_putrum(so->sortstate, item);
2267-
pfree(item);
22682269
}
22692270

22702271
bool

rumsort.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,12 @@ rum_tuplesort_begin_common(int workMem, bool randomAccess)
911911
return state;
912912
}
913913

914+
MemoryContext
915+
rum_tuplesort_get_memorycontext(Tuplesortstate *state)
916+
{
917+
return state->sortcontext;
918+
}
919+
914920
Tuplesortstate *
915921
rum_tuplesort_begin_heap(TupleDesc tupDesc,
916922
int nkeys, AttrNumber *attNums,
@@ -1536,15 +1542,12 @@ rum_tuplesort_putrum(Tuplesortstate *state, RumSortItem *item)
15361542
{
15371543
MemoryContext oldcontext = MemoryContextSwitchTo(state->sortcontext);
15381544
SortTuple stup;
1539-
RumSortItem *itemCopy = palloc(RumSortItemSize(state->nKeys));
1540-
1541-
memcpy(itemCopy, item, RumSortItemSize(state->nKeys));
15421545

15431546
/*
15441547
* Copy the given tuple into memory we control, and decrease availMem.
15451548
* Then call the common code.
15461549
*/
1547-
COPYTUP(state, &stup, (void *) itemCopy);
1550+
COPYTUP(state, &stup, (void *) item);
15481551

15491552
puttuple_common(state, &stup);
15501553

rumsort.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ typedef struct
6767

6868
#define RumSortItemSize(nKeys) (offsetof(RumSortItem,data)+(nKeys)*sizeof(float8))
6969

70+
extern MemoryContext rum_tuplesort_get_memorycontext(Tuplesortstate *state);
7071
extern Tuplesortstate *rum_tuplesort_begin_heap(TupleDesc tupDesc,
7172
int nkeys, AttrNumber *attNums,
7273
Oid *sortOperators, Oid *sortCollations,

0 commit comments

Comments
 (0)