diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-10-25 17:19:17 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-10-25 17:19:17 +0000 |
commit | 6571729d5490d12505ab5b6f180f15fe593c3105 (patch) | |
tree | 0b736bf1aa882a2672236367c3221bd56d591b2f /src/backend/parser/parse_coerce.c | |
parent | d4a1e5b0a3cd503de0f84e4c423643e0788bb066 (diff) |
Add a heuristic to transformAExprIn() to make it prefer expanding "x IN (list)"
into an OR of equality comparisons, rather than x = ANY(ARRAY[...]), when there
are Vars in the right-hand side. This avoids a performance regression compared
to pre-8.2 releases, in cases where the OR form can be optimized into scans
of multiple indexes. Limit the possible downside by preferring this form only
when the list isn't very long (I set the cutoff at 32 elements, which is a
bit arbitrary but in the right ballpark). Per discussion with Jim Nasby.
In passing, also make it try the OR form if it cannot select a common type
for the array elements; we've seen a complaint or two about how the OR form
worked for such cases and ARRAY doesn't.
Diffstat (limited to 'src/backend/parser/parse_coerce.c')
-rw-r--r-- | src/backend/parser/parse_coerce.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/backend/parser/parse_coerce.c b/src/backend/parser/parse_coerce.c index 24676404340..7933283cabc 100644 --- a/src/backend/parser/parse_coerce.c +++ b/src/backend/parser/parse_coerce.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.161 2008/01/11 18:39:40 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.161.2.1 2008/10/25 17:19:17 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -961,7 +961,8 @@ coerce_to_specific_type(ParseState *pstate, Node *node, * 'typeids' is a nonempty list of type OIDs. Note that earlier items * in the list will be preferred if there is doubt. * 'context' is a phrase to use in the error message if we fail to select - * a usable type. + * a usable type. Pass NULL to have the routine return InvalidOid + * rather than throwing an error on failure. */ Oid select_common_type(List *typeids, const char *context) @@ -1013,6 +1014,8 @@ select_common_type(List *typeids, const char *context) /* * both types in different categories? then not much hope... */ + if (context == NULL) + return InvalidOid; ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), |