aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/util')
-rw-r--r--src/backend/optimizer/util/clauses.c56
-rw-r--r--src/backend/optimizer/util/plancat.c48
2 files changed, 57 insertions, 47 deletions
diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c
index f52ec6d2d87..c8df8b26fe4 100644
--- a/src/backend/optimizer/util/clauses.c
+++ b/src/backend/optimizer/util/clauses.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.77 2000/10/05 19:11:32 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.78 2000/11/16 22:30:26 tgl Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -28,7 +28,6 @@
#include "optimizer/clauses.h"
#include "optimizer/tlist.h"
#include "optimizer/var.h"
-#include "parser/parse_type.h"
#include "parser/parsetree.h"
#include "utils/datum.h"
#include "utils/lsyscache.h"
@@ -995,7 +994,8 @@ get_rels_atts(Node *clause,
void
CommuteClause(Expr *clause)
{
- HeapTuple heapTup;
+ Oid opoid;
+ HeapTuple optup;
Form_pg_operator commuTup;
Oper *commu;
Node *temp;
@@ -1004,19 +1004,22 @@ CommuteClause(Expr *clause)
length(clause->args) != 2)
elog(ERROR, "CommuteClause: applied to non-binary-operator clause");
- heapTup = (HeapTuple)
- get_operator_tuple(get_commutator(((Oper *) clause->oper)->opno));
+ opoid = ((Oper *) clause->oper)->opno;
- if (heapTup == (HeapTuple) NULL)
- elog(ERROR, "CommuteClause: no commutator for operator %u",
- ((Oper *) clause->oper)->opno);
+ optup = SearchSysCache(OPEROID,
+ ObjectIdGetDatum(get_commutator(opoid)),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(optup))
+ elog(ERROR, "CommuteClause: no commutator for operator %u", opoid);
- commuTup = (Form_pg_operator) GETSTRUCT(heapTup);
+ commuTup = (Form_pg_operator) GETSTRUCT(optup);
- commu = makeOper(heapTup->t_data->t_oid,
+ commu = makeOper(optup->t_data->t_oid,
commuTup->oprcode,
commuTup->oprresult);
+ ReleaseSysCache(optup);
+
/*
* re-form the clause in-place!
*/
@@ -1434,9 +1437,11 @@ simplify_op_or_func(Expr *expr, List *args)
Oid result_typeid;
HeapTuple func_tuple;
Form_pg_proc funcform;
- Type resultType;
+ bool proiscachable;
+ bool proisstrict;
+ bool proretset;
+ int16 resultTypLen;
bool resultTypByVal;
- int resultTypLen;
Expr *newexpr;
ExprContext *econtext;
Datum const_val;
@@ -1491,36 +1496,37 @@ simplify_op_or_func(Expr *expr, List *args)
* we could use func_iscachable() here, but we need several fields
* out of the func tuple, so might as well just look it up once.
*/
- func_tuple = SearchSysCacheTuple(PROCOID,
- ObjectIdGetDatum(funcid),
- 0, 0, 0);
+ func_tuple = SearchSysCache(PROCOID,
+ ObjectIdGetDatum(funcid),
+ 0, 0, 0);
if (!HeapTupleIsValid(func_tuple))
elog(ERROR, "Function OID %u does not exist", funcid);
funcform = (Form_pg_proc) GETSTRUCT(func_tuple);
- if (!funcform->proiscachable)
+ proiscachable = funcform->proiscachable;
+ proisstrict = funcform->proisstrict;
+ proretset = funcform->proretset;
+ ReleaseSysCache(func_tuple);
+
+ if (!proiscachable)
return NULL;
/*
* Also check to make sure it doesn't return a set.
*/
- if (funcform->proretset)
+ if (proretset)
return NULL;
/*
* Now that we know if the function is strict, we can finish the
* checks for simplifiable inputs that we started above.
*/
- if (funcform->proisstrict && has_null_input)
+ if (proisstrict && has_null_input)
{
/*
* It's strict and has NULL input, so must produce NULL output.
* Return a NULL constant of the right type.
*/
- resultType = typeidType(result_typeid);
- return (Expr *) makeConst(result_typeid, typeLen(resultType),
- (Datum) 0, true,
- typeByVal(resultType),
- false, false);
+ return (Expr *) makeNullConst(result_typeid);
}
/*
@@ -1548,9 +1554,7 @@ simplify_op_or_func(Expr *expr, List *args)
newexpr->args = args;
/* Get info needed about result datatype */
- resultType = typeidType(result_typeid);
- resultTypByVal = typeByVal(resultType);
- resultTypLen = typeLen(resultType);
+ get_typlenbyval(result_typeid, &resultTypLen, &resultTypByVal);
/*
* It is OK to pass a dummy econtext because none of the ExecEvalExpr()
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index 0d32e82ed9a..055cd3788b9 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.61 2000/09/29 18:21:23 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/util/plancat.c,v 1.62 2000/11/16 22:30:26 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -48,9 +48,9 @@ relation_info(Oid relationObjectId,
HeapTuple relationTuple;
Form_pg_class relation;
- relationTuple = SearchSysCacheTuple(RELOID,
- ObjectIdGetDatum(relationObjectId),
- 0, 0, 0);
+ relationTuple = SearchSysCache(RELOID,
+ ObjectIdGetDatum(relationObjectId),
+ 0, 0, 0);
if (!HeapTupleIsValid(relationTuple))
elog(ERROR, "relation_info: Relation %u not found",
relationObjectId);
@@ -62,6 +62,7 @@ relation_info(Oid relationObjectId,
*hasindex = (relation->relhasindex) ? true : false;
*pages = relation->relpages;
*tuples = relation->reltuples;
+ ReleaseSysCache(relationTuple);
}
/*
@@ -100,9 +101,9 @@ find_secondary_indexes(Oid relationObjectId)
Oid relam;
uint16 amorderstrategy;
- indexTuple = SearchSysCacheTupleCopy(INDEXRELID,
- ObjectIdGetDatum(indexoid),
- 0, 0, 0);
+ indexTuple = SearchSysCache(INDEXRELID,
+ ObjectIdGetDatum(indexoid),
+ 0, 0, 0);
if (!HeapTupleIsValid(indexTuple))
elog(ERROR, "find_secondary_indexes: index %u not found",
indexoid);
@@ -162,20 +163,22 @@ find_secondary_indexes(Oid relationObjectId)
Form_pg_amop amop;
amopTuple =
- SearchSysCacheTuple(AMOPSTRATEGY,
- ObjectIdGetDatum(relam),
- ObjectIdGetDatum(index->indclass[i]),
- UInt16GetDatum(amorderstrategy),
- 0);
+ SearchSysCache(AMOPSTRATEGY,
+ ObjectIdGetDatum(relam),
+ ObjectIdGetDatum(index->indclass[i]),
+ UInt16GetDatum(amorderstrategy),
+ 0);
if (!HeapTupleIsValid(amopTuple))
elog(ERROR, "find_secondary_indexes: no amop %u %u %d",
- relam, index->indclass[i], (int) amorderstrategy);
+ relam, index->indclass[i],
+ (int) amorderstrategy);
amop = (Form_pg_amop) GETSTRUCT(amopTuple);
info->ordering[i] = amop->amopopr;
+ ReleaseSysCache(amopTuple);
}
}
- heap_freetuple(indexTuple);
+ ReleaseSysCache(indexTuple);
indexinfos = lcons(info, indexinfos);
}
@@ -315,13 +318,16 @@ find_inheritance_children(Oid inhparent)
bool
has_subclass(Oid relationId)
{
- HeapTuple tuple =
- SearchSysCacheTuple(RELOID,
- ObjectIdGetDatum(relationId),
- 0, 0, 0);
+ HeapTuple tuple;
+ bool result;
+ tuple = SearchSysCache(RELOID,
+ ObjectIdGetDatum(relationId),
+ 0, 0, 0);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "has_subclass: Relation %u not found",
- relationId);
- return ((Form_pg_class) GETSTRUCT(tuple))->relhassubclass;
+ elog(ERROR, "has_subclass: Relation %u not found", relationId);
+
+ result = ((Form_pg_class) GETSTRUCT(tuple))->relhassubclass;
+ ReleaseSysCache(tuple);
+ return result;
}