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

Implement approximate solution of distinct count #14632

Closed
ilovesoup opened this issue Feb 4, 2020 · 3 comments · Fixed by #17175
Closed

Implement approximate solution of distinct count #14632

ilovesoup opened this issue Feb 4, 2020 · 3 comments · Fixed by #17175
Assignees
Labels
sig/execution SIG execution type/enhancement The issue or PR belongs to an enhancement.

Comments

@ilovesoup
Copy link
Contributor

Feature Request

Is your feature request related to a problem? Please describe:
User found distinct count very slow and might consume high amount of memory.

Describe the feature you'd like:
SELECT HLL_DISTINCT_COUNT(A) from TBL;
Either TiKV Cop or TiFlash Cop compute hyperloglog of distinct key from each region and group. TiDB therefore merge the HLL result from each group. Essentially HLL provide a data structure that support add, count and merge. Results from each region cop / group can be merged together forms a final results. This final results has a bounded error margin.
https://en.wikipedia.org/wiki/HyperLogLog

Describe alternatives you've considered:
No.

Teachability, Documentation, Adoption, Migration Strategy:
A simple new function. Just need to tell user its not accurate but a lot faster.

@ilovesoup ilovesoup added the type/enhancement The issue or PR belongs to an enhancement. label Feb 4, 2020
@zz-jason zz-jason added the sig/execution SIG execution label Mar 9, 2020
@zz-jason
Copy link
Member

zz-jason commented Apr 8, 2020

@SunRunAway PTAL

@zz-jason
Copy link
Member

zz-jason commented May 8, 2020

maybe we can utilize this package: https://pkg.go.dev/github.com/DataDog/hyperloglog?tab=doc

@zz-jason zz-jason assigned solotzg and unassigned SunRunAway May 13, 2020
@solotzg solotzg changed the title Implement Hyperloglog version of distinct count Implement approximate solution of distinct count May 13, 2020
@solotzg
Copy link
Contributor

solotzg commented May 13, 2020

@zz-jason It better to use BJKST algorithm for lower error rate. According to http://www.vldb.org/pvldb/vol11/p499-harmouch.pdf. This algorithm is also default for clickhouse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@SunRunAway @ilovesoup @zz-jason @solotzg and others