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

Q: Evaluation cost of hll_empty() #157

Open
samkillin opened this issue Jan 29, 2024 · 1 comment
Open

Q: Evaluation cost of hll_empty() #157

samkillin opened this issue Jan 29, 2024 · 1 comment

Comments

@samkillin
Copy link

samkillin commented Jan 29, 2024

I am looking to "upsert" hll's in my database, using a traditional two stage query:

# Add an empty HLL if one doesn't exist
INSERT INTO counts(event_type, reference, count) 
VALUES(:event_type, :reference, hll_empty()) 
ON CONFLICT DO NOTHING; 

# Add to the HLL
UPDATE counts 
SET count = hll_add(count, hll_hash_text(:event_id)) 
WHERE event_type = :event_type AND reference = :reference;

Given hll_empty() will be invoked on every query, even in the update case (i.e. before a conflict is identified), how cheap/expensive is that function to execute? The README mentions use of a sentinel value – is this sentinel value recalculated every call?

Should I be concerned with the evaluation of that function being a potential bottleneck compared to hll_add and hll_hash_text?

@emelsimsek
Copy link
Contributor

Looking at the code, hll_empty() in fact creates an empty set (internally represented as a byte array) at every call. So it does not use a precalculated sentinel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants