diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-25 20:10:42 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-03-25 20:10:42 -0400 |
commit | bfa4440ca5d948c4d4f0ab5bb82d433200c35288 (patch) | |
tree | 729b839f5f03c46773250ce3d33fc351f394e63e /src/backend/optimizer/path/indxpath.c | |
parent | c8e993503d0f1a0cb8f187a136fb64cead9ba591 (diff) |
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.
Diffstat (limited to 'src/backend/optimizer/path/indxpath.c')
-rw-r--r-- | src/backend/optimizer/path/indxpath.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c index 925155c64d4..ecae57bdbbf 100644 --- a/src/backend/optimizer/path/indxpath.c +++ b/src/backend/optimizer/path/indxpath.c @@ -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); } |