Skip to content

Commit 60555bd

Browse files
committed
Please, apply attached patch of contrib/btree_gist to 7.2.1 and current cvs. The patch fixes memory leak during creation GiST index on timestamp column. Thank you. -- Teodor Sigaev teodor@stack.net
1 parent 4633ee2 commit 60555bd

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

contrib/btree_gist/btree_gist.c

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ Datum gts_same(PG_FUNCTION_ARGS);
8686
static void gts_binary_union(Datum *r1, char *r2);
8787
static int tskey_cmp(const void *a, const void *b);
8888

89+
#define TimestampGetDatumFast(X) Float8GetDatumFast(X)
90+
8991
/* define for comparison */
9092
#define TSGE( ts1, ts2 ) (DatumGetBool(DirectFunctionCall2( \
9193
timestamp_ge, \
@@ -297,23 +299,11 @@ gts_compress(PG_FUNCTION_ARGS)
297299
if (entry->leafkey)
298300
{
299301
TSKEY *r = (TSKEY *) palloc(sizeof(TSKEY));
300-
301302
retval = palloc(sizeof(GISTENTRY));
302-
if (entry->key)
303-
{
304-
r->lower = r->upper = *(Timestamp *) (entry->key);
305-
306-
gistentryinit(*retval, PointerGetDatum(r),
307-
entry->rel, entry->page,
308-
entry->offset, sizeof(TSKEY), FALSE);
309-
310-
}
311-
else
312-
{
313-
gistentryinit(*retval, PointerGetDatum(NULL),
314-
entry->rel, entry->page,
315-
entry->offset, 0, FALSE);
316-
}
303+
r->lower = r->upper = *(Timestamp *) (entry->key);
304+
gistentryinit(*retval, PointerGetDatum(r),
305+
entry->rel, entry->page,
306+
entry->offset, sizeof(TSKEY), FALSE);
317307
}
318308
else
319309
retval = entry;
@@ -408,17 +398,17 @@ gts_penalty(PG_FUNCTION_ARGS)
408398

409399
intr = DatumGetIntervalP(DirectFunctionCall2(
410400
timestamp_mi,
411-
TimestampGetDatum(newentry->upper),
412-
TimestampGetDatum(origentry->upper)));
401+
TimestampGetDatumFast(newentry->upper),
402+
TimestampGetDatumFast(origentry->upper)));
413403

414404
/* see interval_larger */
415405
*result = Max(intr->time + intr->month * (30.0 * 86400), 0);
416406
pfree(intr);
417407

418408
intr = DatumGetIntervalP(DirectFunctionCall2(
419409
timestamp_mi,
420-
TimestampGetDatum(origentry->lower),
421-
TimestampGetDatum(newentry->lower)));
410+
TimestampGetDatumFast(origentry->lower),
411+
TimestampGetDatumFast(newentry->lower)));
422412

423413
/* see interval_larger */
424414
*result += Max(intr->time + intr->month * (30.0 * 86400), 0);
@@ -483,8 +473,8 @@ tskey_cmp(const void *a, const void *b)
483473
return DatumGetInt32(
484474
DirectFunctionCall2(
485475
timestamp_cmp,
486-
TimestampGetDatum(((TSKEY *) (((RIX *) a)->r))->lower),
487-
TimestampGetDatum(((TSKEY *) (((RIX *) b)->r))->lower)
476+
TimestampGetDatumFast(((TSKEY *) (((RIX *) a)->r))->lower),
477+
TimestampGetDatumFast(((TSKEY *) (((RIX *) b)->r))->lower)
488478
)
489479
);
490480
}

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