aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/util/plancat.c16
-rw-r--r--src/backend/utils/misc/guc.c39
-rw-r--r--src/backend/utils/misc/postgresql.conf.sample2
-rw-r--r--src/include/optimizer/cost.h11
4 files changed, 49 insertions, 19 deletions
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index 948c0602136..f4f8ac8a763 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.153 2009/01/01 17:23:45 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.154 2009/01/07 22:40:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -27,6 +27,7 @@
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
+#include "optimizer/cost.h"
#include "optimizer/plancat.h"
#include "optimizer/predtest.h"
#include "optimizer/prep.h"
@@ -43,7 +44,7 @@
/* GUC parameter */
-bool constraint_exclusion = false;
+int constraint_exclusion = CONSTRAINT_EXCLUSION_PARTITION;
/* Hook for plugins to get control in get_relation_info() */
get_relation_info_hook_type get_relation_info_hook = NULL;
@@ -561,8 +562,9 @@ get_relation_constraints(PlannerInfo *root,
* self-inconsistent restrictions, or restrictions inconsistent with the
* relation's CHECK constraints.
*
- * Note: this examines only rel->relid and rel->baserestrictinfo; therefore
- * it can be called before filling in other fields of the RelOptInfo.
+ * Note: this examines only rel->relid, rel->reloptkind, and
+ * rel->baserestrictinfo; therefore it can be called before filling in
+ * other fields of the RelOptInfo.
*/
bool
relation_excluded_by_constraints(PlannerInfo *root,
@@ -573,8 +575,10 @@ relation_excluded_by_constraints(PlannerInfo *root,
List *safe_constraints;
ListCell *lc;
- /* Skip the test if constraint exclusion is disabled */
- if (!constraint_exclusion)
+ /* Skip the test if constraint exclusion is disabled for the rel */
+ if (constraint_exclusion == CONSTRAINT_EXCLUSION_OFF ||
+ (constraint_exclusion == CONSTRAINT_EXCLUSION_PARTITION &&
+ rel->reloptkind != RELOPT_OTHER_MEMBER_REL))
return false;
/*
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 479279cdc43..22cfbff6105 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.490 2009/01/06 16:39:52 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.491 2009/01/07 22:40:49 tgl Exp $
*
*--------------------------------------------------------------------
*/
@@ -312,6 +312,23 @@ static const struct config_enum_entry backslash_quote_options[] = {
};
/*
+ * Although only "on", "off", and "partition" are documented, we
+ * accept all the likely variants of "on" and "off".
+ */
+static const struct config_enum_entry constraint_exclusion_options[] = {
+ {"partition", CONSTRAINT_EXCLUSION_PARTITION, false},
+ {"on", CONSTRAINT_EXCLUSION_ON, false},
+ {"off", CONSTRAINT_EXCLUSION_OFF, false},
+ {"true", CONSTRAINT_EXCLUSION_ON, true},
+ {"false", CONSTRAINT_EXCLUSION_OFF, true},
+ {"yes", CONSTRAINT_EXCLUSION_ON, true},
+ {"no", CONSTRAINT_EXCLUSION_OFF, true},
+ {"1", CONSTRAINT_EXCLUSION_ON, true},
+ {"0", CONSTRAINT_EXCLUSION_OFF, true},
+ {NULL, 0, false}
+};
+
+/*
* Options for enum values stored in other modules
*/
extern const struct config_enum_entry sync_method_options[];
@@ -636,15 +653,6 @@ static struct config_bool ConfigureNamesBool[] =
true, NULL, NULL
},
{
- {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
- gettext_noop("Enables the planner to use constraints to optimize queries."),
- gettext_noop("Child table scans will be skipped if their "
- "constraints guarantee that no rows match the query.")
- },
- &constraint_exclusion,
- false, NULL, NULL
- },
- {
{"geqo", PGC_USERSET, QUERY_TUNING_GEQO,
gettext_noop("Enables genetic query optimization."),
gettext_noop("This algorithm attempts to do planning without "
@@ -2522,6 +2530,17 @@ static struct config_enum ConfigureNamesEnum[] =
},
{
+ {"constraint_exclusion", PGC_USERSET, QUERY_TUNING_OTHER,
+ gettext_noop("Enables the planner to use constraints to optimize queries."),
+ gettext_noop("Table scans will be skipped if their constraints"
+ " guarantee that no rows match the query.")
+ },
+ &constraint_exclusion,
+ CONSTRAINT_EXCLUSION_PARTITION, constraint_exclusion_options,
+ NULL, NULL
+ },
+
+ {
{"default_transaction_isolation", PGC_USERSET, CLIENT_CONN_STATEMENT,
gettext_noop("Sets the transaction isolation level of each new transaction."),
NULL
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index e28feb8e428..d53861511ae 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -211,7 +211,7 @@
# - Other Planner Options -
#default_statistics_target = 100 # range 1-10000
-#constraint_exclusion = off
+#constraint_exclusion = partition # on, off, or partition
#cursor_tuple_fraction = 0.1 # range 0.0-1.0
#from_collapse_limit = 8
#join_collapse_limit = 8 # 1 disables collapsing of explicit
diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h
index 39ece8f4ff7..27600fa1acc 100644
--- a/src/include/optimizer/cost.h
+++ b/src/include/optimizer/cost.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/cost.h,v 1.95 2009/01/01 17:24:00 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/cost.h,v 1.96 2009/01/07 22:40:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -29,6 +29,13 @@
#define DEFAULT_EFFECTIVE_CACHE_SIZE 16384 /* measured in pages */
+typedef enum
+{
+ CONSTRAINT_EXCLUSION_OFF, /* do not use c_e */
+ CONSTRAINT_EXCLUSION_ON, /* apply c_e to all rels */
+ CONSTRAINT_EXCLUSION_PARTITION /* apply c_e to otherrels only */
+} ConstraintExclusionType;
+
/*
* prototypes for costsize.c
@@ -52,7 +59,7 @@ extern bool enable_hashagg;
extern bool enable_nestloop;
extern bool enable_mergejoin;
extern bool enable_hashjoin;
-extern bool constraint_exclusion;
+extern int constraint_exclusion;
extern double clamp_row_est(double nrows);
extern double index_pages_fetched(double tuples_fetched, BlockNumber pages,