-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting prefer_column_name_to_alias=1
makes column names refer to the wrong sub-query column
#47552
Comments
I experience the same issue with enabled WITH first_table AS (
SELECT '2023-06-02' AS day
), second_table AS (
SELECT '2023-06-03' AS day
)
SELECT day, day >= '2023-06-01' AS condition_from_where_filter_is_always_true
FROM (
SELECT
CASE
WHEN first_table.day != '' THEN first_table.day
ELSE second_table.day
END AS day
FROM first_table
FULL OUTER JOIN second_table
ON (first_table.day = second_table.day)
) AS virtual_table
WHERE day >= '2023-06-01'
SETTINGS prefer_column_name_to_alias = 1 returns 1 row:
after changing settings to
|
It is expected that prefer_column_name_to_alias has to pick the first alias after group by statements, otherwise it works incorrect. |
@HSEhomework The workaround we found is to insert the sub-query content into a We are looking to ditch that setting as it's behavior seems unreliable. |
Fixed by Analyzer: https://fiddle.clickhouse.com/dba9ab3d-4a6b-4034-91be-ea108a4c1fa1 |
What's wrong
Using the setting
prefer_column_name_to_alias=1
.With multiple
SELECT
sub-queries in which columns are aliased to the same name, using those alias in the top query seems to refer columns of the bottom query.Does it reproduce on recent release?
I first detected the bug on release
v22.7.3.5
. I was able to reproduce it on ClickHouse Fiddle using the latest releasev23.2.3.17-stable
.How to reproduce
v22.7.3.5
orv23.2.3.17-stable
(may be any) ;prefer_column_name_to_alias=1
;Expected behavior
The expected result is :
While the actual result is empty :
It seems like the columns used in the
WHERE
condition are referencingT1
columns instead ofT2
.For your convenience, here are the returned values of
T1
andT2
:T1
T2
The text was updated successfully, but these errors were encountered: