summaryrefslogtreecommitdiff
path: root/src/backend/optimizer
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer')
-rw-r--r--src/backend/optimizer/path/indxpath.c16
-rw-r--r--src/backend/optimizer/plan/planner.c44
-rw-r--r--src/backend/optimizer/util/plancat.c22
3 files changed, 30 insertions, 52 deletions
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 68fb4eda07..3964d5d5bb 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.71 1999/09/13 00:17:19 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/indxpath.c,v 1.72 1999/09/18 19:06:54 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1163,7 +1163,7 @@ clause_pred_clause_test(Expr *predicate, Node *clause)
F_OIDEQ,
ObjectIdGetDatum(pred_op));
- relation = heap_openr(AccessMethodOperatorRelationName);
+ relation = heap_openr(AccessMethodOperatorRelationName, AccessShareLock);
/*
* The following assumes that any given operator will only be in a
@@ -1178,6 +1178,8 @@ clause_pred_clause_test(Expr *predicate, Node *clause)
if (!HeapTupleIsValid(tuple))
{
elog(DEBUG, "clause_pred_clause_test: unknown pred_op");
+ heap_endscan(scan);
+ heap_close(relation, AccessShareLock);
return false;
}
aform = (Form_pg_amop) GETSTRUCT(tuple);
@@ -1209,6 +1211,8 @@ clause_pred_clause_test(Expr *predicate, Node *clause)
if (!HeapTupleIsValid(tuple))
{
elog(DEBUG, "clause_pred_clause_test: unknown clause_op");
+ heap_endscan(scan);
+ heap_close(relation, AccessShareLock);
return false;
}
aform = (Form_pg_amop) GETSTRUCT(tuple);
@@ -1224,8 +1228,10 @@ clause_pred_clause_test(Expr *predicate, Node *clause)
test_strategy = BT_implic_table[clause_strategy - 1][pred_strategy - 1];
if (test_strategy == 0)
+ {
+ heap_close(relation, AccessShareLock);
return false; /* the implication cannot be determined */
-
+ }
/*
* 4. From the same opclass, find the operator for the test strategy
@@ -1241,14 +1247,18 @@ clause_pred_clause_test(Expr *predicate, Node *clause)
if (!HeapTupleIsValid(tuple))
{
elog(DEBUG, "clause_pred_clause_test: unknown test_op");
+ heap_endscan(scan);
+ heap_close(relation, AccessShareLock);
return false;
}
aform = (Form_pg_amop) GETSTRUCT(tuple);
/* Get the test operator */
test_op = aform->amopopr;
+
heap_endscan(scan);
+ heap_close(relation, AccessShareLock);
/*
* 5. Evaluate the test
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index a22d3ed43a..32a5bb52cd 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.67 1999/09/13 00:17:25 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.68 1999/09/18 19:07:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -627,7 +627,6 @@ pg_checkretval(Oid rettype, List *queryTreeList)
Resdom *resnode;
Relation reln;
Oid relid;
- Oid tletype;
int relnatts;
int i;
@@ -713,11 +712,7 @@ pg_checkretval(Oid rettype, List *queryTreeList)
* declared return type, and be sure that attributes 1 .. n in the
* target list match the declared types.
*/
- reln = heap_open(typeTypeRelid(typ));
-
- if (!RelationIsValid(reln))
- elog(ERROR, "cannot open relation relid %u", typeTypeRelid(typ));
-
+ reln = heap_open(typeTypeRelid(typ), AccessShareLock);
relid = reln->rd_id;
relnatts = reln->rd_rel->relnatts;
@@ -729,41 +724,12 @@ pg_checkretval(Oid rettype, List *queryTreeList)
{
TargetEntry *tle = lfirst(tlist);
Node *thenode = tle->expr;
+ Oid tletype = exprType(thenode);
- tlist = lnext(tlist);
- tletype = exprType(thenode);
-
-#ifdef NOT_USED /* fix me */
- /* this is tedious */
- if (IsA(thenode, Var))
- tletype = (Oid) ((Var *) thenode)->vartype;
- else if (IsA(thenode, Const))
- tletype = (Oid) ((Const *) thenode)->consttype;
- else if (IsA(thenode, Param))
- tletype = (Oid) ((Param *) thenode)->paramtype;
- else if (IsA(thenode, Expr))
- tletype = Expr;
-
- else if (IsA(thenode, LispList))
- {
- thenode = lfirst(thenode);
- if (IsA(thenode, Oper))
- tletype = (Oid) get_opresulttype((Oper *) thenode);
- else if (IsA(thenode, Func))
- tletype = (Oid) get_functype((Func *) thenode);
- else
- elog(ERROR, "function declared to return type %s does not retrieve (%s.all)", typeTypeName(typ), typeTypeName(typ));
- }
- else
- elog(ERROR, "function declared to return type %s does not retrieve (%s.all)", typeTypeName(typ), typeTypeName(typ));
-#endif
- /* reach right in there, why don't you? */
if (tletype != reln->rd_att->attrs[i - 1]->atttypid)
elog(ERROR, "function declared to return type %s does not retrieve (%s.all)", typeTypeName(typ), typeTypeName(typ));
+ tlist = lnext(tlist);
}
- heap_close(reln);
-
- /* success */
- return;
+ heap_close(reln, AccessShareLock);
}
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index 9ca188bce6..ef120f8d2f 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.37 1999/09/09 02:35:53 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.38 1999/09/18 19:07:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -126,17 +126,19 @@ index_info(Query *root, bool first, int relid, IdxInfoRetval *info)
/* Find an index on the given relation */
if (first)
{
- if (RelationIsValid(relation))
- heap_close(relation);
if (HeapScanIsValid(scan))
heap_endscan(scan);
+ scan = (HeapScanDesc) NULL;
+ if (RelationIsValid(relation))
+ heap_close(relation, AccessShareLock);
+ relation = (Relation) NULL;
ScanKeyEntryInitialize(&indexKey, 0,
Anum_pg_index_indrelid,
F_OIDEQ,
ObjectIdGetDatum(indrelid));
- relation = heap_openr(IndexRelationName);
+ relation = heap_openr(IndexRelationName, AccessShareLock);
scan = heap_beginscan(relation, 0, SnapshotNow,
1, &indexKey);
}
@@ -146,7 +148,7 @@ index_info(Query *root, bool first, int relid, IdxInfoRetval *info)
if (!HeapTupleIsValid(indexTuple))
{
heap_endscan(scan);
- heap_close(relation);
+ heap_close(relation, AccessShareLock);
scan = (HeapScanDesc) NULL;
relation = (Relation) NULL;
return 0;
@@ -190,7 +192,7 @@ index_info(Query *root, bool first, int relid, IdxInfoRetval *info)
info->relam = relam;
info->pages = indexRelation->rd_rel->relpages;
info->tuples = indexRelation->rd_rel->reltuples;
- heap_close(indexRelation);
+ index_close(indexRelation);
/*
* Find the index ordering keys
@@ -390,7 +392,7 @@ find_inheritance_children(Oid inhparent)
key[0].sk_nargs = key[0].sk_func.fn_nargs;
key[0].sk_argument = ObjectIdGetDatum((Oid) inhparent);
- relation = heap_openr(InheritsRelationName);
+ relation = heap_openr(InheritsRelationName, AccessShareLock);
scan = heap_beginscan(relation, 0, SnapshotNow, 1, key);
while (HeapTupleIsValid(inheritsTuple = heap_getnext(scan, 0)))
{
@@ -398,7 +400,7 @@ find_inheritance_children(Oid inhparent)
list = lappendi(list, inhrelid);
}
heap_endscan(scan);
- heap_close(relation);
+ heap_close(relation, AccessShareLock);
return list;
}
@@ -424,8 +426,8 @@ VersionGetParents(Oid verrelid)
fmgr_info(F_OIDEQ, &key[0].sk_func);
key[0].sk_nargs = key[0].sk_func.fn_nargs;
- relation = heap_openr(VersionRelationName);
key[0].sk_argument = ObjectIdGetDatum(verrelid);
+ relation = heap_openr(VersionRelationName, AccessShareLock);
scan = heap_beginscan(relation, 0, SnapshotNow, 1, key);
while (HeapTupleIsValid(versionTuple = heap_getnext(scan, 0)))
{
@@ -438,7 +440,7 @@ VersionGetParents(Oid verrelid)
heap_rescan(scan, 0, key);
}
heap_endscan(scan);
- heap_close(relation);
+ heap_close(relation, AccessShareLock);
return list;
}