aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/plancat.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-06-07 17:21:17 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-06-07 17:21:17 -0400
commit77ba610805e7ef9ba9c9a593ea8b1ca8f98f8bcb (patch)
tree1c607e007c59f23ab471bb790e1237cf8d849e5e /src/backend/optimizer/util/plancat.c
parent5c6d2a5e7c83bf6e157fe4ca0ab9b123012289e9 (diff)
downloadpostgresql-77ba610805e7ef9ba9c9a593ea8b1ca8f98f8bcb.tar.gz
postgresql-77ba610805e7ef9ba9c9a593ea8b1ca8f98f8bcb.zip
Revert "Use Foreign Key relationships to infer multi-column join selectivity".
This commit reverts 137805f89 as well as the associated commits 015e88942, 5306df283, and 68d704edb. We found multiple bugs in this feature, and there was concern about possible planner slowdown (though to be fair, exhibiting a very large slowdown proved difficult). The way forward requires a considerable rewrite, which may or may not be possible to accomplish in time for beta2. In my judgment reviewing the rewrite will be easier to accomplish starting from a clean slate, so let's temporarily revert what's there now. This also leaves us in a safe state if it turns out to be necessary to postpone the rewrite to the next development cycle. Discussion: <20160429102531.GA13701@huehner.biz>
Diffstat (limited to 'src/backend/optimizer/util/plancat.c')
-rw-r--r--src/backend/optimizer/util/plancat.c85
1 files changed, 1 insertions, 84 deletions
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index b0b606ebc82..3a585ade747 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -28,7 +28,6 @@
#include "catalog/dependency.h"
#include "catalog/heap.h"
#include "catalog/pg_am.h"
-#include "catalog/pg_constraint.h"
#include "foreign/fdwapi.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
@@ -42,7 +41,6 @@
#include "rewrite/rewriteManip.h"
#include "storage/bufmgr.h"
#include "utils/lsyscache.h"
-#include "utils/syscache.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
@@ -96,9 +94,6 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
Relation relation;
bool hasindex;
List *indexinfos = NIL;
- List *fkinfos = NIL;
- List *fkoidlist;
- ListCell *l;
/*
* We need not lock the relation since it was already locked, either by
@@ -149,6 +144,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
if (hasindex)
{
List *indexoidlist;
+ ListCell *l;
LOCKMODE lmode;
indexoidlist = RelationGetIndexList(relation);
@@ -395,85 +391,6 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
rel->indexlist = indexinfos;
- /*
- * Load foreign key data. Note this is the definitional data from the
- * catalog only and does not lock the referenced tables here. The
- * precise definition of the FK is important and may affect the usage
- * elsewhere in the planner, e.g. if the constraint is deferred or
- * if the constraint is not valid then relying upon this in the executor
- * may not be accurate, though might be considered a useful estimate for
- * planning purposes.
- */
- fkoidlist = RelationGetFKeyList(relation);
-
- foreach(l, fkoidlist)
- {
- Oid fkoid = lfirst_oid(l);
- HeapTuple htup;
- Form_pg_constraint constraint;
- ForeignKeyOptInfo *info;
- Datum adatum;
- bool isnull;
- ArrayType *arr;
- int numkeys;
- int i;
-
- htup = SearchSysCache1(CONSTROID, ObjectIdGetDatum(fkoid));
- if (!HeapTupleIsValid(htup)) /* should not happen */
- elog(ERROR, "cache lookup failed for constraint %u", fkoid);
- constraint = (Form_pg_constraint) GETSTRUCT(htup);
-
- Assert(constraint->contype == CONSTRAINT_FOREIGN);
-
- info = makeNode(ForeignKeyOptInfo);
-
- info->conrelid = constraint->conrelid;
- info->confrelid = constraint->confrelid;
-
- /* conkey */
- adatum = SysCacheGetAttr(CONSTROID, htup,
- Anum_pg_constraint_conkey, &isnull);
- Assert(!isnull);
-
- arr = DatumGetArrayTypeP(adatum);
- numkeys = ARR_DIMS(arr)[0];
- info->conkeys = (int*)palloc(numkeys * sizeof(int));
- for (i = 0; i < numkeys; i++)
- info->conkeys[i] = ((int16 *) ARR_DATA_PTR(arr))[i];
-
- /* confkey */
- adatum = SysCacheGetAttr(CONSTROID, htup,
- Anum_pg_constraint_confkey, &isnull);
- Assert(!isnull);
-
- arr = DatumGetArrayTypeP(adatum);
- Assert(numkeys == ARR_DIMS(arr)[0]);
- info->confkeys = (int*)palloc(numkeys * sizeof(int));
- for (i = 0; i < numkeys; i++)
- info->confkeys[i] = ((int16 *) ARR_DATA_PTR(arr))[i];
-
- /* conpfeqop */
- adatum = SysCacheGetAttr(CONSTROID, htup,
- Anum_pg_constraint_conpfeqop, &isnull);
- Assert(!isnull);
-
- arr = DatumGetArrayTypeP(adatum);
- Assert(numkeys == ARR_DIMS(arr)[0]);
- info->conpfeqop = (Oid*)palloc(numkeys * sizeof(Oid));
- for (i = 0; i < numkeys; i++)
- info->conpfeqop[i] = ((Oid *) ARR_DATA_PTR(arr))[i];
-
- info->nkeys = numkeys;
-
- ReleaseSysCache(htup);
-
- fkinfos = lappend(fkinfos, info);
- }
-
- list_free(fkoidlist);
-
- rel->fkeylist = fkinfos;
-
/* Grab foreign-table info using the relcache, while we have it */
if (relation->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
{