summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2006-01-14 22:03:35 +0000
committerTom Lane2006-01-14 22:03:35 +0000
commit1085aabfd3727004ac136a60aa5de0dceca44db0 (patch)
tree33e2150e484d2c780aa2a9d019a48ba09789bc51
parent15210036c649c6177cf6bd055e0b52a07ee07a6b (diff)
Some minor code cleanup, falling out from the removal of rtree. SK_NEGATE
isn't being used anywhere anymore, and there seems no point in a generic index_keytest() routine when two out of three remaining access methods aren't using it. Also, add a comment documenting a convention for letting access methods define private flag bits in ScanKey sk_flags. There are no such flags at the moment but I'm thinking about changing btree's handling of "required keys" to use flag bits in the keys rather than a count of required key positions. Also, if some AM did still want SK_NEGATE then it would be reasonable to treat it as a private flag bit.
-rw-r--r--src/backend/access/common/Makefile3
-rw-r--r--src/backend/access/common/indexvalid.c78
-rw-r--r--src/backend/access/gist/gistget.c16
-rw-r--r--src/backend/access/hash/hashutil.c37
-rw-r--r--src/backend/executor/execUtils.c4
-rw-r--r--src/include/access/iqual.h31
-rw-r--r--src/include/access/skey.h9
7 files changed, 52 insertions, 126 deletions
diff --git a/src/backend/access/common/Makefile b/src/backend/access/common/Makefile
index 736c38e6b4..9b45fde209 100644
--- a/src/backend/access/common/Makefile
+++ b/src/backend/access/common/Makefile
@@ -12,8 +12,7 @@ subdir = src/backend/access/common
top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global
-OBJS = heaptuple.o indextuple.o indexvalid.o printtup.o \
- scankey.o tupdesc.o
+OBJS = heaptuple.o indextuple.o printtup.o scankey.o tupdesc.o
all: SUBSYS.o
diff --git a/src/backend/access/common/indexvalid.c b/src/backend/access/common/indexvalid.c
deleted file mode 100644
index d687deda65..0000000000
--- a/src/backend/access/common/indexvalid.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * indexvalid.c
- * index tuple qualification validity checking code
- *
- * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * $PostgreSQL$
- *
- *-------------------------------------------------------------------------
- */
-
-#include "postgres.h"
-
-#include "access/iqual.h"
-#include "executor/execdebug.h"
-
-/* ----------------------------------------------------------------
- * index scan key qualification code
- * ----------------------------------------------------------------
- */
-int NIndexTupleProcessed;
-
-
-/* ----------------
- * index_keytest - does this index tuple satisfy the scan key(s)?
- * ----------------
- */
-bool
-index_keytest(IndexTuple tuple,
- TupleDesc tupdesc,
- int scanKeySize,
- ScanKey key)
-{
- IncrIndexProcessed();
-
- while (scanKeySize > 0)
- {
- Datum datum;
- bool isNull;
- Datum test;
-
- datum = index_getattr(tuple,
- key->sk_attno,
- tupdesc,
- &isNull);
-
- if (isNull)
- {
- /* XXX eventually should check if SK_ISNULL */
- return false;
- }
-
- if (key->sk_flags & SK_ISNULL)
- return false;
-
- test = FunctionCall2(&key->sk_func, datum, key->sk_argument);
-
- if (key->sk_flags & SK_NEGATE)
- {
- if (DatumGetBool(test))
- return false;
- }
- else
- {
- if (!DatumGetBool(test))
- return false;
- }
-
- key++;
- scanKeySize--;
- }
-
- return true;
-}
diff --git a/src/backend/access/gist/gistget.c b/src/backend/access/gist/gistget.c
index 016a3793c8..e164b0df52 100644
--- a/src/backend/access/gist/gistget.c
+++ b/src/backend/access/gist/gistget.c
@@ -332,13 +332,15 @@ gistnext(IndexScanDesc scan, ScanDirection dir, ItemPointer tids, int maxtids, b
}
/*
- * Similar to index_keytest, but first decompress the key in the
- * IndexTuple before passing it to the sk_func (and we have previously
- * overwritten the sk_func to use the user-defined Consistent method,
- * so we actually invoke that). Note that this function is always
- * invoked in a short-lived memory context, so we don't need to worry
- * about cleaning up allocated memory (either here or in the
- * implementation of any Consistent methods).
+ * gistindex_keytest() -- does this index tuple satisfy the scan key(s)?
+ *
+ * We must decompress the key in the IndexTuple before passing it to the
+ * sk_func (and we have previously overwritten the sk_func to use the
+ * user-defined Consistent method, so we actually are invoking that).
+ *
+ * Note that this function is always invoked in a short-lived memory context,
+ * so we don't need to worry about cleaning up allocated memory, either here
+ * or in the implementation of any Consistent methods.
*/
static bool
gistindex_keytest(IndexTuple tuple,
diff --git a/src/backend/access/hash/hashutil.c b/src/backend/access/hash/hashutil.c
index 61ab8c478a..4778befb14 100644
--- a/src/backend/access/hash/hashutil.c
+++ b/src/backend/access/hash/hashutil.c
@@ -16,7 +16,7 @@
#include "access/genam.h"
#include "access/hash.h"
-#include "access/iqual.h"
+#include "executor/execdebug.h"
/*
@@ -25,8 +25,39 @@
bool
_hash_checkqual(IndexScanDesc scan, IndexTuple itup)
{
- return index_keytest(itup, RelationGetDescr(scan->indexRelation),
- scan->numberOfKeys, scan->keyData);
+ TupleDesc tupdesc = RelationGetDescr(scan->indexRelation);
+ ScanKey key = scan->keyData;
+ int scanKeySize = scan->numberOfKeys;
+
+ IncrIndexProcessed();
+
+ while (scanKeySize > 0)
+ {
+ Datum datum;
+ bool isNull;
+ Datum test;
+
+ datum = index_getattr(itup,
+ key->sk_attno,
+ tupdesc,
+ &isNull);
+
+ /* assume sk_func is strict */
+ if (isNull)
+ return false;
+ if (key->sk_flags & SK_ISNULL)
+ return false;
+
+ test = FunctionCall2(&key->sk_func, datum, key->sk_argument);
+
+ if (!DatumGetBool(test))
+ return false;
+
+ key++;
+ scanKeySize--;
+ }
+
+ return true;
}
/*
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c
index 2626dcbf6b..a9b8173440 100644
--- a/src/backend/executor/execUtils.c
+++ b/src/backend/executor/execUtils.c
@@ -67,9 +67,7 @@ int NTupleReplaced;
int NTupleAppended;
int NTupleDeleted;
int NIndexTupleInserted;
-extern int NIndexTupleProcessed; /* have to be defined in the access
- * method level so that the
- * cinterface.a will link ok. */
+int NIndexTupleProcessed;
static void ShutdownExprContext(ExprContext *econtext);
diff --git a/src/include/access/iqual.h b/src/include/access/iqual.h
deleted file mode 100644
index 5ba90025b3..0000000000
--- a/src/include/access/iqual.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * iqual.h
- * Index scan key qualification definitions.
- *
- *
- * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * $PostgreSQL$
- *
- *-------------------------------------------------------------------------
- */
-#ifndef IQUAL_H
-#define IQUAL_H
-
-#include "access/itup.h"
-#include "access/skey.h"
-
-
-/* ----------------
- * index tuple qualification support
- * ----------------
- */
-
-extern int NIndexTupleProcessed;
-
-extern bool index_keytest(IndexTuple tuple, TupleDesc tupdesc,
- int scanKeySize, ScanKey key);
-
-#endif /* IQUAL_H */
diff --git a/src/include/access/skey.h b/src/include/access/skey.h
index 4c54f7c177..6031117b11 100644
--- a/src/include/access/skey.h
+++ b/src/include/access/skey.h
@@ -69,10 +69,15 @@ typedef struct ScanKeyData
typedef ScanKeyData *ScanKey;
-/* ScanKeyData sk_flags */
+/*
+ * ScanKeyData sk_flags
+ *
+ * sk_flags bits 0-15 are reserved for system-wide use (symbols for those
+ * bits should be defined here). Bits 16-31 are reserved for use within
+ * individual index access methods.
+ */
#define SK_ISNULL 0x0001 /* sk_argument is NULL */
#define SK_UNARY 0x0002 /* unary operator (currently unsupported) */
-#define SK_NEGATE 0x0004 /* must negate the function result */
/*