diff --git a/imgsmlr.c b/imgsmlr.c index 84ee11f..21551e7 100755 --- a/imgsmlr.c +++ b/imgsmlr.c @@ -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" diff --git a/imgsmlr.h b/imgsmlr.h index 9ee8cae..6810b39 100755 --- a/imgsmlr.h +++ b/imgsmlr.h @@ -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 diff --git a/imgsmlr_idx.c b/imgsmlr_idx.c index d85fbd0..81e0c97 100755 --- a/imgsmlr_idx.c +++ b/imgsmlr_idx.c @@ -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" @@ -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