Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.36.0
-
None
-
None
Description
SqlCoalesceFunction has a rewriteCall() method which will replace the call with an SqlCase call during the unconditional rewrites stage.
But expanding natural joins and USING conditions is done using COALESCE calls in a later validation stage.
As a result, the following query:
WITH A AS (SELECT 1 AS X) SELECT COALESCE(A0.X, A1.X), * FROM A AS A0 NATURAL JOIN A AS A1
is transformed by the validation step into:
WITH `A` AS (SELECT 1 AS `X`) SELECT CASE WHEN `A0`.`X` IS NOT NULL THEN `A0`.`X` ELSE `A1`.`X` END, COALESCE(`A0`.`X`, `A1`.`X` AS `X0`) AS `X` FROM `A` AS `A0` NATURAL INNER JOIN `A` AS `A1`
Maybe, the expanded results of * with natural joins and of USING should pass through unconditional rewrites at creation.