Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Support new 8.4 consistent function signature, handle recheck in the …

…C code
  • Loading branch information...
commit f152e96ff6ea37530aea12c0b32c475a23686020 1 parent 1362494
dim authored
Showing with 72 additions and 28 deletions.
  1. +1 −0  debian/changelog
  2. +57 −24 prefix.c
  3. +14 −4 prefix.sql.in
View
1  debian/changelog
@@ -4,6 +4,7 @@ prefix (1.0-1~dev1) experimental; urgency=low
* Added support for GiST index lookups for operators <@, =, &&
* Added detection of version 8.1 of PostgreSQL, similar to ip4r
* Fixed wrong build dependancy to README.html
+ * Support new 8.4 consistent function signature, handle recheck in the C code
-- Dimitri Fontaine <dim@tapoueh.org> Thu, 04 Jun 2009 14:49:51 +0200
View
81 prefix.c
@@ -9,7 +9,7 @@
* writting of this opclass, on the PostgreSQL internals, GiST inner
* working and prefix search analyses.
*
- * $Id: prefix.c,v 1.49 2009/06/04 20:10:58 dim Exp $
+ * $Id: prefix.c,v 1.50 2009/06/05 21:05:23 dim Exp $
*/
#include <stdio.h>
@@ -24,6 +24,7 @@
#include <math.h>
#define DEBUG
+#define DEBUG_CONSISTENT
/**
* We use those DEBUG defines in the code, uncomment them to get very
* verbose output.
@@ -1000,31 +1001,27 @@ Datum gpr_union(PG_FUNCTION_ARGS);
Datum gpr_same(PG_FUNCTION_ARGS);
Datum pr_penalty(PG_FUNCTION_ARGS);
-PG_FUNCTION_INFO_V1(gpr_consistent);
-Datum
-gpr_consistent(PG_FUNCTION_ARGS)
-{
- GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
- prefix_range *query = PG_GETARG_PREFIX_RANGE_P(1);
- StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
- prefix_range *key = DatumGetPrefixRange(entry->key);
-
- /*
- OPERATOR 1 @>,
- OPERATOR 2 <@,
- OPERATOR 3 =,
- OPERATOR 4 &&,
- */
+/*
+ * Internal implementation of consistent
+ *
+ OPERATOR 1 @>,
+ OPERATOR 2 <@,
+ OPERATOR 3 =,
+ OPERATOR 4 &&,
+*/
+static inline
+bool pr_consistent(StrategyNumber strategy,
+ prefix_range *key, prefix_range *query, bool is_leaf) {
switch (strategy) {
case 1:
- PG_RETURN_BOOL( pr_contains(key, query, true) );
+ return pr_contains(key, query, true);
case 2:
- PG_RETURN_BOOL( pr_contains(query, key, true) );
+ return pr_contains(query, key, true);
case 3:
- if( GIST_LEAF(entry) ) {
+ if( is_leaf ) {
#ifdef DEBUG_CONSISTENT
elog(NOTICE, "gpr_consistent: %s %c= %s",
@@ -1034,18 +1031,54 @@ gpr_consistent(PG_FUNCTION_ARGS)
DatumGetCString(DirectFunctionCall1(prefix_range_out,PrefixRangeGetDatum(query))));
#endif
- PG_RETURN_BOOL( pr_eq(key, query) );
+ return pr_eq(key, query);
}
else {
- PG_RETURN_BOOL( pr_contains(key, query, true) );
+ return pr_contains(key, query, true);
}
case 4:
- PG_RETURN_BOOL( pr_overlaps(key, query) );
+ return pr_overlaps(key, query);
default:
- PG_RETURN_BOOL(false);
- }
+ return false;
+ }
+}
+
+/*
+ * The consistent function signature has changed in 8.4 to include RECHECK
+ * handling, but the signature declared in the OPERATOR CLASS is not
+ * considered at all.
+ *
+ * Still the function is called by mean of the fmgr, so we know whether
+ * we're called with pre-8.4 conventions or not by checking PG_NARGS().
+ *
+ * In all cases, we currently ignore the oid parameter (subtype).
+ */
+PG_FUNCTION_INFO_V1(gpr_consistent);
+Datum
+gpr_consistent(PG_FUNCTION_ARGS)
+{
+ GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+ prefix_range *query = PG_GETARG_PREFIX_RANGE_P(1);
+ StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
+ prefix_range *key = DatumGetPrefixRange(entry->key);
+ bool *recheck;
+
+ Assert( PG_NARGS() == 4 || PG_NARGS() == 5);
+
+ if( PG_NARGS() == 5 ) {
+ /*
+ * New API in 8.4:
+ * consistent(internal, data_type, smallint, oid, internal)
+ *
+ * We don't ever want to recheck: index ain't lossy, we store
+ * prefix_range keys on the leaves.
+ */
+ recheck = (bool *) PG_GETARG_POINTER(4);
+ *recheck = false;
+ }
+ PG_RETURN_BOOL( pr_consistent(strategy, key, query, GIST_LEAF(entry)) );
}
/*
View
18 prefix.sql.in
@@ -245,7 +245,17 @@ AS
FUNCTION 1 prefix_range_cmp(prefix_range, prefix_range);
-CREATE OR REPLACE FUNCTION gpr_consistent(internal, prefix_range, prefix_range)
+--
+-- Up until 8.4, consistent took 3 arguments, then 5. In all cases, the
+-- CREATE OPERATOR CLASS command will not check this.
+--
+
+CREATE OR REPLACE FUNCTION gpr_consistent(internal, prefix_range, smallint, oid)
+RETURNS bool
+AS 'MODULE_PATHNAME'
+LANGUAGE 'C';
+
+CREATE OR REPLACE FUNCTION gpr_consistent(internal, prefix_range, smallint, oid, internal)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE 'C';
@@ -303,7 +313,7 @@ AS
OPERATOR 2 <@,
OPERATOR 3 =,
OPERATOR 4 &&,
- FUNCTION 1 gpr_consistent (internal, prefix_range, prefix_range),
+ FUNCTION 1 gpr_consistent (internal, prefix_range, smallint, oid, internal),
FUNCTION 2 gpr_union (internal, internal),
FUNCTION 3 gpr_compress (internal),
FUNCTION 4 gpr_decompress (internal),
@@ -315,7 +325,7 @@ CREATE OPERATOR CLASS gist_prefix_range_presort_ops
FOR TYPE prefix_range USING gist
AS
OPERATOR 1 @>,
- FUNCTION 1 gpr_consistent (internal, prefix_range, prefix_range),
+ FUNCTION 1 gpr_consistent (internal, prefix_range, smallint, oid, internal),
FUNCTION 2 gpr_union (internal, internal),
FUNCTION 3 gpr_compress (internal),
FUNCTION 4 gpr_decompress (internal),
@@ -327,7 +337,7 @@ CREATE OPERATOR CLASS gist_prefix_range_jordan_ops
FOR TYPE prefix_range USING gist
AS
OPERATOR 1 @>,
- FUNCTION 1 gpr_consistent (internal, prefix_range, prefix_range),
+ FUNCTION 1 gpr_consistent (internal, prefix_range, smallint, oid, internal),
FUNCTION 2 gpr_union (internal, internal),
FUNCTION 3 gpr_compress (internal),
FUNCTION 4 gpr_decompress (internal),
Please sign in to comment.
Something went wrong with that request. Please try again.