aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/selfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-03-25 20:10:42 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-03-25 20:10:42 -0400
commitbfa4440ca5d948c4d4f0ab5bb82d433200c35288 (patch)
tree729b839f5f03c46773250ce3d33fc351f394e63e /src/backend/utils/adt/selfuncs.c
parentc8e993503d0f1a0cb8f187a136fb64cead9ba591 (diff)
downloadpostgresql-bfa4440ca5d948c4d4f0ab5bb82d433200c35288.tar.gz
postgresql-bfa4440ca5d948c4d4f0ab5bb82d433200c35288.zip
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/utils/adt/selfuncs.c')
-rw-r--r--src/backend/utils/adt/selfuncs.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 33f300bfea2..c757fcb424f 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -1686,6 +1686,7 @@ scalararraysel(PlannerInfo *root,
Node *leftop;
Node *rightop;
Oid nominal_element_type;
+ Oid nominal_element_collation;
RegProcedure oprsel;
FmgrInfo oprselproc;
Selectivity s1;
@@ -1712,6 +1713,8 @@ scalararraysel(PlannerInfo *root,
nominal_element_type = get_base_element_type(exprType(rightop));
if (!OidIsValid(nominal_element_type))
return (Selectivity) 0.5; /* probably shouldn't happen */
+ /* get nominal collation, too, for generating constants */
+ nominal_element_collation = exprCollation(rightop);
/* look through any binary-compatible relabeling of rightop */
rightop = strip_array_coercion(rightop);
@@ -1759,6 +1762,7 @@ scalararraysel(PlannerInfo *root,
args = list_make2(leftop,
makeConst(nominal_element_type,
-1,
+ nominal_element_collation,
elmlen,
elem_values[i],
elem_nulls[i],
@@ -5616,9 +5620,39 @@ 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);
}
@@ -5635,7 +5669,7 @@ string_to_bytea_const(const char *str, size_t str_len)
SET_VARSIZE(bstr, VARHDRSZ + str_len);
conval = PointerGetDatum(bstr);
- return makeConst(BYTEAOID, -1, -1, conval, false, false);
+ return makeConst(BYTEAOID, -1, InvalidOid, -1, conval, false, false);
}
/*-------------------------------------------------------------------------