mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
Operators live in namespaces. CREATE/DROP/COMMENT ON OPERATOR take
qualified operator names directly, for example CREATE OPERATOR myschema.+ ( ... ). To qualify an operator name in an expression you need to write OPERATOR(myschema.+) (thanks to Peter for suggesting an escape hatch). I also took advantage of having to reformat pg_operator to fix something that'd been bugging me for a while: mergejoinable operators should have explicit links to the associated cross-data-type comparison operators, rather than hardwiring an assumption that they are named < and >.
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
* Portions Copyright (c) 2000-2001, PostgreSQL Global Development Group
|
||||
* Copyright 1999 Jan Wieck
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.36 2002/04/02 01:03:07 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.37 2002/04/16 23:08:11 tgl Exp $
|
||||
*
|
||||
* ----------
|
||||
*/
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "catalog/pg_operator.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "executor/spi_priv.h"
|
||||
#include "parser/parse_oper.h"
|
||||
#include "utils/lsyscache.h"
|
||||
#include "miscadmin.h"
|
||||
|
||||
@@ -3338,27 +3339,20 @@ ri_AttributesEqual(Oid typeid, Datum oldvalue, Datum newvalue)
|
||||
HASH_FIND, NULL);
|
||||
|
||||
/*
|
||||
* If not found, lookup the OPERNAME system cache for it to get the
|
||||
* func OID, then do the function manager lookup, and remember that
|
||||
* info.
|
||||
* If not found, lookup the operator, then do the function manager
|
||||
* lookup, and remember that info.
|
||||
*/
|
||||
if (!entry)
|
||||
{
|
||||
HeapTuple opr_tup;
|
||||
Oid opr_proc;
|
||||
FmgrInfo finfo;
|
||||
|
||||
opr_tup = SearchSysCache(OPERNAME,
|
||||
PointerGetDatum("="),
|
||||
ObjectIdGetDatum(typeid),
|
||||
ObjectIdGetDatum(typeid),
|
||||
CharGetDatum('b'));
|
||||
if (!HeapTupleIsValid(opr_tup))
|
||||
opr_proc = compatible_oper_funcid(makeList1(makeString("=")),
|
||||
typeid, typeid, true);
|
||||
if (!OidIsValid(opr_proc))
|
||||
elog(ERROR,
|
||||
"ri_AttributesEqual(): cannot find '=' operator for type %u",
|
||||
"ri_AttributesEqual(): cannot find '=' operator for type %u",
|
||||
typeid);
|
||||
opr_proc = ((Form_pg_operator) GETSTRUCT(opr_tup))->oprcode;
|
||||
ReleaseSysCache(opr_tup);
|
||||
|
||||
/*
|
||||
* Since fmgr_info could fail, call it *before* creating the
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.107 2002/04/03 05:39:31 petere Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/selfuncs.c,v 1.108 2002/04/16 23:08:11 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -74,6 +74,7 @@
|
||||
|
||||
#include "access/heapam.h"
|
||||
#include "catalog/catname.h"
|
||||
#include "catalog/pg_namespace.h"
|
||||
#include "catalog/pg_operator.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
#include "catalog/pg_statistic.h"
|
||||
@@ -3285,14 +3286,15 @@ string_lessthan(const char *str1, const char *str2, Oid datatype)
|
||||
}
|
||||
|
||||
/* See if there is a binary op of the given name for the given datatype */
|
||||
/* NB: we assume that only built-in system operators are searched for */
|
||||
static Oid
|
||||
find_operator(const char *opname, Oid datatype)
|
||||
{
|
||||
return GetSysCacheOid(OPERNAME,
|
||||
return GetSysCacheOid(OPERNAMENSP,
|
||||
PointerGetDatum(opname),
|
||||
ObjectIdGetDatum(datatype),
|
||||
ObjectIdGetDatum(datatype),
|
||||
CharGetDatum('b'));
|
||||
ObjectIdGetDatum(PG_CATALOG_NAMESPACE));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
47
src/backend/utils/cache/lsyscache.c
vendored
47
src/backend/utils/cache/lsyscache.c
vendored
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.69 2002/04/05 00:31:30 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.70 2002/04/16 23:08:11 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Eventually, the index information should go through here, too.
|
||||
@@ -378,10 +378,6 @@ op_mergejoinable(Oid opno, Oid ltype, Oid rtype, Oid *leftOp, Oid *rightOp)
|
||||
* ltype ">" rtype) for an operator previously determined to be
|
||||
* mergejoinable. Optionally, fetches the regproc ids of these
|
||||
* operators, as well as their operator OIDs.
|
||||
*
|
||||
* Raises error if operators cannot be found. Assuming that the operator
|
||||
* had indeed been marked mergejoinable, this indicates that whoever marked
|
||||
* it so was mistaken.
|
||||
*/
|
||||
void
|
||||
op_mergejoin_crossops(Oid opno, Oid *ltop, Oid *gtop,
|
||||
@@ -389,11 +385,9 @@ op_mergejoin_crossops(Oid opno, Oid *ltop, Oid *gtop,
|
||||
{
|
||||
HeapTuple tp;
|
||||
Form_pg_operator optup;
|
||||
Oid oprleft,
|
||||
oprright;
|
||||
|
||||
/*
|
||||
* Get the declared left and right operand types of the operator.
|
||||
* Get the declared comparison operators of the operator.
|
||||
*/
|
||||
tp = SearchSysCache(OPEROID,
|
||||
ObjectIdGetDatum(opno),
|
||||
@@ -401,44 +395,23 @@ op_mergejoin_crossops(Oid opno, Oid *ltop, Oid *gtop,
|
||||
if (!HeapTupleIsValid(tp)) /* shouldn't happen */
|
||||
elog(ERROR, "op_mergejoin_crossops: operator %u not found", opno);
|
||||
optup = (Form_pg_operator) GETSTRUCT(tp);
|
||||
oprleft = optup->oprleft;
|
||||
oprright = optup->oprright;
|
||||
*ltop = optup->oprltcmpop;
|
||||
*gtop = optup->oprgtcmpop;
|
||||
ReleaseSysCache(tp);
|
||||
|
||||
/*
|
||||
* Look up the "<" operator with the same input types. If there isn't
|
||||
* one, whoever marked the "=" operator mergejoinable was a loser.
|
||||
*/
|
||||
tp = SearchSysCache(OPERNAME,
|
||||
PointerGetDatum("<"),
|
||||
ObjectIdGetDatum(oprleft),
|
||||
ObjectIdGetDatum(oprright),
|
||||
CharGetDatum('b'));
|
||||
if (!HeapTupleIsValid(tp))
|
||||
/* Check < op provided */
|
||||
if (!OidIsValid(*ltop))
|
||||
elog(ERROR, "op_mergejoin_crossops: mergejoin operator %u has no matching < operator",
|
||||
opno);
|
||||
optup = (Form_pg_operator) GETSTRUCT(tp);
|
||||
*ltop = tp->t_data->t_oid;
|
||||
if (ltproc)
|
||||
*ltproc = optup->oprcode;
|
||||
ReleaseSysCache(tp);
|
||||
*ltproc = get_opcode(*ltop);
|
||||
|
||||
/*
|
||||
* And the same for the ">" operator.
|
||||
*/
|
||||
tp = SearchSysCache(OPERNAME,
|
||||
PointerGetDatum(">"),
|
||||
ObjectIdGetDatum(oprleft),
|
||||
ObjectIdGetDatum(oprright),
|
||||
CharGetDatum('b'));
|
||||
if (!HeapTupleIsValid(tp))
|
||||
/* Check > op provided */
|
||||
if (!OidIsValid(*gtop))
|
||||
elog(ERROR, "op_mergejoin_crossops: mergejoin operator %u has no matching > operator",
|
||||
opno);
|
||||
optup = (Form_pg_operator) GETSTRUCT(tp);
|
||||
*gtop = tp->t_data->t_oid;
|
||||
if (gtproc)
|
||||
*gtproc = optup->oprcode;
|
||||
ReleaseSysCache(tp);
|
||||
*gtproc = get_opcode(*gtop);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
8
src/backend/utils/cache/syscache.c
vendored
8
src/backend/utils/cache/syscache.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.76 2002/04/11 20:00:06 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.77 2002/04/16 23:08:11 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* These routines allow the parser/planner/executor to perform
|
||||
@@ -273,15 +273,15 @@ static const struct cachedesc cacheinfo[] = {
|
||||
0,
|
||||
0
|
||||
}},
|
||||
{OperatorRelationName, /* OPERNAME */
|
||||
OperatorNameIndex,
|
||||
{OperatorRelationName, /* OPERNAMENSP */
|
||||
OperatorNameNspIndex,
|
||||
0,
|
||||
4,
|
||||
{
|
||||
Anum_pg_operator_oprname,
|
||||
Anum_pg_operator_oprleft,
|
||||
Anum_pg_operator_oprright,
|
||||
Anum_pg_operator_oprkind
|
||||
Anum_pg_operator_oprnamespace
|
||||
}},
|
||||
{OperatorRelationName, /* OPEROID */
|
||||
OperatorOidIndex,
|
||||
|
||||
Reference in New Issue
Block a user