Skip literal vs round tripped comparison for non-orderable types in UnwrapCastInComparison#16815
Conversation
|
The optimization works for non-orderable types, too, when they are “equatable” (they support equals/not-equals). What problem are you trying to solve? BTW, you can read more about the optimization here: https://trino.io/blog/2019/05/21/optimizing-the-casts-away.html |
The simple query below, fails because map type is not orderable. Because UnwrapCastInComparison calls |
|
The proper fix would be to check if the type is not orderable but equatable, skip the |
Will try. |
86306fe to
6e64042
Compare
6e64042 to
fd95845
Compare
|
@martint can you review, please? Thanks. |
There was a problem hiding this comment.
This is unnecessary. It can be made to support row types by changing the query to do this, instead:
FROM (VALUES CAST(ROW(%s) AS row(%s))) t(v)fd95845 to
dec4f5f
Compare
There was a problem hiding this comment.
This should never happen. If the type of the right term of the comparison expression were not orderable or comparable, the ComparisonExpression would be invalid.
There was a problem hiding this comment.
Right. This is an additional check arguments like other check arguments as safeguards since this should not add any overheads. Also, I think this is helpful to understand the codes. I can change it to throw instead of silently return. Or do you think it's totally superfluous?
There was a problem hiding this comment.
Yes, it's superfluous. There's an assumption everywhere in the optimizer that the plan that is provided to each rule is well-formed. It's unreasonable to expect that every rule has to validate that structure. Otherwise, we'll end up with these types of checks sprinkled all over the code and we'll end up with code that's much harder to read and follow.
There was a problem hiding this comment.
This is unnecessary, too. It's effectively validating that the ComparisonExpression that was passed to this method is valid, but that's an assumption we don't need to check.
There was a problem hiding this comment.
This is also a safeguard. In case there is a bug in parser/checker, it would be easier to understand what the cause is. And this also improves the code readability. But, if you strongly believe that this is not beneficial at all, I'm fine with deleting it.
dec4f5f to
c913919
Compare
…nwrapCastInComparison - Non-orderable type allows only equality checks, so round tripped comparison cannot be applicable.
c913919 to
ad8151f
Compare
|
The test failures seem irrelevant. Can you merge this if you don't have more comments, please? |
Skip literal vs round tripped comparison for non-orderable types in UnwrapCastInComparison
Description
Additional context and related issues
Release notes
(v ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text: