-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix next-subscribers batch query for a ~210x speedup.
It was observed that the next-campaign-subscribers query on an instance with ~9 million subscribers had slowed down significantly. Fetching a batch of 5k subscribers was taking around ~25 seconds. After multiple hours of debugging and trial and errors, it turned out that Postgres was doing very poor query planning on JOINs with CTEs because of the dynamic cardinality of some CTEs (even with just 1 row). Afer rewriting the query and adding a hack to overcome the CTE cardinality issue, the same query now takes a few milliseconds, a speed up of several orders of magnitude.
- Loading branch information
Showing
1 changed file
with
19 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters