Skip to content

Rewrite GROUP BY queries with constant keys #5198

Open
@puzpuzpuz

Description

@puzpuzpuz

Is your feature request related to a problem?

Our query engine should rewrite

SELECT 1, URL, COUNT(*) AS c FROM hits ORDER BY c DESC LIMIT 10;

to

SELECT 1, URL, c FROM (SELECT URL, COUNT(*) AS c FROM hits ORDER BY c DESC LIMIT 10);

or

SELECT 1, URL, c FROM (SELECT URL, COUNT(*) AS c FROM hits) ORDER BY c DESC LIMIT 10;

The latter queries are more efficient due to smaller hash table key which opens up opportunity to use a specialized hash table implementation, but even within the same hash table implementation having less key columns is beneficial.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    PerformancePerformance improvementsSQLIssues or changes relating to SQL execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions