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

🪲 COUNT(*) and DISTINCT #2319

Closed
joocer opened this issue Jan 25, 2025 · 1 comment · Fixed by #2364
Closed

🪲 COUNT(*) and DISTINCT #2319

joocer opened this issue Jan 25, 2025 · 1 comment · Fixed by #2364
Assignees
Labels
Bug 🪲 Something isn't working High Priority 1️⃣

Comments

@joocer
Copy link
Contributor

joocer commented Jan 25, 2025

These two queries should return the same result, as id is unique values

SELECT COUNT(*) FROM (SELECT DISTINCT id FROM $planets) AS S
SELECT COUNT(*) FROM (SELECT id FROM $planets) AS S

but the inclusion of DISTINCT in the first query causes the result to be incorrect.

@joocer joocer added Bug 🪲 Something isn't working High Priority 1️⃣ labels Jan 25, 2025
@joocer
Copy link
Contributor Author

joocer commented Jan 27, 2025

The problem appears to be the projection pushdown and count(*) optimizations.

Because count(*) doesn't reference any columns when we remove the subquery we don't reference any of the inner columns.

What we need to do is ensure the distinct explicitly references the columns so that the projection pushdown doesn't eliminate them.

Currently the reference to columns by distinct is implied, it references all of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Something isn't working High Priority 1️⃣
Projects
None yet
1 participant