|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
|
*
|
Clean up two rather nasty bugs in operator selection code.
1. If there is exactly one pg_operator entry of the right name and oprkind,
oper() and related routines would return that entry whether its input type
had anything to do with the request or not. This is just premature
optimization: we shouldn't return the single candidate until after we verify
that it really is a valid candidate, ie, is at least coercion-compatible
with the given types.
2. oper() and related routines only promise a coercion-compatible result.
Unfortunately, there were quite a few callers that assumed the returned
operator is binary-compatible with the given datatype; they would proceed
to call it without making any datatype coercions. These callers include
sorting, grouping, aggregation, and VACUUM ANALYZE. In general I think
it is appropriate for these callers to require an exact or binary-compatible
match, so I've added a new routine compatible_oper() that only succeeds if
it can find an operator that doesn't require any run-time conversions.
Callers now call oper() or compatible_oper() depending on whether they are
prepared to deal with type conversion or not.
The upshot of these bugs is revealed by the following silliness in PL/Tcl's
selftest: it creates an operator @< on int4, and then tries to use it to
sort a char(N) column. The system would let it do that :-( (and evidently
has done so since 6.3 :-( :-(). The result in this case was just a silly
sort order, but the reverse combination would've provoked coredump from
trying to dereference integers. With this fix you get more reasonable
behavior:
pltcl_test=# select * from T_pkey1 order by key1, key2 using @<;
ERROR: Unable to identify an operator '@<' for types 'bpchar' and 'bpchar'
You will have to retype this query using an explicit cast
25 years ago
|
|
|
* parse_oper.h
|
|
|
|
|
* handle operator things for parser
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
|
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
|
*
|
|
|
|
|
* src/include/parser/parse_oper.h
|
|
|
|
|
*
|
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
#ifndef PARSE_OPER_H
|
|
|
|
|
#define PARSE_OPER_H
|
|
|
|
|
|
|
|
|
|
#include "access/htup.h"
|
|
|
|
|
#include "parser/parse_node.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef HeapTuple Operator;
|
|
|
|
|
|
|
|
|
|
/* Routines to look up an operator given name and exact input type(s) */
|
|
|
|
|
extern Oid LookupOperName(ParseState *pstate, List *opername,
|
|
|
|
|
Oid oprleft, Oid oprright,
|
|
|
|
|
bool noError, int location);
|
|
|
|
|
extern Oid LookupOperNameTypeNames(ParseState *pstate, List *opername,
|
|
|
|
|
TypeName *oprleft, TypeName *oprright,
|
|
|
|
|
bool noError, int location);
|
|
|
|
|
|
Clean up two rather nasty bugs in operator selection code.
1. If there is exactly one pg_operator entry of the right name and oprkind,
oper() and related routines would return that entry whether its input type
had anything to do with the request or not. This is just premature
optimization: we shouldn't return the single candidate until after we verify
that it really is a valid candidate, ie, is at least coercion-compatible
with the given types.
2. oper() and related routines only promise a coercion-compatible result.
Unfortunately, there were quite a few callers that assumed the returned
operator is binary-compatible with the given datatype; they would proceed
to call it without making any datatype coercions. These callers include
sorting, grouping, aggregation, and VACUUM ANALYZE. In general I think
it is appropriate for these callers to require an exact or binary-compatible
match, so I've added a new routine compatible_oper() that only succeeds if
it can find an operator that doesn't require any run-time conversions.
Callers now call oper() or compatible_oper() depending on whether they are
prepared to deal with type conversion or not.
The upshot of these bugs is revealed by the following silliness in PL/Tcl's
selftest: it creates an operator @< on int4, and then tries to use it to
sort a char(N) column. The system would let it do that :-( (and evidently
has done so since 6.3 :-( :-(). The result in this case was just a silly
sort order, but the reverse combination would've provoked coredump from
trying to dereference integers. With this fix you get more reasonable
behavior:
pltcl_test=# select * from T_pkey1 order by key1, key2 using @<;
ERROR: Unable to identify an operator '@<' for types 'bpchar' and 'bpchar'
You will have to retype this query using an explicit cast
25 years ago
|
|
|
/* Routines to find operators matching a name and given input types */
|
|
|
|
|
/* NB: the selected operator may require coercion of the input types! */
|
|
|
|
|
extern Operator oper(ParseState *pstate, List *op, Oid arg1, Oid arg2,
|
|
|
|
|
bool noError, int location);
|
|
|
|
|
extern Operator right_oper(ParseState *pstate, List *op, Oid arg,
|
|
|
|
|
bool noError, int location);
|
|
|
|
|
extern Operator left_oper(ParseState *pstate, List *op, Oid arg,
|
|
|
|
|
bool noError, int location);
|
|
|
|
|
|
Clean up two rather nasty bugs in operator selection code.
1. If there is exactly one pg_operator entry of the right name and oprkind,
oper() and related routines would return that entry whether its input type
had anything to do with the request or not. This is just premature
optimization: we shouldn't return the single candidate until after we verify
that it really is a valid candidate, ie, is at least coercion-compatible
with the given types.
2. oper() and related routines only promise a coercion-compatible result.
Unfortunately, there were quite a few callers that assumed the returned
operator is binary-compatible with the given datatype; they would proceed
to call it without making any datatype coercions. These callers include
sorting, grouping, aggregation, and VACUUM ANALYZE. In general I think
it is appropriate for these callers to require an exact or binary-compatible
match, so I've added a new routine compatible_oper() that only succeeds if
it can find an operator that doesn't require any run-time conversions.
Callers now call oper() or compatible_oper() depending on whether they are
prepared to deal with type conversion or not.
The upshot of these bugs is revealed by the following silliness in PL/Tcl's
selftest: it creates an operator @< on int4, and then tries to use it to
sort a char(N) column. The system would let it do that :-( (and evidently
has done so since 6.3 :-( :-(). The result in this case was just a silly
sort order, but the reverse combination would've provoked coredump from
trying to dereference integers. With this fix you get more reasonable
behavior:
pltcl_test=# select * from T_pkey1 order by key1, key2 using @<;
ERROR: Unable to identify an operator '@<' for types 'bpchar' and 'bpchar'
You will have to retype this query using an explicit cast
25 years ago
|
|
|
/* Routines to find operators that DO NOT require coercion --- ie, their */
|
|
|
|
|
/* input types are either exactly as given, or binary-compatible */
|
|
|
|
|
extern Operator compatible_oper(ParseState *pstate, List *op,
|
|
|
|
|
Oid arg1, Oid arg2,
|
|
|
|
|
bool noError, int location);
|
|
|
|
|
|
Clean up two rather nasty bugs in operator selection code.
1. If there is exactly one pg_operator entry of the right name and oprkind,
oper() and related routines would return that entry whether its input type
had anything to do with the request or not. This is just premature
optimization: we shouldn't return the single candidate until after we verify
that it really is a valid candidate, ie, is at least coercion-compatible
with the given types.
2. oper() and related routines only promise a coercion-compatible result.
Unfortunately, there were quite a few callers that assumed the returned
operator is binary-compatible with the given datatype; they would proceed
to call it without making any datatype coercions. These callers include
sorting, grouping, aggregation, and VACUUM ANALYZE. In general I think
it is appropriate for these callers to require an exact or binary-compatible
match, so I've added a new routine compatible_oper() that only succeeds if
it can find an operator that doesn't require any run-time conversions.
Callers now call oper() or compatible_oper() depending on whether they are
prepared to deal with type conversion or not.
The upshot of these bugs is revealed by the following silliness in PL/Tcl's
selftest: it creates an operator @< on int4, and then tries to use it to
sort a char(N) column. The system would let it do that :-( (and evidently
has done so since 6.3 :-( :-(). The result in this case was just a silly
sort order, but the reverse combination would've provoked coredump from
trying to dereference integers. With this fix you get more reasonable
behavior:
pltcl_test=# select * from T_pkey1 order by key1, key2 using @<;
ERROR: Unable to identify an operator '@<' for types 'bpchar' and 'bpchar'
You will have to retype this query using an explicit cast
25 years ago
|
|
|
/* currently no need for compatible_left_oper/compatible_right_oper */
|
|
|
|
|
|
|
|
|
|
/* Routines for identifying "<", "=", ">" operators for a type */
|
|
|
|
|
extern void get_sort_group_operators(Oid argtype,
|
|
|
|
|
bool needLT, bool needEQ, bool needGT,
|
|
|
|
|
Oid *ltOpr, Oid *eqOpr, Oid *gtOpr,
|
|
|
|
|
bool *isHashable);
|
|
|
|
|
|
|
|
|
|
/* Convenience routines for common calls on the above */
|
|
|
|
|
extern Oid compatible_oper_opid(List *op, Oid arg1, Oid arg2, bool noError);
|
Clean up two rather nasty bugs in operator selection code.
1. If there is exactly one pg_operator entry of the right name and oprkind,
oper() and related routines would return that entry whether its input type
had anything to do with the request or not. This is just premature
optimization: we shouldn't return the single candidate until after we verify
that it really is a valid candidate, ie, is at least coercion-compatible
with the given types.
2. oper() and related routines only promise a coercion-compatible result.
Unfortunately, there were quite a few callers that assumed the returned
operator is binary-compatible with the given datatype; they would proceed
to call it without making any datatype coercions. These callers include
sorting, grouping, aggregation, and VACUUM ANALYZE. In general I think
it is appropriate for these callers to require an exact or binary-compatible
match, so I've added a new routine compatible_oper() that only succeeds if
it can find an operator that doesn't require any run-time conversions.
Callers now call oper() or compatible_oper() depending on whether they are
prepared to deal with type conversion or not.
The upshot of these bugs is revealed by the following silliness in PL/Tcl's
selftest: it creates an operator @< on int4, and then tries to use it to
sort a char(N) column. The system would let it do that :-( (and evidently
has done so since 6.3 :-( :-(). The result in this case was just a silly
sort order, but the reverse combination would've provoked coredump from
trying to dereference integers. With this fix you get more reasonable
behavior:
pltcl_test=# select * from T_pkey1 order by key1, key2 using @<;
ERROR: Unable to identify an operator '@<' for types 'bpchar' and 'bpchar'
You will have to retype this query using an explicit cast
25 years ago
|
|
|
|
|
|
|
|
/* Extract operator OID or underlying-function OID from an Operator tuple */
|
|
|
|
|
extern Oid oprid(Operator op);
|
|
|
|
|
extern Oid oprfuncid(Operator op);
|
|
|
|
|
|
|
|
|
|
/* Build expression tree for an operator invocation */
|
|
|
|
|
extern Expr *make_op(ParseState *pstate, List *opname,
|
|
|
|
|
Node *ltree, Node *rtree, int location);
|
|
|
|
|
extern Expr *make_scalar_array_op(ParseState *pstate, List *opname,
|
|
|
|
|
bool useOr,
|
|
|
|
|
Node *ltree, Node *rtree, int location);
|
|
|
|
|
|
|
|
|
|
#endif /* PARSE_OPER_H */
|