1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00

Massive commit to run PGINDENT on all *.c and *.h files.

This commit is contained in:
Bruce Momjian
1997-09-07 05:04:48 +00:00
parent 8fecd4febf
commit 1ccd423235
687 changed files with 150775 additions and 136888 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
/*-------------------------------------------------------------------------
*
* fcache.c--
* Code for the 'function cache' used in Oper and Func nodes....
* Code for the 'function cache' used in Oper and Func nodes....
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.4 1996/11/10 03:03:22 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/fcache.c,v 1.5 1997/09/07 04:52:59 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -23,23 +23,24 @@
#include "catalog/pg_proc.h"
#include "catalog/pg_language.h"
#include "catalog/pg_class.h"
#include "parser/parsetree.h" /* for getrelname() */
#include "parser/parsetree.h" /* for getrelname() */
#include "utils/builtins.h"
#include "utils/fcache.h"
#include "utils/fcache2.h"
#include "nodes/primnodes.h"
#include "nodes/execnodes.h"
#ifndef HAVE_MEMMOVE
# include <regex/utils.h>
#include <regex/utils.h>
#else
# include <string.h>
#include <string.h>
#endif
static Oid GetDynamicFuncArgType(Var *arg, ExprContext *econtext);
static FunctionCachePtr init_fcache(Oid foid,
bool use_syscache,
List *argList,
ExprContext *econtext);
static Oid GetDynamicFuncArgType(Var * arg, ExprContext * econtext);
static FunctionCachePtr
init_fcache(Oid foid,
bool use_syscache,
List * argList,
ExprContext * econtext);
/*-----------------------------------------------------------------
*
@ -47,259 +48,269 @@ static FunctionCachePtr init_fcache(Oid foid,
*
*
* NOTE: This function can be called when the system cache is being
* initialized. Therefore, use_syscache should ONLY be true
* when the function return type is interesting (ie: set_fcache).
* initialized. Therefore, use_syscache should ONLY be true
* when the function return type is interesting (ie: set_fcache).
*-----------------------------------------------------------------
*/
#define FuncArgTypeIsDynamic(arg) \
(IsA(arg,Var) && ((Var*)arg)->varattno == InvalidAttrNumber)
(IsA(arg,Var) && ((Var*)arg)->varattno == InvalidAttrNumber)
static Oid
GetDynamicFuncArgType(Var *arg, ExprContext *econtext)
static Oid
GetDynamicFuncArgType(Var * arg, ExprContext * econtext)
{
char *relname;
int rtid;
HeapTuple tup;
Assert(IsA(arg,Var));
rtid = ((Var*)arg)->varno;
relname = (char*)getrelname(rtid, econtext->ecxt_range_table);
char *relname;
int rtid;
HeapTuple tup;
tup = SearchSysCacheTuple(TYPNAME, PointerGetDatum(relname),
0,0,0);
if (!tup)
elog(WARN, "Lookup failed on type tuple for class %s",
relname);
return tup->t_oid;
Assert(IsA(arg, Var));
rtid = ((Var *) arg)->varno;
relname = (char *) getrelname(rtid, econtext->ecxt_range_table);
tup = SearchSysCacheTuple(TYPNAME, PointerGetDatum(relname),
0, 0, 0);
if (!tup)
elog(WARN, "Lookup failed on type tuple for class %s",
relname);
return tup->t_oid;
}
static FunctionCachePtr
static FunctionCachePtr
init_fcache(Oid foid,
bool use_syscache,
List *argList,
ExprContext *econtext)
bool use_syscache,
List * argList,
ExprContext * econtext)
{
HeapTuple procedureTuple;
HeapTuple typeTuple;
Form_pg_proc procedureStruct;
TypeTupleForm typeStruct;
FunctionCachePtr retval;
text *tmp;
int nargs;
/* ----------------
* get the procedure tuple corresponding to the given
* functionOid. If this fails, returnValue has been
* pre-initialized to "null" so we just return it.
* ----------------
*/
retval = (FunctionCachePtr) palloc(sizeof(FunctionCache));
if (!use_syscache)
elog(WARN, "what the ????, init the fcache without the catalogs?");
procedureTuple = SearchSysCacheTuple(PROOID,
ObjectIdGetDatum(foid),
0,0,0);
if (!HeapTupleIsValid(procedureTuple))
elog(WARN,
"init_fcache: %s %d",
"Cache lookup failed for procedure", foid);
/* ----------------
* get the return type from the procedure tuple
* ----------------
*/
procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
/* ----------------
* get the type tuple corresponding to the return type
* If this fails, returnValue has been pre-initialized
* to "null" so we just return it.
* ----------------
*/
typeTuple = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(procedureStruct->prorettype),
0,0,0);
if (!HeapTupleIsValid(typeTuple))
elog(WARN,
"init_fcache: %s %d",
"Cache lookup failed for type",
(procedureStruct)->prorettype);
/* ----------------
* get the type length and by-value from the type tuple and
* save the information in our one element cache.
* ----------------
*/
typeStruct = (TypeTupleForm) GETSTRUCT(typeTuple);
retval->typlen = (typeStruct)->typlen;
if ((typeStruct)->typrelid == InvalidOid) {
/* The return type is not a relation, so just use byval */
retval->typbyval = (typeStruct)->typbyval ? true : false ;
} else {
/* This is a hack. We assume here that any function returning
* a relation returns it by reference. This needs to be
* fixed.
HeapTuple procedureTuple;
HeapTuple typeTuple;
Form_pg_proc procedureStruct;
TypeTupleForm typeStruct;
FunctionCachePtr retval;
text *tmp;
int nargs;
/* ----------------
* get the procedure tuple corresponding to the given
* functionOid. If this fails, returnValue has been
* pre-initialized to "null" so we just return it.
* ----------------
*/
retval->typbyval = false;
}
retval->foid = foid;
retval->language = procedureStruct->prolang;
retval->func_state = (char *)NULL;
retval->setArg = NULL;
retval->hasSetArg = false;
retval->oneResult = ! procedureStruct->proretset;
retval->istrusted = procedureStruct->proistrusted;
/*
* If we are returning exactly one result then we have to copy
* tuples and by reference results because we have to end the execution
* before we return the results. When you do this everything allocated
* by the executor (i.e. slots and tuples) is freed.
*/
if ((retval->language == SQLlanguageId) &&
(retval->oneResult) &&
!(retval->typbyval))
retval = (FunctionCachePtr) palloc(sizeof(FunctionCache));
if (!use_syscache)
elog(WARN, "what the ????, init the fcache without the catalogs?");
procedureTuple = SearchSysCacheTuple(PROOID,
ObjectIdGetDatum(foid),
0, 0, 0);
if (!HeapTupleIsValid(procedureTuple))
elog(WARN,
"init_fcache: %s %d",
"Cache lookup failed for procedure", foid);
/* ----------------
* get the return type from the procedure tuple
* ----------------
*/
procedureStruct = (Form_pg_proc) GETSTRUCT(procedureTuple);
/* ----------------
* get the type tuple corresponding to the return type
* If this fails, returnValue has been pre-initialized
* to "null" so we just return it.
* ----------------
*/
typeTuple = SearchSysCacheTuple(TYPOID,
ObjectIdGetDatum(procedureStruct->prorettype),
0, 0, 0);
if (!HeapTupleIsValid(typeTuple))
elog(WARN,
"init_fcache: %s %d",
"Cache lookup failed for type",
(procedureStruct)->prorettype);
/* ----------------
* get the type length and by-value from the type tuple and
* save the information in our one element cache.
* ----------------
*/
typeStruct = (TypeTupleForm) GETSTRUCT(typeTuple);
retval->typlen = (typeStruct)->typlen;
if ((typeStruct)->typrelid == InvalidOid)
{
Form_pg_class relationStruct;
HeapTuple relationTuple;
TupleDesc td;
TupleTableSlot *slot;
slot = makeNode(TupleTableSlot);
slot->ttc_shouldFree = true;
slot->ttc_descIsNew = true;
slot->ttc_tupleDescriptor = (TupleDesc) NULL;
slot->ttc_buffer = InvalidBuffer;
slot->ttc_whichplan = -1;
retval->funcSlot = (Pointer)slot;
relationTuple = (HeapTuple)
SearchSysCacheTuple(RELNAME,
PointerGetDatum(&typeStruct->typname),
0,0,0);
if (relationTuple)
{
relationStruct = (Form_pg_class)GETSTRUCT(relationTuple);
td = CreateTemplateTupleDesc(relationStruct->relnatts);
}
else
td = CreateTemplateTupleDesc(1);
((TupleTableSlot*)retval->funcSlot)->ttc_tupleDescriptor = td;
/* The return type is not a relation, so just use byval */
retval->typbyval = (typeStruct)->typbyval ? true : false;
}
else
retval->funcSlot = (char *)NULL;
nargs = procedureStruct->pronargs;
retval->nargs = nargs;
if (nargs > 0)
else
{
Oid *argTypes;
retval->nullVect = (bool *)palloc((retval->nargs)*sizeof(bool));
if (retval->language == SQLlanguageId)
/*
* This is a hack. We assume here that any function returning a
* relation returns it by reference. This needs to be fixed.
*/
retval->typbyval = false;
}
retval->foid = foid;
retval->language = procedureStruct->prolang;
retval->func_state = (char *) NULL;
retval->setArg = NULL;
retval->hasSetArg = false;
retval->oneResult = !procedureStruct->proretset;
retval->istrusted = procedureStruct->proistrusted;
/*
* If we are returning exactly one result then we have to copy tuples
* and by reference results because we have to end the execution
* before we return the results. When you do this everything
* allocated by the executor (i.e. slots and tuples) is freed.
*/
if ((retval->language == SQLlanguageId) &&
(retval->oneResult) &&
!(retval->typbyval))
{
Form_pg_class relationStruct;
HeapTuple relationTuple;
TupleDesc td;
TupleTableSlot *slot;
slot = makeNode(TupleTableSlot);
slot->ttc_shouldFree = true;
slot->ttc_descIsNew = true;
slot->ttc_tupleDescriptor = (TupleDesc) NULL;
slot->ttc_buffer = InvalidBuffer;
slot->ttc_whichplan = -1;
retval->funcSlot = (Pointer) slot;
relationTuple = (HeapTuple)
SearchSysCacheTuple(RELNAME,
PointerGetDatum(&typeStruct->typname),
0, 0, 0);
if (relationTuple)
{
int i;
List *oneArg;
retval->argOidVect =
(Oid *)palloc(retval->nargs*sizeof(Oid));
argTypes = procedureStruct->proargtypes;
memmove(retval->argOidVect,
argTypes,
(retval->nargs)*sizeof(Oid));
for (i=0;
argList;
i++, argList = lnext(argList))
relationStruct = (Form_pg_class) GETSTRUCT(relationTuple);
td = CreateTemplateTupleDesc(relationStruct->relnatts);
}
else
td = CreateTemplateTupleDesc(1);
((TupleTableSlot *) retval->funcSlot)->ttc_tupleDescriptor = td;
}
else
retval->funcSlot = (char *) NULL;
nargs = procedureStruct->pronargs;
retval->nargs = nargs;
if (nargs > 0)
{
Oid *argTypes;
retval->nullVect = (bool *) palloc((retval->nargs) * sizeof(bool));
if (retval->language == SQLlanguageId)
{
int i;
List *oneArg;
retval->argOidVect =
(Oid *) palloc(retval->nargs * sizeof(Oid));
argTypes = procedureStruct->proargtypes;
memmove(retval->argOidVect,
argTypes,
(retval->nargs) * sizeof(Oid));
for (i = 0;
argList;
i++, argList = lnext(argList))
{
oneArg = lfirst(argList);
if (FuncArgTypeIsDynamic(oneArg))
retval->argOidVect[i] = GetDynamicFuncArgType((Var*)oneArg,
econtext);
oneArg = lfirst(argList);
if (FuncArgTypeIsDynamic(oneArg))
retval->argOidVect[i] = GetDynamicFuncArgType((Var *) oneArg,
econtext);
}
}
else
retval->argOidVect = (Oid *)NULL;
else
retval->argOidVect = (Oid *) NULL;
}
else
else
{
retval->argOidVect = (Oid *)NULL;
retval->nullVect = (BoolPtr)NULL;
retval->argOidVect = (Oid *) NULL;
retval->nullVect = (BoolPtr) NULL;
}
/*
* XXX this is the first varlena in the struct. If the order
* changes for some reason this will fail.
*/
if (procedureStruct->prolang == SQLlanguageId)
/*
* XXX this is the first varlena in the struct. If the order changes
* for some reason this will fail.
*/
if (procedureStruct->prolang == SQLlanguageId)
{
retval->src = textout(&(procedureStruct->prosrc));
retval->bin = (char *) NULL;
}
else
{
/*
* I'm not sure that we even need to do this at all.
*/
/*
* We do for untrusted functions.
*/
if (procedureStruct->proistrusted)
retval->src = textout(&(procedureStruct->prosrc));
retval->bin = (char *) NULL;
else {
tmp = (text *)
SearchSysCacheGetAttribute(PROOID,
Anum_pg_proc_probin,
ObjectIdGetDatum(foid),
0,0,0);
retval->bin = textout(tmp);
}
retval->src = (char *) NULL;
}
if (retval->language != SQLlanguageId)
fmgr_info(foid, &(retval->func), &(retval->nargs));
else
retval->func = (func_ptr)NULL;
return(retval);
else
{
/*
* I'm not sure that we even need to do this at all.
*/
/*
* We do for untrusted functions.
*/
if (procedureStruct->proistrusted)
retval->bin = (char *) NULL;
else
{
tmp = (text *)
SearchSysCacheGetAttribute(PROOID,
Anum_pg_proc_probin,
ObjectIdGetDatum(foid),
0, 0, 0);
retval->bin = textout(tmp);
}
retval->src = (char *) NULL;
}
if (retval->language != SQLlanguageId)
fmgr_info(foid, &(retval->func), &(retval->nargs));
else
retval->func = (func_ptr) NULL;
return (retval);
}
void
setFcache(Node *node, Oid foid, List *argList, ExprContext *econtext)
setFcache(Node * node, Oid foid, List * argList, ExprContext * econtext)
{
Func *fnode;
Oper *onode;
FunctionCachePtr fcache;
fcache = init_fcache(foid, true, argList, econtext);
if (IsA(node,Oper)) {
onode = (Oper*) node;
onode->op_fcache = fcache;
}else if (IsA(node,Func)) {
fnode = (Func*) node;
fnode->func_fcache = fcache;
}else {
elog(WARN, "init_fcache: node must be Oper or Func!");
}
Func *fnode;
Oper *onode;
FunctionCachePtr fcache;
fcache = init_fcache(foid, true, argList, econtext);
if (IsA(node, Oper))
{
onode = (Oper *) node;
onode->op_fcache = fcache;
}
else if (IsA(node, Func))
{
fnode = (Func *) node;
fnode->func_fcache = fcache;
}
else
{
elog(WARN, "init_fcache: node must be Oper or Func!");
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,20 +1,20 @@
/*-------------------------------------------------------------------------
*
* lsyscache.c--
* Routines to access information within system caches
* Routines to access information within system caches
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.3 1997/08/19 21:35:11 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.4 1997/09/07 04:53:04 momjian Exp $
*
* NOTES
* Eventually, the index information should go through here, too.
*
* Most of these routines call SearchSysCacheStruct() and thus simply
* (1) allocate some space for the return struct and (2) call it.
*
* Eventually, the index information should go through here, too.
*
* Most of these routines call SearchSysCacheStruct() and thus simply
* (1) allocate some space for the return struct and (2) call it.
*
*-------------------------------------------------------------------------
*/
#include <string.h>
@ -34,99 +34,100 @@
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
/* ---------- AMOP CACHES ---------- */
/* ---------- AMOP CACHES ---------- */
/*
/*
* op_class -
*
* Return t iff operator 'opno' is in operator class 'opclass'.
*
*
* Return t iff operator 'opno' is in operator class 'opclass'.
*
*/
bool
op_class(Oid opno, int32 opclass, Oid amopid)
{
FormData_pg_amop amoptup;
FormData_pg_amop amoptup;
if (SearchSysCacheStruct(AMOPOPID,
(char *) &amoptup,
ObjectIdGetDatum(opclass),
ObjectIdGetDatum(opno),
ObjectIdGetDatum(amopid),
0))
return(true);
else
return(false);
if (SearchSysCacheStruct(AMOPOPID,
(char *) &amoptup,
ObjectIdGetDatum(opclass),
ObjectIdGetDatum(opno),
ObjectIdGetDatum(amopid),
0))
return (true);
else
return (false);
}
/* ---------- ATTRIBUTE CACHES ---------- */
/* ---------- ATTRIBUTE CACHES ---------- */
/*
/*
* get_attname -
*
* Given the relation id and the attribute number,
* return the "attname" field from the attribute relation.
*
*
* Given the relation id and the attribute number,
* return the "attname" field from the attribute relation.
*
*/
char*
char *
get_attname(Oid relid, AttrNumber attnum)
{
FormData_pg_attribute att_tup;
char *retval;
FormData_pg_attribute att_tup;
char *retval;
if (SearchSysCacheStruct(ATTNUM,
(char*)&att_tup,
ObjectIdGetDatum(relid),
UInt16GetDatum(attnum),
0,0)) {
retval = pstrdup(att_tup.attname.data);
if (SearchSysCacheStruct(ATTNUM,
(char *) &att_tup,
ObjectIdGetDatum(relid),
UInt16GetDatum(attnum),
0, 0))
{
retval = pstrdup(att_tup.attname.data);
return(retval);
}
else
return(NULL);
return (retval);
}
else
return (NULL);
}
/*
/*
* get_attnum -
*
* Given the relation id and the attribute name,
* return the "attnum" field from the attribute relation.
*
*
* Given the relation id and the attribute name,
* return the "attnum" field from the attribute relation.
*
*/
AttrNumber
get_attnum(Oid relid, char *attname)
{
FormData_pg_attribute att_tup;
FormData_pg_attribute att_tup;
if (SearchSysCacheStruct(ATTNAME, (char *) &att_tup,
ObjectIdGetDatum(relid),
PointerGetDatum(attname),
0,0))
return(att_tup.attnum);
else
return(InvalidAttrNumber);
if (SearchSysCacheStruct(ATTNAME, (char *) &att_tup,
ObjectIdGetDatum(relid),
PointerGetDatum(attname),
0, 0))
return (att_tup.attnum);
else
return (InvalidAttrNumber);
}
/*
/*
* get_atttype -
*
* Given the relation OID and the attribute number with the relation,
* return the attribute type OID.
*
*
* Given the relation OID and the attribute number with the relation,
* return the attribute type OID.
*
*/
Oid
get_atttype(Oid relid, AttrNumber attnum)
{
AttributeTupleForm att_tup = (AttributeTupleForm)palloc(sizeof(*att_tup));
AttributeTupleForm att_tup = (AttributeTupleForm) palloc(sizeof(*att_tup));
if (SearchSysCacheStruct(ATTNUM,
(char *) att_tup,
ObjectIdGetDatum(relid),
UInt16GetDatum(attnum),
0,0))
return(att_tup->atttypid);
else
return((Oid)NULL);
if (SearchSysCacheStruct(ATTNUM,
(char *) att_tup,
ObjectIdGetDatum(relid),
UInt16GetDatum(attnum),
0, 0))
return (att_tup->atttypid);
else
return ((Oid) NULL);
}
/* This routine uses the attname instead of the attnum because it
@ -136,353 +137,366 @@ get_atttype(Oid relid, AttrNumber attnum)
bool
get_attisset(Oid relid, char *attname)
{
HeapTuple htup;
AttrNumber attno;
AttributeTupleForm att_tup;
HeapTuple htup;
AttrNumber attno;
AttributeTupleForm att_tup;
attno = get_attnum(relid, attname);
htup = SearchSysCacheTuple(ATTNAME,
ObjectIdGetDatum(relid),
PointerGetDatum(attname),
0,0);
if (!HeapTupleIsValid(htup))
elog(WARN, "get_attisset: no attribute %.16s in relation %d",
attname, relid);
if (heap_attisnull(htup, attno))
return(false);
else {
att_tup = (AttributeTupleForm)GETSTRUCT(htup);
return(att_tup->attisset);
}
attno = get_attnum(relid, attname);
htup = SearchSysCacheTuple(ATTNAME,
ObjectIdGetDatum(relid),
PointerGetDatum(attname),
0, 0);
if (!HeapTupleIsValid(htup))
elog(WARN, "get_attisset: no attribute %.16s in relation %d",
attname, relid);
if (heap_attisnull(htup, attno))
return (false);
else
{
att_tup = (AttributeTupleForm) GETSTRUCT(htup);
return (att_tup->attisset);
}
}
/* ---------- INDEX CACHE ---------- */
/* ---------- INDEX CACHE ---------- */
/* watch this space...
/* watch this space...
*/
/* ---------- OPERATOR CACHE ---------- */
/* ---------- OPERATOR CACHE ---------- */
/*
/*
* get_opcode -
*
* Returns the regproc id of the routine used to implement an
* operator given the operator uid.
*
*
* Returns the regproc id of the routine used to implement an
* operator given the operator uid.
*
*/
RegProcedure
get_opcode(Oid opno)
{
FormData_pg_operator optup;
FormData_pg_operator optup;
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0,0,0))
return(optup.oprcode);
else
return((RegProcedure)NULL);
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0, 0, 0))
return (optup.oprcode);
else
return ((RegProcedure) NULL);
}
/*
* get_opname -
* returns the name of the operator with the given opno
* returns the name of the operator with the given opno
*
* Note: return the struct so that it gets copied.
*/
char*
char *
get_opname(Oid opno)
{
FormData_pg_operator optup;
FormData_pg_operator optup;
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0,0,0))
return (pstrdup(optup.oprname.data));
else {
elog(WARN, "can't look up operator %d\n", opno);
return NULL;
}
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0, 0, 0))
return (pstrdup(optup.oprname.data));
else
{
elog(WARN, "can't look up operator %d\n", opno);
return NULL;
}
}
/*
/*
* op_mergesortable -
*
* Returns the left and right sort operators and types corresponding to a
* mergesortable operator, or nil if the operator is not mergesortable.
*
*
* Returns the left and right sort operators and types corresponding to a
* mergesortable operator, or nil if the operator is not mergesortable.
*
*/
bool
op_mergesortable(Oid opno, Oid ltype, Oid rtype, Oid *leftOp, Oid *rightOp)
op_mergesortable(Oid opno, Oid ltype, Oid rtype, Oid * leftOp, Oid * rightOp)
{
FormData_pg_operator optup;
FormData_pg_operator optup;
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0,0,0) &&
optup.oprlsortop &&
optup.oprrsortop &&
optup.oprleft == ltype &&
optup.oprright == rtype) {
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0, 0, 0) &&
optup.oprlsortop &&
optup.oprrsortop &&
optup.oprleft == ltype &&
optup.oprright == rtype)
{
*leftOp = ObjectIdGetDatum(optup.oprlsortop);
*rightOp = ObjectIdGetDatum(optup.oprrsortop);
return TRUE;
} else {
return FALSE;
}
*leftOp = ObjectIdGetDatum(optup.oprlsortop);
*rightOp = ObjectIdGetDatum(optup.oprrsortop);
return TRUE;
}
else
{
return FALSE;
}
}
/*
/*
* op_hashjoinable--
*
* Returns the hash operator corresponding to a hashjoinable operator,
*
* Returns the hash operator corresponding to a hashjoinable operator,
* or nil if the operator is not hashjoinable.
*
*
*/
Oid
op_hashjoinable(Oid opno, Oid ltype, Oid rtype)
{
FormData_pg_operator optup;
FormData_pg_operator optup;
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0,0,0) &&
optup.oprcanhash &&
optup.oprleft == ltype &&
optup.oprright == rtype)
return(opno);
else
return(InvalidOid);
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0, 0, 0) &&
optup.oprcanhash &&
optup.oprleft == ltype &&
optup.oprright == rtype)
return (opno);
else
return (InvalidOid);
}
/*
/*
* get_commutator -
*
* Returns the corresponding commutator of an operator.
*
*
* Returns the corresponding commutator of an operator.
*
*/
Oid
get_commutator(Oid opno)
{
FormData_pg_operator optup;
FormData_pg_operator optup;
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0,0,0))
return(optup.oprcom);
else
return((Oid)NULL);
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0, 0, 0))
return (optup.oprcom);
else
return ((Oid) NULL);
}
HeapTuple
get_operator_tuple(Oid opno)
{
HeapTuple optup;
HeapTuple optup;
if ((optup = SearchSysCacheTuple(OPROID,
ObjectIdGetDatum(opno),
0,0,0)))
return(optup);
else
return((HeapTuple)NULL);
if ((optup = SearchSysCacheTuple(OPROID,
ObjectIdGetDatum(opno),
0, 0, 0)))
return (optup);
else
return ((HeapTuple) NULL);
}
/*
/*
* get_negator -
*
* Returns the corresponding negator of an operator.
*
*
* Returns the corresponding negator of an operator.
*
*/
Oid
get_negator(Oid opno)
{
FormData_pg_operator optup;
FormData_pg_operator optup;
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0,0,0))
return(optup.oprnegate);
else
return((Oid)NULL);
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0, 0, 0))
return (optup.oprnegate);
else
return ((Oid) NULL);
}
/*
/*
* get_oprrest -
*
* Returns procedure id for computing selectivity of an operator.
*
*
* Returns procedure id for computing selectivity of an operator.
*
*/
RegProcedure
get_oprrest(Oid opno)
{
FormData_pg_operator optup;
FormData_pg_operator optup;
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0,0,0))
return(optup.oprrest );
else
return((RegProcedure) NULL);
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0, 0, 0))
return (optup.oprrest);
else
return ((RegProcedure) NULL);
}
/*
/*
* get_oprjoin -
*
* Returns procedure id for computing selectivity of a join.
*
*
* Returns procedure id for computing selectivity of a join.
*
*/
RegProcedure
get_oprjoin(Oid opno)
{
FormData_pg_operator optup;
FormData_pg_operator optup;
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0,0,0))
return(optup.oprjoin);
else
return((RegProcedure)NULL);
if (SearchSysCacheStruct(OPROID, (char *) &optup,
ObjectIdGetDatum(opno),
0, 0, 0))
return (optup.oprjoin);
else
return ((RegProcedure) NULL);
}
/* ---------- RELATION CACHE ---------- */
/* ---------- RELATION CACHE ---------- */
/*
/*
* get_relnatts -
*
* Returns the number of attributes for a given relation.
*
*
* Returns the number of attributes for a given relation.
*
*/
int
get_relnatts(Oid relid)
{
FormData_pg_class reltup;
FormData_pg_class reltup;
if (SearchSysCacheStruct(RELOID, (char *) &reltup,
ObjectIdGetDatum(relid),
0,0,0))
return(reltup.relnatts);
else
return(InvalidAttrNumber);
if (SearchSysCacheStruct(RELOID, (char *) &reltup,
ObjectIdGetDatum(relid),
0, 0, 0))
return (reltup.relnatts);
else
return (InvalidAttrNumber);
}
/*
/*
* get_rel_name -
*
* Returns the name of a given relation.
*
*
* Returns the name of a given relation.
*
*/
char*
char *
get_rel_name(Oid relid)
{
FormData_pg_class reltup;
FormData_pg_class reltup;
if ((SearchSysCacheStruct(RELOID,
(char*)&reltup,
ObjectIdGetDatum(relid),
0,0,0))) {
return (pstrdup(reltup.relname.data));
} else
return(NULL);
if ((SearchSysCacheStruct(RELOID,
(char *) &reltup,
ObjectIdGetDatum(relid),
0, 0, 0)))
{
return (pstrdup(reltup.relname.data));
}
else
return (NULL);
}
/* ---------- TYPE CACHE ---------- */
/* ---------- TYPE CACHE ---------- */
/*
/*
* get_typlen -
*
* Given the type OID, return the length of the type.
*
*
* Given the type OID, return the length of the type.
*
*/
int16
get_typlen(Oid typid)
{
TypeTupleFormData typtup;
TypeTupleFormData typtup;
if (SearchSysCacheStruct(TYPOID, (char *) &typtup,
ObjectIdGetDatum(typid),
0,0,0))
return(typtup.typlen);
else
return((int16)NULL);
if (SearchSysCacheStruct(TYPOID, (char *) &typtup,
ObjectIdGetDatum(typid),
0, 0, 0))
return (typtup.typlen);
else
return ((int16) NULL);
}
/*
/*
* get_typbyval -
*
* Given the type OID, determine whether the type is returned by value or
* not. Returns 1 if by value, 0 if by reference.
*
*
* Given the type OID, determine whether the type is returned by value or
* not. Returns 1 if by value, 0 if by reference.
*
*/
bool
get_typbyval(Oid typid)
{
TypeTupleFormData typtup;
TypeTupleFormData typtup;
if (SearchSysCacheStruct(TYPOID, (char *) &typtup,
ObjectIdGetDatum(typid),
0,0,0))
return((bool)typtup.typbyval);
else
return(false);
if (SearchSysCacheStruct(TYPOID, (char *) &typtup,
ObjectIdGetDatum(typid),
0, 0, 0))
return ((bool) typtup.typbyval);
else
return (false);
}
/*
/*
* get_typbyval -
*
* Given the type OID, determine whether the type is returned by value or
* not. Returns 1 if by value, 0 if by reference.
*
*
* Given the type OID, determine whether the type is returned by value or
* not. Returns 1 if by value, 0 if by reference.
*
*/
#ifdef NOT_USED
char
get_typalign(Oid typid)
{
TypeTupleFormData typtup;
TypeTupleFormData typtup;
if (SearchSysCacheStruct(TYPOID, (char *) &typtup,
ObjectIdGetDatum(typid),
0,0,0))
return(typtup.typalign);
else
return ('i');
if (SearchSysCacheStruct(TYPOID, (char *) &typtup,
ObjectIdGetDatum(typid),
0, 0, 0))
return (typtup.typalign);
else
return ('i');
}
#endif
/*
* get_typdefault -
*
* Given the type OID, return the default value of the ADT.
*
/*
* get_typdefault -
*
* Given the type OID, return the default value of the ADT.
*
*/
struct varlena *
get_typdefault(Oid typid)
{
struct varlena *typdefault =
(struct varlena *)TypeDefaultRetrieve (typid);
return(typdefault);
struct varlena *typdefault =
(struct varlena *) TypeDefaultRetrieve(typid);
return (typdefault);
}
/*
/*
* get_typtype -
*
* Given the type OID, find if it is a basic type, a named relation
* or the generic type 'relation'.
* It returns the null char if the cache lookup fails...
*
*
* Given the type OID, find if it is a basic type, a named relation
* or the generic type 'relation'.
* It returns the null char if the cache lookup fails...
*
*/
#ifdef NOT_USED
char
get_typtype(Oid typid)
{
TypeTupleFormData typtup;
TypeTupleFormData typtup;
if (SearchSysCacheStruct(TYPOID, (char *) &typtup,
ObjectIdGetDatum(typid),
0,0,0)) {
return(typtup.typtype);
} else {
return('\0');
}
if (SearchSysCacheStruct(TYPOID, (char *) &typtup,
ObjectIdGetDatum(typid),
0, 0, 0))
{
return (typtup.typtype);
}
else
{
return ('\0');
}
}
#endif

