Faster query with a simpler plan by joining with the CTE instead of making IN query #113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I set a benchmark doing 200+ updates/second on the queue (using the current behaviour), and ran both queries 1 after the other in a separate session to get their plans. My change removes the
HashAggregate
. The same plan was with LIMIT 10.Using
PostgreSQL 15.4 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0, 64-bit
.limit_1_before.sql.txt
limit_1_after.sql.txt
The limit 10 was done with a bigger queue doing 40 read/s of batch_size=100.
limit_10.sql.txt