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

Rewrite GROUP BY queries with trivial expressions over the same column #4141

Open
puzpuzpuz opened this issue Jan 17, 2024 · 0 comments
Open
Labels
Performance Performance improvements SQL Issues or changes relating to SQL execution

Comments

@puzpuzpuz
Copy link
Contributor

puzpuzpuz commented Jan 17, 2024

Is your feature request related to a problem?

Example query:

-- 2.9s
SELECT ClientIP, ClientIP - 1, ClientIP - 2, ClientIP - 3, COUNT(*) AS c FROM hits GROUP BY ClientIP, ClientIP - 1, ClientIP - 2, ClientIP - 3 ORDER BY c DESC LIMIT 10;

Here ClientIP is INT. This query can be rewritten in the following form:

-- 2.1s
SELECT ClientIP, ClientIP - 1, ClientIP - 2, ClientIP - 3, COUNT
FROM (SELECT ClientIP, COUNT(*) AS c FROM hits GROUP BY ClientIP ORDER BY c DESC LIMIT 10);

Apart from subtraction, we could support adding, multiplication and division.

Describe the solution you'd like.

No response

Describe alternatives you've considered.

No response

Full Name:

Andrei Pechkurov

Affiliation:

QuestDB

Additional context

No response

@puzpuzpuz puzpuzpuz added SQL Issues or changes relating to SQL execution Performance Performance improvements labels Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Performance Performance improvements SQL Issues or changes relating to SQL execution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant