Skip to content

Commit 6e5d9f2

Browse files
committed
Avoid O(N^2) behavior when enlarging SPI tuple table in spi_printtup().
For no obvious reason, spi_printtup() was coded to enlarge the tuple pointer table by just 256 slots at a time, rather than doubling the size at each reallocation, as is our usual habit. For very large SPI results, this makes for O(N^2) time spent in repalloc(), which of course soon comes to dominate the runtime. Use the standard doubling approach instead. This is a longstanding performance bug, so back-patch to all active branches. Neil Conway
1 parent fcdfce6 commit 6e5d9f2

File tree

1 file changed

+2
-1
lines changed
  • src/backend/executor

1 file changed

+2
-1
lines changed

src/backend/executor/spi.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,8 @@ spi_printtup(TupleTableSlot *slot, DestReceiver *self)
17971797

17981798
if (tuptable->free == 0)
17991799
{
1800-
tuptable->free = 256;
1800+
/* Double the size of the pointer array */
1801+
tuptable->free = tuptable->alloced;
18011802
tuptable->alloced += tuptable->free;
18021803
tuptable->vals = (HeapTuple *) repalloc(tuptable->vals,
18031804
tuptable->alloced * sizeof(HeapTuple));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy