diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index d6efd07073a..cbc70fde716 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -5295,6 +5295,14 @@ convert_string_datum(Datum value, Oid typid, Oid collid, bool *failure) return NULL; } + /* + * If we don't have a collation, act as though it's "C". This would + * normally happen only for the "char" type, but perhaps there are other + * cases. + */ + if (!OidIsValid(collid)) + return val; + mylocale = pg_newlocale_from_collation(collid); if (!mylocale->collate_is_c) diff --git a/src/test/regress/expected/planner_est.out b/src/test/regress/expected/planner_est.out index b62a47552fa..236cb274a78 100644 --- a/src/test/regress/expected/planner_est.out +++ b/src/test/regress/expected/planner_est.out @@ -210,4 +210,15 @@ false, true, false, true); -> Result (cost=N..N rows=1 width=N) (4 rows) +-- Verify that scalarineqsel() works on "char" columns +CREATE TEMP TABLE char_table_1 AS + SELECT i::"char" AS c FROM generate_series(64,96) i; +ANALYZE char_table_1; +EXPLAIN (COSTS OFF) SELECT * FROM char_table_1 WHERE c < 'Q'; + QUERY PLAN +----------------------------- + Seq Scan on char_table_1 + Filter: (c < 'Q'::"char") +(2 rows) + DROP FUNCTION explain_mask_costs(text, bool, bool, bool, bool); diff --git a/src/test/regress/sql/planner_est.sql b/src/test/regress/sql/planner_est.sql index 53210d5baad..2b696a4e4e5 100644 --- a/src/test/regress/sql/planner_est.sql +++ b/src/test/regress/sql/planner_est.sql @@ -147,4 +147,10 @@ SELECT explain_mask_costs($$ SELECT * FROM tenk1 WHERE unique1 <> ALL (ARRAY[1, 2, 98, (SELECT 99), NULL]);$$, false, true, false, true); +-- Verify that scalarineqsel() works on "char" columns +CREATE TEMP TABLE char_table_1 AS + SELECT i::"char" AS c FROM generate_series(64,96) i; +ANALYZE char_table_1; +EXPLAIN (COSTS OFF) SELECT * FROM char_table_1 WHERE c < 'Q'; + DROP FUNCTION explain_mask_costs(text, bool, bool, bool, bool);