Skip to content

Improve PostgreSQL functions#3770

Merged
roger2hk merged 4 commits intogoogle:masterfrom
robstradling:improve_postgres_functions
Apr 10, 2025
Merged

Improve PostgreSQL functions#3770
roger2hk merged 4 commits intogoogle:masterfrom
robstradling:improve_postgres_functions

Conversation

@robstradling
Copy link
Contributor

@robstradling robstradling commented Apr 3, 2025

In our CT logs that use the PostgreSQL quota manager, we've found that in practice ANALYZE (SKIP_LOCKED TRUE) in the count_estimate() function gets skipped a lot of the time. Removing (SKIP_LOCKED TRUE) hurts performance, because it first has to wait for a lock and then it holds that lock until the ANALYZE operation completes. For tables with a relatively small number of rows, it's actually a lot quicker to do a simple SELECT count(1) query (whereas for large tables, SELECT count(1) is very slow). This PR implements a hybrid approach that avoids running ANALYZE when there are <1000 rows and avoids running SELECT count(1) for >1000 rows. We've deployed this to our Elephant and Tiger CT logs, and it's definitely improved performance.

This PR also implements a couple of minor editorial changes to the queue_leaves() and add_sequenced_leaves() functions.

Checklist

@robstradling robstradling requested a review from a team as a code owner April 3, 2025 19:02
@roger2hk
Copy link
Contributor

roger2hk commented Apr 3, 2025

/gcbrun

@robstradling robstradling mentioned this pull request Apr 9, 2025
2 tasks
@roger2hk
Copy link
Contributor

roger2hk commented Apr 9, 2025

@AlCutter ping :)

@roger2hk roger2hk merged commit 84855a0 into google:master Apr 10, 2025
12 checks passed
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

Successfully merging this pull request may close these issues.

3 participants