View File

@ -1,13 +1,13 @@
/*-------------------------------------------------------------------------
*
* rel.c--
* POSTGRES relation descriptor code.
* POSTGRES relation descriptor code.
*
* Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/rel.c,v 1.1.1.1 1996/07/09 06:22:06 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/rel.c,v 1.2 1997/09/07 04:53:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -21,57 +21,56 @@
#include "storage/fd.h"
/*
* RelationIsValid is now a macro in rel.h -cim 4/27/91
/*
* RelationIsValid is now a macro in rel.h -cim 4/27/91
*
* Many of the RelationGet...() functions are now macros in rel.h
* -mer 3/2/92
* Many of the RelationGet...() functions are now macros in rel.h
* -mer 3/2/92
*/
/*
* RelationGetIndexStrategy --
* Returns index strategy for a relation.
* Returns index strategy for a relation.
*
* Note:
* Assumes relation descriptor is valid.
* Assumes relation descriptor is for an index relation.
* Assumes relation descriptor is valid.
* Assumes relation descriptor is for an index relation.
*/
IndexStrategy
RelationGetIndexStrategy(Relation relation)
{
return relation->rd_istrat;
return relation->rd_istrat;
}
/*
* RelationSetIndexSupport --
* Sets index strategy and support info for a relation.
* Sets index strategy and support info for a relation.
*
* Note:
* Assumes relation descriptor is a valid pointer to sufficient space.
* Assumes index strategy is valid. Assumes support is valid if non-
* NULL.
* Assumes relation descriptor is a valid pointer to sufficient space.
* Assumes index strategy is valid. Assumes support is valid if non-
* NULL.
*/
/* ----------------
* RelationSetIndexSupport
* RelationSetIndexSupport
*
* This routine saves two pointers -- one to the IndexStrategy, and
* one to the RegProcs that support the indexed access method. These
* pointers are stored in the space following the attribute data in the
* reldesc.
* This routine saves two pointers -- one to the IndexStrategy, and
* one to the RegProcs that support the indexed access method. These
* pointers are stored in the space following the attribute data in the
* reldesc.
*
* NEW: the index strategy and support are now stored in real fields
* at the end of the structure - jolly
* NEW: the index strategy and support are now stored in real fields
* at the end of the structure - jolly
* ----------------
*/
void
RelationSetIndexSupport(Relation relation,
IndexStrategy strategy,
RegProcedure *support)
IndexStrategy strategy,
RegProcedure * support)
{
Assert(PointerIsValid(relation));
Assert(IndexStrategyIsValid(strategy));
relation->rd_istrat = strategy;
relation->rd_support = support;
}
Assert(PointerIsValid(relation));
Assert(IndexStrategyIsValid(strategy));
relation->rd_istrat = strategy;
relation->rd_support = support;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff