Detoast query in g_intbig_consistent and copy query in g_int_consistent
authorTeodor Sigaev
Mon, 3 Apr 2006 08:21:05 +0000 (08:21 +0000)
committerTeodor Sigaev
Mon, 3 Apr 2006 08:21:05 +0000 (08:21 +0000)
contrib/intarray/_int_gist.c
contrib/intarray/_intbig_gist.c

index 246d56698736773d39cada3e0045563cfed0f9a2..e8cf24fe47b907945fc8e9f1a0de8066e30b66d0 100644 (file)
@@ -32,17 +32,19 @@ Datum
 g_int_consistent(PG_FUNCTION_ARGS)
 {
    GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
-   ArrayType  *query = (ArrayType *) PG_GETARG_POINTER(1);
+   ArrayType  *query = (ArrayType *) PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(1));
    StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
    bool        retval;
 
-   if (strategy == BooleanSearchStrategy)
-       PG_RETURN_BOOL(execconsistent((QUERYTYPE *) query,
+   if (strategy == BooleanSearchStrategy) {
+       retval = execconsistent((QUERYTYPE *) query,
                                   (ArrayType *) DatumGetPointer(entry->key),
-                                     GIST_LEAF(entry)));
+                                     GIST_LEAF(entry));
+
+       pfree( query );
+       PG_RETURN_BOOL(retval);
+   }
 
-   /* XXX are we sure it's safe to scribble on the query object here? */
-   /* XXX what about toasted input? */
    /* sort query for fast search, key is already sorted */
    CHECKARRVALID(query);
    if (ARRISVOID(query))
@@ -82,6 +84,7 @@ g_int_consistent(PG_FUNCTION_ARGS)
        default:
            retval = FALSE;
    }
+   pfree( query );
    PG_RETURN_BOOL(retval);
 }
 
index 844236068dbaf23ab67adbdcdd604d83e59e87bd..caa0ad48c6058e48e6b58e7f3231bd00b5ccf58c 100644 (file)
@@ -497,7 +497,7 @@ Datum
 g_intbig_consistent(PG_FUNCTION_ARGS)
 {
    GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
-   ArrayType  *query = (ArrayType *) PG_GETARG_POINTER(1);
+   ArrayType  *query = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_POINTER(1));
    StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
    bool        retval;
 
@@ -506,12 +506,13 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
 
    if (strategy == BooleanSearchStrategy)
    {
-       PG_RETURN_BOOL(signconsistent((QUERYTYPE *) query,
+       retval =signconsistent((QUERYTYPE *) query,
                                      GETSIGN(DatumGetPointer(entry->key)),
-                                     false));
+                                     false);
+       PG_FREE_IF_COPY( query, 1 );
+       return retval;
    }
 
-   /* XXX what about toasted input? */
    CHECKARRVALID(query);
    if (ARRISVOID(query))
        return FALSE;
@@ -597,5 +598,6 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
        default:
            retval = FALSE;
    }
+   PG_FREE_IF_COPY( query, 1 );
    PG_RETURN_BOOL(retval);
 }