mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Pass collation to makeConst() instead of looking it up internally.
In nearly all cases, the caller already knows the correct collation, and in a number of places, the value the caller has handy is more correct than the default for the type would be. (In particular, this patch makes it significantly less likely that eval_const_expressions will result in changing the exposed collation of an expression.) So an internal lookup is both expensive and wrong.
This commit is contained in:
@ -19,6 +19,7 @@
|
||||
|
||||
#include "access/skey.h"
|
||||
#include "catalog/pg_am.h"
|
||||
#include "catalog/pg_collation.h"
|
||||
#include "catalog/pg_operator.h"
|
||||
#include "catalog/pg_opfamily.h"
|
||||
#include "catalog/pg_type.h"
|
||||
@ -3233,7 +3234,9 @@ network_prefix_quals(Node *leftop, Oid expr_op, Oid opfamily, Datum rightop)
|
||||
|
||||
expr = make_opclause(opr1oid, BOOLOID, false,
|
||||
(Expr *) leftop,
|
||||
(Expr *) makeConst(datatype, -1, -1, opr1right,
|
||||
(Expr *) makeConst(datatype, -1,
|
||||
InvalidOid, /* not collatable */
|
||||
-1, opr1right,
|
||||
false, false),
|
||||
InvalidOid, InvalidOid);
|
||||
result = list_make1(make_simple_restrictinfo(expr));
|
||||
@ -3249,7 +3252,9 @@ network_prefix_quals(Node *leftop, Oid expr_op, Oid opfamily, Datum rightop)
|
||||
|
||||
expr = make_opclause(opr2oid, BOOLOID, false,
|
||||
(Expr *) leftop,
|
||||
(Expr *) makeConst(datatype, -1, -1, opr2right,
|
||||
(Expr *) makeConst(datatype, -1,
|
||||
InvalidOid, /* not collatable */
|
||||
-1, opr2right,
|
||||
false, false),
|
||||
InvalidOid, InvalidOid);
|
||||
result = lappend(result, make_simple_restrictinfo(expr));
|
||||
@ -3288,8 +3293,38 @@ static Const *
|
||||
string_to_const(const char *str, Oid datatype)
|
||||
{
|
||||
Datum conval = string_to_datum(str, datatype);
|
||||
Oid collation;
|
||||
int constlen;
|
||||
|
||||
return makeConst(datatype, -1,
|
||||
((datatype == NAMEOID) ? NAMEDATALEN : -1),
|
||||
/*
|
||||
* We only need to support a few datatypes here, so hard-wire properties
|
||||
* instead of incurring the expense of catalog lookups.
|
||||
*/
|
||||
switch (datatype)
|
||||
{
|
||||
case TEXTOID:
|
||||
case VARCHAROID:
|
||||
case BPCHAROID:
|
||||
collation = DEFAULT_COLLATION_OID;
|
||||
constlen = -1;
|
||||
break;
|
||||
|
||||
case NAMEOID:
|
||||
collation = InvalidOid;
|
||||
constlen = NAMEDATALEN;
|
||||
break;
|
||||
|
||||
case BYTEAOID:
|
||||
collation = InvalidOid;
|
||||
constlen = -1;
|
||||
break;
|
||||
|
||||
default:
|
||||
elog(ERROR, "unexpected datatype in string_to_const: %u",
|
||||
datatype);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return makeConst(datatype, -1, collation, constlen,
|
||||
conval, false, false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user