Remove unsound varchar->char implicit coercion#10499
Remove unsound varchar->char implicit coercion#10499ebyhr wants to merge 1 commit intotrinodb:masterfrom
Conversation
0984145 to
87283c6
Compare
A conversion from varchar to char adds padding, so it's unsafe to
do it automatically. For example, given a table t with a column v
of type varchar(100), and function that performs the following operation:
function foo(x::char(100)) := '<' || x || '>'
A query such as this would produce surprising results:
SELECT foo(v) from t
It would be more reasonable to fail the query due to a type mismatch.
Moreover, the implicit coercion between varchar and char is lossy.
The way it's currently defined, if the string is larger than the
max allowed size for the char type, it will be silently truncated.
Part of the reason this worked like it does was because of lack of
store assignment conversions during insert. That feature is now supported
by the engine, so we can change the coercion rules to fix the surprising
cases without losing that functionality.
87283c6 to
217514b
Compare
|
AFAIR, the tpch/tpcds template queries need to be updated. |
There was a problem hiding this comment.
This is NOGO as long as tpcds queries need to be changed (when comparing char table column with string literal).
We need to fix character string comparison too. One way to do it would be to have a cast dedicated for comparisons.
Some old doc about it https://docs.google.com/document/d/1UngGirjV_I7nPnIGU6G7SDS0cY8j7N_Jb3Wk3EoHChc/edit?usp=sharing
wdym? We should have proper mechanism for character type comparisons in place before we flip coercion from varchar -> char |
|
If I recall correctly, to be able to reverse the order of char<->varchar implicit casts we first need to:
|
That's interesting. There isn't an assumption that BTW, this problem is preexisting. For instance |
I've seen examples of code that tries to handle both "bare" literals, and literals wrapped in Cast. E.g. However, some sites would be affected, e.g. PPD or |
for trino/core/trino-main/src/main/java/io/trino/cost/ScalarStatsCalculator.java Lines 148 to 152 in 8e40a44 for PPD -- would be good to be more explicit about problems' addresses, as the class is too long to read at once |
I meant the part where the predicate is pushed through a ProjectNode, and the conjuncts to push are extracted: the |
I meant |
Thanks! |
|
|
Let me close because there are blockers (e.g. "treat string literals as char(n)"). Thanks for reviewing the PR. |
cc: @martint