Commit 2f121062 authored by Tom Lane's avatar Tom Lane

Separate predicate-testing code out of indxpath.c, making it a module

in its own right.  As proposed by Simon Riggs, but with some editorializing
of my own.
parent 111e29ef
This diff is collapsed.
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.191 2005/06/05 22:32:55 tgl Exp $ * $PostgreSQL: pgsql/src/backend/optimizer/plan/createplan.c,v 1.192 2005/06/10 22:25:36 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/cost.h" #include "optimizer/cost.h"
#include "optimizer/paths.h"
#include "optimizer/plancat.h" #include "optimizer/plancat.h"
#include "optimizer/planmain.h" #include "optimizer/planmain.h"
#include "optimizer/predtest.h"
#include "optimizer/restrictinfo.h" #include "optimizer/restrictinfo.h"
#include "optimizer/tlist.h" #include "optimizer/tlist.h"
#include "optimizer/var.h" #include "optimizer/var.h"
...@@ -782,8 +782,8 @@ create_indexscan_plan(PlannerInfo *root, ...@@ -782,8 +782,8 @@ create_indexscan_plan(PlannerInfo *root,
* spot duplicate RestrictInfos, so we try that first. In some situations * spot duplicate RestrictInfos, so we try that first. In some situations
* (particularly with OR'd index conditions) we may have scan_clauses * (particularly with OR'd index conditions) we may have scan_clauses
* that are not equal to, but are logically implied by, the index quals; * that are not equal to, but are logically implied by, the index quals;
* so we also try a pred_test() check to see if we can discard quals * so we also try a predicate_implied_by() check to see if we can discard
* that way. * quals that way.
* *
* While at it, we strip off the RestrictInfos to produce a list of * While at it, we strip off the RestrictInfos to produce a list of
* plain expressions. * plain expressions.
...@@ -796,7 +796,8 @@ create_indexscan_plan(PlannerInfo *root, ...@@ -796,7 +796,8 @@ create_indexscan_plan(PlannerInfo *root,
Assert(IsA(rinfo, RestrictInfo)); Assert(IsA(rinfo, RestrictInfo));
if (list_member_ptr(nonlossy_indexquals, rinfo)) if (list_member_ptr(nonlossy_indexquals, rinfo))
continue; continue;
if (pred_test(list_make1(rinfo->clause), nonlossy_indexquals)) if (predicate_implied_by(list_make1(rinfo->clause),
nonlossy_indexquals))
continue; continue;
qpqual = lappend(qpqual, rinfo->clause); qpqual = lappend(qpqual, rinfo->clause);
} }
...@@ -878,7 +879,7 @@ create_bitmap_scan_plan(PlannerInfo *root, ...@@ -878,7 +879,7 @@ create_bitmap_scan_plan(PlannerInfo *root,
* clauses, so we try that first. In some situations (particularly with * clauses, so we try that first. In some situations (particularly with
* OR'd index conditions) we may have scan_clauses that are not equal to, * OR'd index conditions) we may have scan_clauses that are not equal to,
* but are logically implied by, the index quals; so we also try a * but are logically implied by, the index quals; so we also try a
* pred_test() check to see if we can discard quals that way. * predicate_implied_by() check to see if we can discard quals that way.
*/ */
qpqual = NIL; qpqual = NIL;
foreach(l, scan_clauses) foreach(l, scan_clauses)
...@@ -887,7 +888,8 @@ create_bitmap_scan_plan(PlannerInfo *root, ...@@ -887,7 +888,8 @@ create_bitmap_scan_plan(PlannerInfo *root,
if (list_member(indexquals, clause)) if (list_member(indexquals, clause))
continue; continue;
if (pred_test(list_make1(clause), indexquals)) if (predicate_implied_by(list_make1(clause),
indexquals))
continue; continue;
qpqual = lappend(qpqual, clause); qpqual = lappend(qpqual, clause);
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# Makefile for optimizer/util # Makefile for optimizer/util
# #
# IDENTIFICATION # IDENTIFICATION
# $PostgreSQL: pgsql/src/backend/optimizer/util/Makefile,v 1.15 2003/11/29 19:51:51 pgsql Exp $ # $PostgreSQL: pgsql/src/backend/optimizer/util/Makefile,v 1.16 2005/06/10 22:25:36 tgl Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -12,8 +12,8 @@ subdir = src/backend/optimizer/util ...@@ -12,8 +12,8 @@ subdir = src/backend/optimizer/util
top_builddir = ../../../.. top_builddir = ../../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
OBJS = restrictinfo.o clauses.o plancat.o \ OBJS = clauses.o joininfo.o pathnode.o plancat.o predtest.o \
joininfo.o pathnode.o relnode.o tlist.o var.o relnode.o restrictinfo.o tlist.o var.o
all: SUBSYS.o all: SUBSYS.o
......
This diff is collapsed.
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.180 2005/06/05 22:32:57 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.181 2005/06/10 22:25:36 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -4221,12 +4221,11 @@ genericcostestimate(PlannerInfo *root, ...@@ -4221,12 +4221,11 @@ genericcostestimate(PlannerInfo *root,
* of partial redundancy (such as "x < 4" from the qual and "x < 5" * of partial redundancy (such as "x < 4" from the qual and "x < 5"
* from the predicate) will be recognized and handled correctly by * from the predicate) will be recognized and handled correctly by
* clauselist_selectivity(). This assumption is somewhat fragile, * clauselist_selectivity(). This assumption is somewhat fragile,
* since it depends on pred_test() and clauselist_selectivity() having * since it depends on predicate_implied_by() and clauselist_selectivity()
* similar capabilities, and there are certainly many cases where we * having similar capabilities, and there are certainly many cases where
* will end up with a too-low selectivity estimate. This will bias * we will end up with a too-low selectivity estimate. This will bias the
* the system in favor of using partial indexes where possible, which * system in favor of using partial indexes where possible, which is not
* is not necessarily a bad thing. But it'd be nice to do better * necessarily a bad thing. But it'd be nice to do better someday.
* someday.
* *
* Note that index->indpred and indexQuals are both in implicit-AND form, * Note that index->indpred and indexQuals are both in implicit-AND form,
* so ANDing them together just takes merging the lists. However, * so ANDing them together just takes merging the lists. However,
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.84 2005/06/05 22:32:58 tgl Exp $ * $PostgreSQL: pgsql/src/include/optimizer/paths.h,v 1.85 2005/06/10 22:25:37 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -49,7 +49,6 @@ extern bool match_index_to_operand(Node *operand, int indexcol, ...@@ -49,7 +49,6 @@ extern bool match_index_to_operand(Node *operand, int indexcol,
extern List *expand_indexqual_conditions(IndexOptInfo *index, extern List *expand_indexqual_conditions(IndexOptInfo *index,
List *clausegroups); List *clausegroups);
extern void check_partial_indexes(PlannerInfo *root, RelOptInfo *rel); extern void check_partial_indexes(PlannerInfo *root, RelOptInfo *rel);
extern bool pred_test(List *predicate_list, List *restrictinfo_list);
extern List *flatten_clausegroups_list(List *clausegroups); extern List *flatten_clausegroups_list(List *clausegroups);
/* /*
......
/*-------------------------------------------------------------------------
*
* predtest.h
* prototypes for predtest.c
*
*
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/optimizer/predtest.h,v 1.1 2005/06/10 22:25:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef PREDTEST_H
#define PREDTEST_H
#include "nodes/primnodes.h"
extern bool predicate_implied_by(List *predicate_list,
List *restrictinfo_list);
#endif /* PREDTEST_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment