This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use existing number sequences instead of looking them up again (#2299)
In order to avoid a sequential table scan on the `work_items` DB table we take the already calculated values for the new `number_sequences` table from the old `work_item_number_sequences`. Before this was the query plan for `INSERT` into the new `number_sequences` table: ``` EXPLAIN SELECT space_id, 'work_items' "table_name", MAX(number) FROM work_items WHERE number IS NOT NULL GROUP BY 1,2; +--------------------------------------------------------------------------------+ | QUERY PLAN | |--------------------------------------------------------------------------------| | GroupAggregate (cost=37097.49..38835.71 rows=37629 width=52) | | Group Key: space_id, 'work_items'::text | | -> Sort (cost=37097.49..37437.97 rows=136193 width=52) | | Sort Key: space_id | | -> Seq Scan on work_items (cost=0.00..20824.93 rows=136193 width=52) | | Filter: (number IS NOT NULL) | +--------------------------------------------------------------------------------+ ``` and now it is: ``` EXPLAIN SELECT space_id, 'work_items' "table_name", current_val FROM work_item_number_sequences GROUP BY 1,2; +--------------------------------------------------------------------------------------------------------------------------------+ | QUERY PLAN | |--------------------------------------------------------------------------------------------------------------------------------| | Group (cost=0.29..3541.66 rows=43872 width=52) | | Group Key: space_id, 'work_items'::text | | -> Index Scan using work_item_number_sequences_pkey on work_item_number_sequences (cost=0.29..3322.30 rows=43872 width=52) | +--------------------------------------------------------------------------------------------------------------------------------+ ``` Thanks go out to @jarifibrahim for bringing my attention to this sequential table scan. See #2291
- Loading branch information