question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Optimize DISTINCT + ORDER BY

See original GitHub issue

Following Slack discussion : https://apache-pinot.slack.com/archives/C011C9JHN7R/p1623782718117700

Context Documents: 100M Segments: 90

Query Getting DISTINCT values for a low cardinality column (45 distinct STRINGs)

Query select DISTINCT(kpi) from kpis takes ~10ms While select DISTINCT(kpi) from kpis ORDER BY kpi takes more than 300ms

Please have a look at the discussion by @mayankshriv and @kishoreg for more technical details

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
atriscommented, Jul 12, 2021

I would say that we document this behaviour and make users aware of this scenario. WDYT?

0reactions
mayankshrivcommented, Jul 19, 2021

Since we have agreement, marking the issue as closed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DISTINCT with ORDER BY very slow - sql - Stack Overflow
CREATE INDEX call_logs_timestamp ON public.call_logs USING btree (timestamp) TABLESPACE pg_default;. I have tried the below index but does not ...
Read more >
MySQL 8.0 Reference Manual :: 8.2.1.18 DISTINCT Optimization
Because DISTINCT may use GROUP BY , learn how MySQL works with columns in ORDER BY or HAVING clauses that are not part...
Read more >
How to speed up select distinct? - DBA Stack Exchange
Select first row in each GROUP BY group? Optimize GROUP BY query to retrieve latest row per user. Either way, if time intervals...
Read more >
SQL Server ORDER BY performance tips
The Distinct Sort Operator performs eliminating the duplicate rows and sort operations at the same time. 1. SELECT DISTINCT p ...
Read more >
SQL SERVER - Distinct and ORDER BY
The main question which I received is around, why ORDER BY is not required with the DISTINCT. Well, the answer is pretty simple....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found