Skip to content
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

Fix to #29667 - Count after Take throws "No column name was specified for column 1 of 't'." #30134

Merged
merged 1 commit into from
Jan 26, 2023

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Jan 25, 2023

Problem was that in some cases (e.g. count over keyless entity that has been pushed down) we now generate empty projection in the subquery, where before we were projecting some columns. SQL Server doesn't allow unaliased projection in the subquery, so the fix is to simply add an alias to the empty projection that we generate.

Fixes #29667

@maumar maumar requested review from roji and a team January 25, 2023 02:48
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great that the fix ended up this simple... We should consider servicing.

See only test comments below.


SELECT COUNT(*)
FROM (
SELECT TOP(@__p_0) [k].[Number]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it a bit odd that just adding OrderBy makes the subquery project out [Number], and when we remove it the projection disappears? I wouldn't expect OrderBy to have any effect on whether we project out or not...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when we perform pushdown we add ordering from the subquery to the outer (so that we can order by it in the final result if needed - e.g. Correlated_collection_with_top_level_Last_with_order_by_on_inner) and in order to construct that ordering for outer we need to add it to the projection in the inner. In this case we don't end up using it, so maybe we could try prune it, but might be tricky.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, that makes sense 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filed #30143 to track this

… for column 1 of 't'."

Problem was that in some cases (e.g. count over keyless entity that has been pushed down) we now generate empty projection in the subquery, where before we were projecting some columns.
SQL Server doesn't allow unaliased projection in the subquery, so the fix is to simply add an alias to the empty projection that we generate.

Fixes #29667
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Count after Take throws "No column name was specified for column 1 of 't'."
2 participants