2002-04-15 07:22:04 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* operatorcmds.c
|
|
|
|
*
|
|
|
|
* Routines for operator manipulation commands
|
|
|
|
*
|
2018-01-03 05:30:12 +01:00
|
|
|
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
|
2002-04-15 07:22:04 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2010-09-20 22:08:53 +02:00
|
|
|
* src/backend/commands/operatorcmds.c
|
2002-04-15 07:22:04 +02:00
|
|
|
*
|
|
|
|
* DESCRIPTION
|
|
|
|
* The "DefineFoo" routines take the parse tree and pick out the
|
|
|
|
* appropriate arguments/flags, passing the results to the
|
|
|
|
* corresponding "FooDefine" routines (in src/catalog) that do
|
|
|
|
* the actual catalog-munging. These routines also verify permission
|
|
|
|
* of the user to execute the command.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* These things must be defined and committed in the following order:
|
|
|
|
* "create function":
|
2018-08-15 18:05:46 +02:00
|
|
|
* input/output, recv/send functions
|
2002-04-15 07:22:04 +02:00
|
|
|
* "create type":
|
|
|
|
* type
|
|
|
|
* "create operator":
|
|
|
|
* operators
|
|
|
|
*
|
|
|
|
* Most of the parse-tree manipulation routines are defined in
|
|
|
|
* commands/manip.c.
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "access/heapam.h"
|
2012-08-30 22:15:44 +02:00
|
|
|
#include "access/htup_details.h"
|
2002-07-12 20:43:19 +02:00
|
|
|
#include "catalog/dependency.h"
|
2004-06-25 23:55:59 +02:00
|
|
|
#include "catalog/indexing.h"
|
2015-07-14 18:50:18 +02:00
|
|
|
#include "catalog/objectaccess.h"
|
2002-04-15 07:22:04 +02:00
|
|
|
#include "catalog/pg_operator.h"
|
2008-08-16 02:01:38 +02:00
|
|
|
#include "catalog/pg_type.h"
|
2010-11-26 23:27:23 +01:00
|
|
|
#include "commands/alter.h"
|
2002-04-15 07:22:04 +02:00
|
|
|
#include "commands/defrem.h"
|
|
|
|
#include "miscadmin.h"
|
2008-08-16 02:01:38 +02:00
|
|
|
#include "parser/parse_func.h"
|
2002-04-17 01:08:12 +02:00
|
|
|
#include "parser/parse_oper.h"
|
2002-04-15 07:22:04 +02:00
|
|
|
#include "parser/parse_type.h"
|
2011-12-19 23:05:19 +01:00
|
|
|
#include "utils/builtins.h"
|
2002-04-27 05:45:03 +02:00
|
|
|
#include "utils/lsyscache.h"
|
2008-06-19 02:46:06 +02:00
|
|
|
#include "utils/rel.h"
|
2002-04-15 07:22:04 +02:00
|
|
|
#include "utils/syscache.h"
|
|
|
|
|
2015-07-14 17:17:55 +02:00
|
|
|
static Oid ValidateRestrictionEstimator(List *restrictionName);
|
|
|
|
static Oid ValidateJoinEstimator(List *joinName);
|
|
|
|
|
2002-04-15 07:22:04 +02:00
|
|
|
/*
|
|
|
|
* DefineOperator
|
|
|
|
* this function extracts all the information from the
|
|
|
|
* parameter list generated by the parser and then has
|
|
|
|
* OperatorCreate() do all the actual work.
|
|
|
|
*
|
|
|
|
* 'parameters' is a list of DefElem
|
|
|
|
*/
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
ObjectAddress
|
2002-04-15 07:22:04 +02:00
|
|
|
DefineOperator(List *names, List *parameters)
|
|
|
|
{
|
|
|
|
char *oprName;
|
|
|
|
Oid oprNamespace;
|
2002-04-27 05:45:03 +02:00
|
|
|
AclResult aclresult;
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
bool canMerge = false; /* operator merges */
|
2007-11-15 22:14:46 +01:00
|
|
|
bool canHash = false; /* operator hashes */
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
List *functionName = NIL; /* function for operator */
|
|
|
|
TypeName *typeName1 = NULL; /* first type name */
|
|
|
|
TypeName *typeName2 = NULL; /* second type name */
|
2002-04-15 07:22:04 +02:00
|
|
|
Oid typeId1 = InvalidOid; /* types converted to OID */
|
|
|
|
Oid typeId2 = InvalidOid;
|
2011-12-19 23:05:19 +01:00
|
|
|
Oid rettype;
|
2005-10-15 04:49:52 +02:00
|
|
|
List *commutatorName = NIL; /* optional commutator operator name */
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
List *negatorName = NIL; /* optional negator operator name */
|
2018-08-15 18:05:46 +02:00
|
|
|
List *restrictionName = NIL; /* optional restrict. sel. function */
|
|
|
|
List *joinName = NIL; /* optional join sel. function */
|
2008-08-16 02:01:38 +02:00
|
|
|
Oid functionOid; /* functions converted to OID */
|
|
|
|
Oid restrictionOid;
|
|
|
|
Oid joinOid;
|
2015-07-14 17:17:55 +02:00
|
|
|
Oid typeId[2]; /* to hold left and right arg */
|
2008-08-16 02:01:38 +02:00
|
|
|
int nargs;
|
2004-05-26 06:41:50 +02:00
|
|
|
ListCell *pl;
|
2002-04-15 07:22:04 +02:00
|
|
|
|
|
|
|
/* Convert list of names to a name and namespace */
|
|
|
|
oprNamespace = QualifiedNameGetCreationNamespace(names, &oprName);
|
|
|
|
|
2002-04-27 05:45:03 +02:00
|
|
|
/* Check we have creation rights in target namespace */
|
|
|
|
aclresult = pg_namespace_aclcheck(oprNamespace, GetUserId(), ACL_CREATE);
|
|
|
|
if (aclresult != ACLCHECK_OK)
|
2017-12-02 15:26:34 +01:00
|
|
|
aclcheck_error(aclresult, OBJECT_SCHEMA,
|
2003-08-01 02:15:26 +02:00
|
|
|
get_namespace_name(oprNamespace));
|
2002-04-27 05:45:03 +02:00
|
|
|
|
2002-04-15 07:22:04 +02:00
|
|
|
/*
|
|
|
|
* loop over the definition list and extract the information we need.
|
|
|
|
*/
|
|
|
|
foreach(pl, parameters)
|
|
|
|
{
|
|
|
|
DefElem *defel = (DefElem *) lfirst(pl);
|
|
|
|
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
if (strcmp(defel->defname, "leftarg") == 0)
|
2002-04-15 07:22:04 +02:00
|
|
|
{
|
|
|
|
typeName1 = defGetTypeName(defel);
|
|
|
|
if (typeName1->setof)
|
2003-07-20 23:56:35 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
errmsg("SETOF type not allowed for operator argument")));
|
2002-04-15 07:22:04 +02:00
|
|
|
}
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "rightarg") == 0)
|
2002-04-15 07:22:04 +02:00
|
|
|
{
|
|
|
|
typeName2 = defGetTypeName(defel);
|
|
|
|
if (typeName2->setof)
|
2003-07-20 23:56:35 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
errmsg("SETOF type not allowed for operator argument")));
|
2002-04-15 07:22:04 +02:00
|
|
|
}
|
2018-08-15 18:05:46 +02:00
|
|
|
/* "function" and "procedure" are equivalent here */
|
|
|
|
else if (strcmp(defel->defname, "function") == 0)
|
|
|
|
functionName = defGetQualifiedName(defel);
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "procedure") == 0)
|
2002-04-17 01:08:12 +02:00
|
|
|
functionName = defGetQualifiedName(defel);
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "commutator") == 0)
|
2002-04-17 01:08:12 +02:00
|
|
|
commutatorName = defGetQualifiedName(defel);
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "negator") == 0)
|
2002-04-17 01:08:12 +02:00
|
|
|
negatorName = defGetQualifiedName(defel);
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "restrict") == 0)
|
2002-04-17 01:08:12 +02:00
|
|
|
restrictionName = defGetQualifiedName(defel);
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "join") == 0)
|
2002-04-17 01:08:12 +02:00
|
|
|
joinName = defGetQualifiedName(defel);
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "hashes") == 0)
|
2004-05-14 18:11:25 +02:00
|
|
|
canHash = defGetBoolean(defel);
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "merges") == 0)
|
2004-05-14 18:11:25 +02:00
|
|
|
canMerge = defGetBoolean(defel);
|
2006-12-23 01:43:13 +01:00
|
|
|
/* These obsolete options are taken as meaning canMerge */
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "sort1") == 0)
|
2006-12-23 01:43:13 +01:00
|
|
|
canMerge = true;
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "sort2") == 0)
|
2006-12-23 01:43:13 +01:00
|
|
|
canMerge = true;
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "ltcmp") == 0)
|
2006-12-23 01:43:13 +01:00
|
|
|
canMerge = true;
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "gtcmp") == 0)
|
2006-12-23 01:43:13 +01:00
|
|
|
canMerge = true;
|
2002-04-15 07:22:04 +02:00
|
|
|
else
|
2015-07-14 17:17:55 +02:00
|
|
|
{
|
|
|
|
/* WARNING, not ERROR, for historical backwards-compatibility */
|
2003-07-20 23:56:35 +02:00
|
|
|
ereport(WARNING,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("operator attribute \"%s\" not recognized",
|
|
|
|
defel->defname)));
|
2015-07-14 17:17:55 +02:00
|
|
|
}
|
2002-04-15 07:22:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* make sure we have our required definitions
|
|
|
|
*/
|
2002-04-17 01:08:12 +02:00
|
|
|
if (functionName == NIL)
|
2003-07-20 23:56:35 +02:00
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
2018-08-15 18:05:46 +02:00
|
|
|
errmsg("operator function must be specified")));
|
2002-04-15 07:22:04 +02:00
|
|
|
|
|
|
|
/* Transform type names to type OIDs */
|
|
|
|
if (typeName1)
|
2010-10-25 20:40:46 +02:00
|
|
|
typeId1 = typenameTypeId(NULL, typeName1);
|
2002-04-15 07:22:04 +02:00
|
|
|
if (typeName2)
|
2010-10-25 20:40:46 +02:00
|
|
|
typeId2 = typenameTypeId(NULL, typeName2);
|
2002-04-15 07:22:04 +02:00
|
|
|
|
2008-08-16 02:01:38 +02:00
|
|
|
if (!OidIsValid(typeId1) && !OidIsValid(typeId2))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
errmsg("at least one of leftarg or rightarg must be specified")));
|
2008-08-16 02:01:38 +02:00
|
|
|
|
2011-12-19 23:05:19 +01:00
|
|
|
if (typeName1)
|
|
|
|
{
|
|
|
|
aclresult = pg_type_aclcheck(typeId1, GetUserId(), ACL_USAGE);
|
|
|
|
if (aclresult != ACLCHECK_OK)
|
2012-06-15 21:55:03 +02:00
|
|
|
aclcheck_error_type(aclresult, typeId1);
|
2011-12-19 23:05:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (typeName2)
|
|
|
|
{
|
|
|
|
aclresult = pg_type_aclcheck(typeId2, GetUserId(), ACL_USAGE);
|
|
|
|
if (aclresult != ACLCHECK_OK)
|
2012-06-15 21:55:03 +02:00
|
|
|
aclcheck_error_type(aclresult, typeId2);
|
2011-12-19 23:05:19 +01:00
|
|
|
}
|
|
|
|
|
2008-08-16 02:01:38 +02:00
|
|
|
/*
|
|
|
|
* Look up the operator's underlying function.
|
|
|
|
*/
|
|
|
|
if (!OidIsValid(typeId1))
|
|
|
|
{
|
|
|
|
typeId[0] = typeId2;
|
|
|
|
nargs = 1;
|
|
|
|
}
|
|
|
|
else if (!OidIsValid(typeId2))
|
|
|
|
{
|
|
|
|
typeId[0] = typeId1;
|
|
|
|
nargs = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
typeId[0] = typeId1;
|
|
|
|
typeId[1] = typeId2;
|
|
|
|
nargs = 2;
|
|
|
|
}
|
|
|
|
functionOid = LookupFuncName(functionName, nargs, typeId, false);
|
|
|
|
|
|
|
|
/*
|
2014-05-06 18:12:18 +02:00
|
|
|
* We require EXECUTE rights for the function. This isn't strictly
|
2009-06-11 16:49:15 +02:00
|
|
|
* necessary, since EXECUTE will be checked at any attempted use of the
|
|
|
|
* operator, but it seems like a good idea anyway.
|
2008-08-16 02:01:38 +02:00
|
|
|
*/
|
|
|
|
aclresult = pg_proc_aclcheck(functionOid, GetUserId(), ACL_EXECUTE);
|
|
|
|
if (aclresult != ACLCHECK_OK)
|
2017-12-02 15:26:34 +01:00
|
|
|
aclcheck_error(aclresult, OBJECT_FUNCTION,
|
2008-08-16 02:01:38 +02:00
|
|
|
NameListToString(functionName));
|
|
|
|
|
2011-12-19 23:05:19 +01:00
|
|
|
rettype = get_func_rettype(functionOid);
|
|
|
|
aclresult = pg_type_aclcheck(rettype, GetUserId(), ACL_USAGE);
|
|
|
|
if (aclresult != ACLCHECK_OK)
|
2012-06-15 21:55:03 +02:00
|
|
|
aclcheck_error_type(aclresult, rettype);
|
2011-12-19 23:05:19 +01:00
|
|
|
|
2008-08-16 02:01:38 +02:00
|
|
|
/*
|
2015-07-14 17:17:55 +02:00
|
|
|
* Look up restriction and join estimators if specified
|
2008-08-16 02:01:38 +02:00
|
|
|
*/
|
|
|
|
if (restrictionName)
|
2015-07-14 17:17:55 +02:00
|
|
|
restrictionOid = ValidateRestrictionEstimator(restrictionName);
|
2008-08-16 02:01:38 +02:00
|
|
|
else
|
|
|
|
restrictionOid = InvalidOid;
|
|
|
|
if (joinName)
|
2015-07-14 17:17:55 +02:00
|
|
|
joinOid = ValidateJoinEstimator(joinName);
|
2008-08-16 02:01:38 +02:00
|
|
|
else
|
|
|
|
joinOid = InvalidOid;
|
|
|
|
|
2002-04-15 07:22:04 +02:00
|
|
|
/*
|
|
|
|
* now have OperatorCreate do all the work..
|
|
|
|
*/
|
2012-12-24 00:25:03 +01:00
|
|
|
return
|
2013-05-29 22:58:43 +02:00
|
|
|
OperatorCreate(oprName, /* operator name */
|
2012-12-24 00:25:03 +01:00
|
|
|
oprNamespace, /* namespace */
|
2013-05-29 22:58:43 +02:00
|
|
|
typeId1, /* left type id */
|
|
|
|
typeId2, /* right type id */
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
functionOid, /* function for operator */
|
2013-05-29 22:58:43 +02:00
|
|
|
commutatorName, /* optional commutator operator name */
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
negatorName, /* optional negator operator name */
|
2018-08-15 18:05:46 +02:00
|
|
|
restrictionOid, /* optional restrict. sel. function */
|
|
|
|
joinOid, /* optional join sel. function name */
|
2012-12-24 00:25:03 +01:00
|
|
|
canMerge, /* operator merges */
|
|
|
|
canHash); /* operator hashes */
|
2002-04-15 07:22:04 +02:00
|
|
|
}
|
|
|
|
|
2015-07-14 17:17:55 +02:00
|
|
|
/*
|
|
|
|
* Look up a restriction estimator function ny name, and verify that it has
|
|
|
|
* the correct signature and we have the permissions to attach it to an
|
|
|
|
* operator.
|
|
|
|
*/
|
|
|
|
static Oid
|
|
|
|
ValidateRestrictionEstimator(List *restrictionName)
|
|
|
|
{
|
|
|
|
Oid typeId[4];
|
|
|
|
Oid restrictionOid;
|
|
|
|
AclResult aclresult;
|
|
|
|
|
|
|
|
typeId[0] = INTERNALOID; /* PlannerInfo */
|
|
|
|
typeId[1] = OIDOID; /* operator OID */
|
|
|
|
typeId[2] = INTERNALOID; /* args list */
|
|
|
|
typeId[3] = INT4OID; /* varRelid */
|
|
|
|
|
|
|
|
restrictionOid = LookupFuncName(restrictionName, 4, typeId, false);
|
|
|
|
|
|
|
|
/* estimators must return float8 */
|
|
|
|
if (get_func_rettype(restrictionOid) != FLOAT8OID)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
errmsg("restriction estimator function %s must return type %s",
|
|
|
|
NameListToString(restrictionName), "float8")));
|
2015-07-14 17:17:55 +02:00
|
|
|
|
|
|
|
/* Require EXECUTE rights for the estimator */
|
|
|
|
aclresult = pg_proc_aclcheck(restrictionOid, GetUserId(), ACL_EXECUTE);
|
|
|
|
if (aclresult != ACLCHECK_OK)
|
2017-12-02 15:26:34 +01:00
|
|
|
aclcheck_error(aclresult, OBJECT_FUNCTION,
|
2015-07-14 17:17:55 +02:00
|
|
|
NameListToString(restrictionName));
|
|
|
|
|
|
|
|
return restrictionOid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up a join estimator function ny name, and verify that it has the
|
|
|
|
* correct signature and we have the permissions to attach it to an
|
|
|
|
* operator.
|
|
|
|
*/
|
|
|
|
static Oid
|
|
|
|
ValidateJoinEstimator(List *joinName)
|
|
|
|
{
|
|
|
|
Oid typeId[5];
|
|
|
|
Oid joinOid;
|
|
|
|
AclResult aclresult;
|
|
|
|
|
|
|
|
typeId[0] = INTERNALOID; /* PlannerInfo */
|
|
|
|
typeId[1] = OIDOID; /* operator OID */
|
|
|
|
typeId[2] = INTERNALOID; /* args list */
|
|
|
|
typeId[3] = INT2OID; /* jointype */
|
|
|
|
typeId[4] = INTERNALOID; /* SpecialJoinInfo */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As of Postgres 8.4, the preferred signature for join estimators has 5
|
|
|
|
* arguments, but we still allow the old 4-argument form. Try the
|
|
|
|
* preferred form first.
|
|
|
|
*/
|
|
|
|
joinOid = LookupFuncName(joinName, 5, typeId, true);
|
|
|
|
if (!OidIsValid(joinOid))
|
|
|
|
joinOid = LookupFuncName(joinName, 4, typeId, true);
|
|
|
|
/* If not found, reference the 5-argument signature in error msg */
|
|
|
|
if (!OidIsValid(joinOid))
|
|
|
|
joinOid = LookupFuncName(joinName, 5, typeId, false);
|
|
|
|
|
|
|
|
/* estimators must return float8 */
|
|
|
|
if (get_func_rettype(joinOid) != FLOAT8OID)
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
2016-06-10 00:02:36 +02:00
|
|
|
errmsg("join estimator function %s must return type %s",
|
|
|
|
NameListToString(joinName), "float8")));
|
2015-07-14 17:17:55 +02:00
|
|
|
|
|
|
|
/* Require EXECUTE rights for the estimator */
|
|
|
|
aclresult = pg_proc_aclcheck(joinOid, GetUserId(), ACL_EXECUTE);
|
|
|
|
if (aclresult != ACLCHECK_OK)
|
2017-12-02 15:26:34 +01:00
|
|
|
aclcheck_error(aclresult, OBJECT_FUNCTION,
|
2015-07-14 17:17:55 +02:00
|
|
|
NameListToString(joinName));
|
|
|
|
|
|
|
|
return joinOid;
|
|
|
|
}
|
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
/*
|
|
|
|
* Guts of operator deletion.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
RemoveOperatorById(Oid operOid)
|
|
|
|
{
|
|
|
|
Relation relation;
|
|
|
|
HeapTuple tup;
|
2016-03-25 17:33:16 +01:00
|
|
|
Form_pg_operator op;
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2005-04-14 22:03:27 +02:00
|
|
|
relation = heap_open(OperatorRelationId, RowExclusiveLock);
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2010-02-14 19:42:19 +01:00
|
|
|
tup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operOid));
|
2002-09-04 22:31:48 +02:00
|
|
|
if (!HeapTupleIsValid(tup)) /* should not happen */
|
2003-07-20 23:56:35 +02:00
|
|
|
elog(ERROR, "cache lookup failed for operator %u", operOid);
|
2016-03-25 17:33:16 +01:00
|
|
|
op = (Form_pg_operator) GETSTRUCT(tup);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset links from commutator and negator, if any. In case of a
|
|
|
|
* self-commutator or self-negator, this means we have to re-fetch the
|
|
|
|
* updated tuple. (We could optimize away updates on the tuple we're
|
|
|
|
* about to drop, but it doesn't seem worth convoluting the logic for.)
|
|
|
|
*/
|
|
|
|
if (OidIsValid(op->oprcom) || OidIsValid(op->oprnegate))
|
|
|
|
{
|
|
|
|
OperatorUpd(operOid, op->oprcom, op->oprnegate, true);
|
|
|
|
if (operOid == op->oprcom || operOid == op->oprnegate)
|
|
|
|
{
|
|
|
|
ReleaseSysCache(tup);
|
|
|
|
tup = SearchSysCache1(OPEROID, ObjectIdGetDatum(operOid));
|
|
|
|
if (!HeapTupleIsValid(tup)) /* should not happen */
|
|
|
|
elog(ERROR, "cache lookup failed for operator %u", operOid);
|
|
|
|
}
|
|
|
|
}
|
2002-04-15 07:22:04 +02:00
|
|
|
|
2017-02-01 22:13:30 +01:00
|
|
|
CatalogTupleDelete(relation, &tup->t_self);
|
2002-04-15 07:22:04 +02:00
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
ReleaseSysCache(tup);
|
|
|
|
|
2002-04-15 07:22:04 +02:00
|
|
|
heap_close(relation, RowExclusiveLock);
|
|
|
|
}
|
2015-07-14 17:17:55 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AlterOperator
|
|
|
|
* routine implementing ALTER OPERATOR <operator> SET (option = ...).
|
|
|
|
*
|
|
|
|
* Currently, only RESTRICT and JOIN estimator functions can be changed.
|
|
|
|
*/
|
|
|
|
ObjectAddress
|
|
|
|
AlterOperator(AlterOperatorStmt *stmt)
|
|
|
|
{
|
|
|
|
ObjectAddress address;
|
|
|
|
Oid oprId;
|
|
|
|
Relation catalog;
|
|
|
|
HeapTuple tup;
|
|
|
|
Form_pg_operator oprForm;
|
|
|
|
int i;
|
|
|
|
ListCell *pl;
|
|
|
|
Datum values[Natts_pg_operator];
|
|
|
|
bool nulls[Natts_pg_operator];
|
|
|
|
bool replaces[Natts_pg_operator];
|
2018-08-15 18:05:46 +02:00
|
|
|
List *restrictionName = NIL; /* optional restrict. sel. function */
|
2015-07-14 17:17:55 +02:00
|
|
|
bool updateRestriction = false;
|
|
|
|
Oid restrictionOid;
|
2018-08-15 18:05:46 +02:00
|
|
|
List *joinName = NIL; /* optional join sel. function */
|
2015-07-14 17:17:55 +02:00
|
|
|
bool updateJoin = false;
|
|
|
|
Oid joinOid;
|
|
|
|
|
|
|
|
/* Look up the operator */
|
2016-12-28 18:00:00 +01:00
|
|
|
oprId = LookupOperWithArgs(stmt->opername, false);
|
2015-07-14 17:17:55 +02:00
|
|
|
catalog = heap_open(OperatorRelationId, RowExclusiveLock);
|
|
|
|
tup = SearchSysCacheCopy1(OPEROID, ObjectIdGetDatum(oprId));
|
|
|
|
if (tup == NULL)
|
|
|
|
elog(ERROR, "cache lookup failed for operator %u", oprId);
|
|
|
|
oprForm = (Form_pg_operator) GETSTRUCT(tup);
|
|
|
|
|
|
|
|
/* Process options */
|
|
|
|
foreach(pl, stmt->options)
|
|
|
|
{
|
|
|
|
DefElem *defel = (DefElem *) lfirst(pl);
|
|
|
|
List *param;
|
|
|
|
|
|
|
|
if (defel->arg == NULL)
|
|
|
|
param = NIL; /* NONE, removes the function */
|
|
|
|
else
|
|
|
|
param = defGetQualifiedName(defel);
|
|
|
|
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
if (strcmp(defel->defname, "restrict") == 0)
|
2015-07-14 17:17:55 +02:00
|
|
|
{
|
|
|
|
restrictionName = param;
|
|
|
|
updateRestriction = true;
|
|
|
|
}
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "join") == 0)
|
2015-07-14 17:17:55 +02:00
|
|
|
{
|
|
|
|
joinName = param;
|
|
|
|
updateJoin = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The rest of the options that CREATE accepts cannot be changed.
|
|
|
|
* Check for them so that we can give a meaningful error message.
|
|
|
|
*/
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
else if (strcmp(defel->defname, "leftarg") == 0 ||
|
|
|
|
strcmp(defel->defname, "rightarg") == 0 ||
|
2018-08-15 18:05:46 +02:00
|
|
|
strcmp(defel->defname, "function") == 0 ||
|
Avoid unnecessary use of pg_strcasecmp for already-downcased identifiers.
We have a lot of code in which option names, which from the user's
viewpoint are logically keywords, are passed through the grammar as plain
identifiers, and then matched to string literals during command execution.
This approach avoids making words into lexer keywords unnecessarily. Some
places matched these strings using plain strcmp, some using pg_strcasecmp.
But the latter should be unnecessary since identifiers would have been
downcased on their way through the parser. Aside from any efficiency
concerns (probably not a big factor), the lack of consistency in this area
creates a hazard of subtle bugs due to different places coming to different
conclusions about whether two option names are the same or different.
Hence, standardize on using strcmp() to match any option names that are
expected to have been fed through the parser.
This does create a user-visible behavioral change, which is that while
formerly all of these would work:
alter table foo set (fillfactor = 50);
alter table foo set (FillFactor = 50);
alter table foo set ("fillfactor" = 50);
alter table foo set ("FillFactor" = 50);
now the last case will fail because that double-quoted identifier is
different from the others. However, none of our documentation says that
you can use a quoted identifier in such contexts at all, and we should
discourage doing so since it would break if we ever decide to parse such
constructs as true lexer keywords rather than poor man's substitutes.
So this shouldn't create a significant compatibility issue for users.
Daniel Gustafsson, reviewed by Michael Paquier, small changes by me
Discussion: https://postgr.es/m/29405B24-564E-476B-98C0-677A29805B84@yesql.se
2018-01-27 00:25:02 +01:00
|
|
|
strcmp(defel->defname, "procedure") == 0 ||
|
|
|
|
strcmp(defel->defname, "commutator") == 0 ||
|
|
|
|
strcmp(defel->defname, "negator") == 0 ||
|
|
|
|
strcmp(defel->defname, "hashes") == 0 ||
|
|
|
|
strcmp(defel->defname, "merges") == 0)
|
2015-07-14 17:17:55 +02:00
|
|
|
{
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
2016-06-07 20:18:08 +02:00
|
|
|
errmsg("operator attribute \"%s\" cannot be changed",
|
2015-07-14 17:17:55 +02:00
|
|
|
defel->defname)));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
|
|
errmsg("operator attribute \"%s\" not recognized",
|
|
|
|
defel->defname)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check permissions. Must be owner. */
|
|
|
|
if (!pg_oper_ownercheck(oprId, GetUserId()))
|
2017-12-02 15:26:34 +01:00
|
|
|
aclcheck_error(ACLCHECK_NOT_OWNER, OBJECT_OPERATOR,
|
2015-07-14 17:17:55 +02:00
|
|
|
NameStr(oprForm->oprname));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look up restriction and join estimators if specified
|
|
|
|
*/
|
|
|
|
if (restrictionName)
|
|
|
|
restrictionOid = ValidateRestrictionEstimator(restrictionName);
|
|
|
|
else
|
|
|
|
restrictionOid = InvalidOid;
|
|
|
|
if (joinName)
|
|
|
|
joinOid = ValidateJoinEstimator(joinName);
|
|
|
|
else
|
|
|
|
joinOid = InvalidOid;
|
|
|
|
|
|
|
|
/* Perform additional checks, like OperatorCreate does */
|
|
|
|
if (!(OidIsValid(oprForm->oprleft) && OidIsValid(oprForm->oprright)))
|
|
|
|
{
|
|
|
|
/* If it's not a binary op, these things mustn't be set: */
|
|
|
|
if (OidIsValid(joinOid))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
errmsg("only binary operators can have join selectivity")));
|
2015-07-14 17:17:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (oprForm->oprresult != BOOLOID)
|
|
|
|
{
|
|
|
|
if (OidIsValid(restrictionOid))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
|
|
|
errmsg("only boolean operators can have restriction selectivity")));
|
|
|
|
if (OidIsValid(joinOid))
|
|
|
|
ereport(ERROR,
|
|
|
|
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
|
Phase 3 of pgindent updates.
Don't move parenthesized lines to the left, even if that means they
flow past the right margin.
By default, BSD indent lines up statement continuation lines that are
within parentheses so that they start just to the right of the preceding
left parenthesis. However, traditionally, if that resulted in the
continuation line extending to the right of the desired right margin,
then indent would push it left just far enough to not overrun the margin,
if it could do so without making the continuation line start to the left of
the current statement indent. That makes for a weird mix of indentations
unless one has been completely rigid about never violating the 80-column
limit.
This behavior has been pretty universally panned by Postgres developers.
Hence, disable it with indent's new -lpl switch, so that parenthesized
lines are always lined up with the preceding left paren.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:35:54 +02:00
|
|
|
errmsg("only boolean operators can have join selectivity")));
|
2015-07-14 17:17:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the tuple */
|
|
|
|
for (i = 0; i < Natts_pg_operator; ++i)
|
|
|
|
{
|
|
|
|
values[i] = (Datum) 0;
|
|
|
|
replaces[i] = false;
|
|
|
|
nulls[i] = false;
|
|
|
|
}
|
|
|
|
if (updateRestriction)
|
|
|
|
{
|
|
|
|
replaces[Anum_pg_operator_oprrest - 1] = true;
|
|
|
|
values[Anum_pg_operator_oprrest - 1] = restrictionOid;
|
|
|
|
}
|
|
|
|
if (updateJoin)
|
|
|
|
{
|
|
|
|
replaces[Anum_pg_operator_oprjoin - 1] = true;
|
|
|
|
values[Anum_pg_operator_oprjoin - 1] = joinOid;
|
|
|
|
}
|
|
|
|
|
|
|
|
tup = heap_modify_tuple(tup, RelationGetDescr(catalog),
|
|
|
|
values, nulls, replaces);
|
|
|
|
|
2017-01-31 22:42:24 +01:00
|
|
|
CatalogTupleUpdate(catalog, &tup->t_self, tup);
|
2015-07-14 17:17:55 +02:00
|
|
|
|
2015-12-31 23:37:31 +01:00
|
|
|
address = makeOperatorDependencies(tup, true);
|
2015-07-14 18:50:18 +02:00
|
|
|
|
2015-12-31 23:37:31 +01:00
|
|
|
InvokeObjectPostAlterHook(OperatorRelationId, oprId, 0);
|
2015-07-14 18:50:18 +02:00
|
|
|
|
|
|
|
heap_close(catalog, NoLock);
|
2015-07-14 17:17:55 +02:00
|
|
|
|
|
|
|
return address;
|
|
|
|
}
|