summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2010-01-01 21:53:49 +0000
committerTom Lane2010-01-01 21:53:49 +0000
commit29c4ad98293e3c5cb3fcdd413a3f4904efff8762 (patch)
tree4e4eeea2655e87eca4d3d0dd97f3e2b7d5f1e032 /src/include
parent15faca259651c065bb20e746777f5fb9eb9d50a1 (diff)
Support "x IS NOT NULL" clauses as indexscan conditions. This turns out
to be just a minor extension of the previous patch that made "x IS NULL" indexable, because we can treat the IS NOT NULL condition as if it were "x < NULL" or "x > NULL" (depending on the index's NULLS FIRST/LAST option), just like IS NULL is treated like "x = NULL". Aside from any possible usefulness in its own right, this is an important improvement for index-optimized MAX/MIN aggregates: it is now reliably possible to get a column's min or max value cheaply, even when there are a lot of nulls cluttering the interesting end of the index.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/skey.h25
-rw-r--r--src/include/catalog/pg_am.h4
-rw-r--r--src/include/nodes/relation.h4
-rw-r--r--src/include/optimizer/planmain.h3
4 files changed, 20 insertions, 16 deletions
diff --git a/src/include/access/skey.h b/src/include/access/skey.h
index d295d3d12d5..509e1d08ddb 100644
--- a/src/include/access/skey.h
+++ b/src/include/access/skey.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/skey.h,v 1.37 2009/01/01 17:23:56 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/access/skey.h,v 1.38 2010/01/01 21:53:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -52,11 +52,13 @@ typedef uint16 StrategyNumber;
* the operator. When using a ScanKey in a heap scan, these fields are not
* used and may be set to InvalidStrategy/InvalidOid.
*
- * A ScanKey can also represent a condition "column IS NULL"; this is signaled
- * by the SK_SEARCHNULL flag bit. In this case the argument is always NULL,
+ * A ScanKey can also represent a condition "column IS NULL" or "column
+ * IS NOT NULL"; these cases are signaled by the SK_SEARCHNULL and
+ * SK_SEARCHNOTNULL flag bits respectively. The argument is always NULL,
* and the sk_strategy, sk_subtype, and sk_func fields are not used (unless
- * set by the index AM). Currently, SK_SEARCHNULL is supported only for
- * index scans, not heap scans; and not all index AMs support it.
+ * set by the index AM). Currently, SK_SEARCHNULL and SK_SEARCHNOTNULL are
+ * supported only for index scans, not heap scans; and not all index AMs
+ * support them.
*
* Note: in some places, ScanKeys are used as a convenient representation
* for the invocation of an access method support procedure. In this case
@@ -112,12 +114,13 @@ typedef ScanKeyData *ScanKey;
* 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_ROW_HEADER 0x0004 /* row comparison header (see above) */
-#define SK_ROW_MEMBER 0x0008 /* row comparison member (see above) */
-#define SK_ROW_END 0x0010 /* last row comparison member (see above) */
-#define SK_SEARCHNULL 0x0020 /* scankey represents a "col IS NULL" qual */
+#define SK_ISNULL 0x0001 /* sk_argument is NULL */
+#define SK_UNARY 0x0002 /* unary operator (not supported!) */
+#define SK_ROW_HEADER 0x0004 /* row comparison header (see above) */
+#define SK_ROW_MEMBER 0x0008 /* row comparison member (see above) */
+#define SK_ROW_END 0x0010 /* last row comparison member */
+#define SK_SEARCHNULL 0x0020 /* scankey represents "col IS NULL" */
+#define SK_SEARCHNOTNULL 0x0040 /* scankey represents "col IS NOT NULL" */
/*
diff --git a/src/include/catalog/pg_am.h b/src/include/catalog/pg_am.h
index a92c1f49971..1b3769fdbf5 100644
--- a/src/include/catalog/pg_am.h
+++ b/src/include/catalog/pg_am.h
@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/catalog/pg_am.h,v 1.62 2009/03/24 20:17:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_am.h,v 1.63 2010/01/01 21:53:49 tgl Exp $
*
* NOTES
* the genbki.sh script reads this file and generates .bki
@@ -46,7 +46,7 @@ CATALOG(pg_am,2601)
bool amcanmulticol; /* does AM support multi-column indexes? */
bool amoptionalkey; /* can query omit key for the first column? */
bool amindexnulls; /* does AM support NULL index entries? */
- bool amsearchnulls; /* can AM search for NULL index entries? */
+ bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */
bool amstorage; /* can storage type differ from column type? */
bool amclusterable; /* does AM support cluster command? */
Oid amkeytype; /* type of data in index, or InvalidOid */
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h
index 8738a9924d5..fbbec6d5744 100644
--- a/src/include/nodes/relation.h
+++ b/src/include/nodes/relation.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.180 2009/11/28 00:46:19 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.181 2010/01/01 21:53:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -459,7 +459,7 @@ typedef struct IndexOptInfo
bool predOK; /* true if predicate matches query */
bool unique; /* true if a unique index */
bool amoptionalkey; /* can query omit key for the first column? */
- bool amsearchnulls; /* can AM search for NULL index entries? */
+ bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */
bool amhasgettuple; /* does AM have amgettuple interface? */
bool amhasgetbitmap; /* does AM have amgetbitmap interface? */
} IndexOptInfo;
diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h
index 9a661a5ee8c..2e9f0659f26 100644
--- a/src/include/optimizer/planmain.h
+++ b/src/include/optimizer/planmain.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.121 2009/10/26 02:26:45 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/planmain.h,v 1.122 2010/01/01 21:53:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -39,6 +39,7 @@ extern Plan *optimize_minmax_aggregates(PlannerInfo *root, List *tlist,
* prototypes for plan/createplan.c
*/
extern Plan *create_plan(PlannerInfo *root, Path *best_path);
+extern Node *fix_indexqual_operand(Node *node, IndexOptInfo *index);
extern SubqueryScan *make_subqueryscan(List *qptlist, List *qpqual,
Index scanrelid, Plan *subplan,
List *subrtable, List *subrowmark);