Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions imgsmlr.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#ifdef PG_VERSION_NUM
#if PG_VERSION_NUM >= 160000
#include "varatt.h"
#endif
#endif

#include "c.h"
#include "fmgr.h"
Expand Down
10 changes: 10 additions & 0 deletions imgsmlr.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,13 @@ typedef struct
#define CHECK_SIGNATURE_KEY(key) Assert(VARSIZE_ANY_EXHDR(key) == sizeof(Signature) || VARSIZE_ANY_EXHDR(key) == 2 * sizeof(Signature));

#endif /* IMGSMLR_H */


#ifndef FALSE
#define FALSE (0)
#endif


#ifndef TRUE
#define TRUE (!FALSE)
#endif
36 changes: 23 additions & 13 deletions imgsmlr_idx.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
*-------------------------------------------------------------------------
*/
#include "postgres.h"

#ifdef PG_VERSION_NUM
#if PG_VERSION_NUM >= 160000
#include "varatt.h"
#endif
#endif

#include "fmgr.h"
#include "imgsmlr.h"
#include "access/gist.h"
Expand Down Expand Up @@ -77,19 +84,22 @@ signature_compress(PG_FUNCTION_ARGS)
Datum
signature_decompress(PG_FUNCTION_ARGS)
{
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
bytea *key = DatumGetByteaP(PG_DETOAST_DATUM(entry->key));

if (key != DatumGetByteaP(entry->key))
{
GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));

gistentryinit(*retval, PointerGetDatum(key),
entry->rel, entry->page,
entry->offset, FALSE);
PG_RETURN_POINTER(retval);
}
PG_RETURN_POINTER(entry);
GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
bytea *detoastedKey = DatumGetByteaP(entry->key);
bytea *key = (bytea *) entry->key;

// Variable key is the original entry->key before detoasting, and it’s compared with the
// detoasted key. If they’re different, a new GISTENTRY is created. Otherwise, the original entry is returned.
if (key != detoastedKey)
{
GISTENTRY *retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));

gistentryinit(*retval, PointerGetDatum(key),
entry->rel, entry->page,
entry->offset, FALSE);
PG_RETURN_POINTER(retval);
}
PG_RETURN_POINTER(entry);
}

Datum
Expand Down