mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
Thank god for searchable mail archives.
Patch by: wieck@sapserv.debis.de (Jan Wieck) One of the design rules of PostgreSQL is extensibility. And to follow this rule means (at least for me) that there should not only be a builtin PL. Instead I would prefer a defined interface for PL implemetations.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.37 1998/01/05 16:38:46 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.38 1998/01/15 19:42:36 pgsql Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -202,8 +202,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
||||
int32 attr_count,
|
||||
i;
|
||||
AttributeTupleForm *attr;
|
||||
func_ptr *out_functions;
|
||||
int dummy;
|
||||
FmgrInfo *out_functions;
|
||||
Oid out_func_oid;
|
||||
Oid *elements;
|
||||
Datum value;
|
||||
@@ -229,12 +228,12 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
||||
|
||||
if (!binary)
|
||||
{
|
||||
out_functions = (func_ptr *) palloc(attr_count * sizeof(func_ptr));
|
||||
out_functions = (FmgrInfo *) palloc(attr_count * sizeof(FmgrInfo));
|
||||
elements = (Oid *) palloc(attr_count * sizeof(Oid));
|
||||
for (i = 0; i < attr_count; i++)
|
||||
{
|
||||
out_func_oid = (Oid) GetOutputFunction(attr[i]->atttypid);
|
||||
fmgr_info(out_func_oid, &out_functions[i], &dummy);
|
||||
fmgr_info(out_func_oid, &out_functions[i]);
|
||||
elements[i] = GetTypeElement(attr[i]->atttypid);
|
||||
}
|
||||
nulls = NULL; /* meaningless, but compiler doesn't know
|
||||
@@ -272,7 +271,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
||||
{
|
||||
if (!isnull)
|
||||
{
|
||||
string = (char *) (out_functions[i]) (value, elements[i]);
|
||||
string = (char *) (*fmgr_faddr(&out_functions[i])) (value, elements[i]);
|
||||
CopyAttributeOut(fp, string, delim);
|
||||
pfree(string);
|
||||
}
|
||||
@@ -357,9 +356,8 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
||||
HeapTuple tuple;
|
||||
AttrNumber attr_count;
|
||||
AttributeTupleForm *attr;
|
||||
func_ptr *in_functions;
|
||||
int i,
|
||||
dummy;
|
||||
FmgrInfo *in_functions;
|
||||
int i;
|
||||
Oid in_func_oid;
|
||||
Datum *values;
|
||||
char *nulls,
|
||||
@@ -498,12 +496,12 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
||||
|
||||
if (!binary)
|
||||
{
|
||||
in_functions = (func_ptr *) palloc(attr_count * sizeof(func_ptr));
|
||||
in_functions = (FmgrInfo *) palloc(attr_count * sizeof(FmgrInfo));
|
||||
elements = (Oid *) palloc(attr_count * sizeof(Oid));
|
||||
for (i = 0; i < attr_count; i++)
|
||||
{
|
||||
in_func_oid = (Oid) GetInputFunction(attr[i]->atttypid);
|
||||
fmgr_info(in_func_oid, &in_functions[i], &dummy);
|
||||
fmgr_info(in_func_oid, &in_functions[i]);
|
||||
elements[i] = GetTypeElement(attr[i]->atttypid);
|
||||
}
|
||||
}
|
||||
@@ -574,7 +572,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
|
||||
else
|
||||
{
|
||||
values[i] =
|
||||
(Datum) (in_functions[i]) (string,
|
||||
(Datum) (*fmgr_faddr(&in_functions[i])) (string,
|
||||
elements[i],
|
||||
attr[i]->attlen);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.20 1998/01/05 16:38:58 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.21 1998/01/15 19:42:38 pgsql Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -277,8 +277,8 @@ RemoveType(char *typeName) /* type name to be removed */
|
||||
#endif
|
||||
|
||||
relation = heap_openr(TypeRelationName);
|
||||
fmgr_info(typeKey[0].sk_procedure, &typeKey[0].sk_func,
|
||||
&typeKey[0].sk_nargs);
|
||||
fmgr_info(typeKey[0].sk_procedure, &typeKey[0].sk_func);
|
||||
typeKey[0].sk_nargs = typeKey[0].sk_func.fn_nargs;
|
||||
|
||||
/* Delete the primary type */
|
||||
|
||||
@@ -387,7 +387,8 @@ RemoveFunction(char *functionName, /* function name to be removed */
|
||||
|
||||
key[0].sk_argument = PointerGetDatum(functionName);
|
||||
|
||||
fmgr_info(key[0].sk_procedure, &key[0].sk_func, &key[0].sk_nargs);
|
||||
fmgr_info(key[0].sk_procedure, &key[0].sk_func);
|
||||
key[0].sk_nargs = key[0].sk_func.fn_nargs;
|
||||
|
||||
relation = heap_openr(ProcedureRelationName);
|
||||
scan = heap_beginscan(relation, 0, false, 1, key);
|
||||
|
||||
@@ -43,7 +43,6 @@ static HeapTuple
|
||||
GetTupleForTrigger(Relation relation, ItemPointer tid,
|
||||
bool before);
|
||||
|
||||
extern void fmgr_info(Oid procedureId, func_ptr * function, int *nargs);
|
||||
extern GlobalMemory CacheCxt;
|
||||
|
||||
void
|
||||
@@ -413,8 +412,7 @@ RelationBuildTriggers(Relation relation)
|
||||
|
||||
build->tgname = nameout(&(pg_trigger->tgname));
|
||||
build->tgfoid = pg_trigger->tgfoid;
|
||||
build->tgfunc = NULL;
|
||||
build->tgplfunc = NULL;
|
||||
build->tgfunc.fn_addr = NULL;
|
||||
build->tgtype = pg_trigger->tgtype;
|
||||
build->tgnargs = pg_trigger->tgnargs;
|
||||
memcpy(build->tgattr, &(pg_trigger->tgattr), 8 * sizeof(int16));
|
||||
@@ -598,48 +596,17 @@ static HeapTuple
|
||||
ExecCallTriggerFunc(Trigger * trigger)
|
||||
{
|
||||
|
||||
if (trigger->tgfunc != NULL)
|
||||
if (trigger->tgfunc.fn_addr == NULL)
|
||||
{
|
||||
return (HeapTuple) ((*(trigger->tgfunc)) ());
|
||||
fmgr_info(trigger->tgfoid, &trigger->tgfunc);
|
||||
}
|
||||
|
||||
if (trigger->tgplfunc == NULL)
|
||||
{
|
||||
HeapTuple procTuple;
|
||||
HeapTuple langTuple;
|
||||
Form_pg_proc procStruct;
|
||||
Form_pg_language langStruct;
|
||||
int nargs;
|
||||
|
||||
procTuple = SearchSysCacheTuple(PROOID,
|
||||
ObjectIdGetDatum(trigger->tgfoid),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(procTuple))
|
||||
{
|
||||
elog(ERROR, "ExecCallTriggerFunc(): Cache lookup for proc %ld failed",
|
||||
ObjectIdGetDatum(trigger->tgfoid));
|
||||
}
|
||||
procStruct = (Form_pg_proc) GETSTRUCT(procTuple);
|
||||
|
||||
langTuple = SearchSysCacheTuple(LANOID,
|
||||
ObjectIdGetDatum(procStruct->prolang),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(langTuple))
|
||||
{
|
||||
elog(ERROR, "ExecCallTriggerFunc(): Cache lookup for language %ld failed",
|
||||
ObjectIdGetDatum(procStruct->prolang));
|
||||
}
|
||||
langStruct = (Form_pg_language) GETSTRUCT(langTuple);
|
||||
|
||||
if (langStruct->lanispl == false)
|
||||
{
|
||||
fmgr_info(trigger->tgfoid, &(trigger->tgfunc), &nargs);
|
||||
return (HeapTuple) ((*(trigger->tgfunc)) ());
|
||||
}
|
||||
fmgr_info(langStruct->lanplcallfoid, &(trigger->tgplfunc), &nargs);
|
||||
if (trigger->tgfunc.fn_plhandler != NULL) {
|
||||
return (HeapTuple) (*(trigger->tgfunc.fn_plhandler))
|
||||
(&trigger->tgfunc);
|
||||
}
|
||||
|
||||
return (HeapTuple) ((*(trigger->tgplfunc)) (trigger->tgfoid));
|
||||
return (HeapTuple) ((*fmgr_faddr(&trigger->tgfunc)) ());
|
||||
}
|
||||
|
||||
HeapTuple
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.57 1998/01/05 16:39:05 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.58 1998/01/15 19:42:40 pgsql Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -67,9 +67,9 @@ static int MESSAGE_LEVEL; /* message level */
|
||||
#define swapLong(a,b) {long tmp; tmp=a; a=b; b=tmp;}
|
||||
#define swapInt(a,b) {int tmp; tmp=a; a=b; b=tmp;}
|
||||
#define swapDatum(a,b) {Datum tmp; tmp=a; a=b; b=tmp;}
|
||||
#define VacAttrStatsEqValid(stats) ( stats->f_cmpeq != NULL )
|
||||
#define VacAttrStatsLtGtValid(stats) ( stats->f_cmplt != NULL && \
|
||||
stats->f_cmpgt != NULL && \
|
||||
#define VacAttrStatsEqValid(stats) ( stats->f_cmpeq.fn_addr != NULL )
|
||||
#define VacAttrStatsLtGtValid(stats) ( stats->f_cmplt.fn_addr != NULL && \
|
||||
stats->f_cmpgt.fn_addr != NULL && \
|
||||
RegProcedureIsValid(stats->outfunc) )
|
||||
|
||||
|
||||
@@ -484,35 +484,29 @@ vc_vacone(Oid relid, bool analyze, List *va_cols)
|
||||
func_operator = oper("=", stats->attr->atttypid, stats->attr->atttypid, true);
|
||||
if (func_operator != NULL)
|
||||
{
|
||||
int nargs;
|
||||
|
||||
pgopform = (OperatorTupleForm) GETSTRUCT(func_operator);
|
||||
fmgr_info(pgopform->oprcode, &(stats->f_cmpeq), &nargs);
|
||||
fmgr_info(pgopform->oprcode, &(stats->f_cmpeq));
|
||||
}
|
||||
else
|
||||
stats->f_cmpeq = NULL;
|
||||
stats->f_cmpeq.fn_addr = NULL;
|
||||
|
||||
func_operator = oper("<", stats->attr->atttypid, stats->attr->atttypid, true);
|
||||
if (func_operator != NULL)
|
||||
{
|
||||
int nargs;
|
||||
|
||||
pgopform = (OperatorTupleForm) GETSTRUCT(func_operator);
|
||||
fmgr_info(pgopform->oprcode, &(stats->f_cmplt), &nargs);
|
||||
fmgr_info(pgopform->oprcode, &(stats->f_cmplt));
|
||||
}
|
||||
else
|
||||
stats->f_cmplt = NULL;
|
||||
stats->f_cmplt.fn_addr = NULL;
|
||||
|
||||
func_operator = oper(">", stats->attr->atttypid, stats->attr->atttypid, true);
|
||||
if (func_operator != NULL)
|
||||
{
|
||||
int nargs;
|
||||
|
||||
pgopform = (OperatorTupleForm) GETSTRUCT(func_operator);
|
||||
fmgr_info(pgopform->oprcode, &(stats->f_cmpgt), &nargs);
|
||||
fmgr_info(pgopform->oprcode, &(stats->f_cmpgt));
|
||||
}
|
||||
else
|
||||
stats->f_cmpgt = NULL;
|
||||
stats->f_cmpgt.fn_addr = NULL;
|
||||
|
||||
pgttup = SearchSysCacheTuple(TYPOID,
|
||||
ObjectIdGetDatum(stats->attr->atttypid),
|
||||
@@ -1671,29 +1665,29 @@ vc_attrstats(Relation onerel, VRelStats *vacrelstats, HeapTuple htup)
|
||||
}
|
||||
if (VacAttrStatsLtGtValid(stats))
|
||||
{
|
||||
if ((*(stats->f_cmplt)) (value, stats->min))
|
||||
if ((*fmgr_faddr(&stats->f_cmplt)) (value, stats->min))
|
||||
{
|
||||
vc_bucketcpy(stats->attr, value, &stats->min, &stats->min_len);
|
||||
stats->min_cnt = 0;
|
||||
}
|
||||
if ((*(stats->f_cmpgt)) (value, stats->max))
|
||||
if ((*fmgr_faddr(&stats->f_cmpgt)) (value, stats->max))
|
||||
{
|
||||
vc_bucketcpy(stats->attr, value, &stats->max, &stats->max_len);
|
||||
stats->max_cnt = 0;
|
||||
}
|
||||
if ((*(stats->f_cmpeq)) (value, stats->min))
|
||||
if ((*fmgr_faddr(&stats->f_cmpeq)) (value, stats->min))
|
||||
stats->min_cnt++;
|
||||
else if ((*(stats->f_cmpeq)) (value, stats->max))
|
||||
else if ((*fmgr_faddr(&stats->f_cmpeq)) (value, stats->max))
|
||||
stats->max_cnt++;
|
||||
}
|
||||
if ((*(stats->f_cmpeq)) (value, stats->best))
|
||||
if ((*fmgr_faddr(&stats->f_cmpeq)) (value, stats->best))
|
||||
stats->best_cnt++;
|
||||
else if ((*(stats->f_cmpeq)) (value, stats->guess1))
|
||||
else if ((*fmgr_faddr(&stats->f_cmpeq)) (value, stats->guess1))
|
||||
{
|
||||
stats->guess1_cnt++;
|
||||
stats->guess1_hits++;
|
||||
}
|
||||
else if ((*(stats->f_cmpeq)) (value, stats->guess2))
|
||||
else if ((*fmgr_faddr(&stats->f_cmpeq)) (value, stats->guess2))
|
||||
stats->guess2_hits++;
|
||||
else
|
||||
value_hit = false;
|
||||
@@ -1880,9 +1874,8 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
|
||||
*
|
||||
pgcform->relname.data) */ )
|
||||
{
|
||||
func_ptr out_function;
|
||||
FmgrInfo out_function;
|
||||
char *out_string;
|
||||
int dummy;
|
||||
|
||||
for (i = 0; i < Natts_pg_statistic; ++i)
|
||||
nulls[i] = ' ';
|
||||
@@ -1895,11 +1888,11 @@ vc_updstats(Oid relid, int npages, int ntups, bool hasindex, VRelStats *vacrelst
|
||||
values[i++] = (Datum) relid; /* 1 */
|
||||
values[i++] = (Datum) attp->attnum; /* 2 */
|
||||
values[i++] = (Datum) InvalidOid; /* 3 */
|
||||
fmgr_info(stats->outfunc, &out_function, &dummy);
|
||||
out_string = (*out_function) (stats->min, stats->attr->atttypid);
|
||||
fmgr_info(stats->outfunc, &out_function);
|
||||
out_string = (*fmgr_faddr(&out_function)) (stats->min, stats->attr->atttypid);
|
||||
values[i++] = (Datum) fmgr(TextInRegProcedure, out_string);
|
||||
pfree(out_string);
|
||||
out_string = (char *) (*out_function) (stats->max, stats->attr->atttypid);
|
||||
out_string = (char *) (*fmgr_faddr(&out_function)) (stats->max, stats->attr->atttypid);
|
||||
values[i++] = (Datum) fmgr(TextInRegProcedure, out_string);
|
||||
pfree(out_string);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user