Skip to content

Commit fe939d9

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 22b9ce7 commit fe939d9

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
@@ -1769,7 +1769,8 @@ spi_printtup(TupleTableSlot *slot, DestReceiver *self)
17691769

17701770
if (tuptable->free == 0)
17711771
{
1772-
tuptable->free = 256;
1772+
/* Double the size of the pointer array */
1773+
tuptable->free = tuptable->alloced;
17731774
tuptable->alloced += tuptable->free;
17741775
tuptable->vals = (HeapTuple *) repalloc(tuptable->vals,
17751776
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