Skip to content

Commit 51c1316

Browse files
committed
perf(repository): add indexes on sp_action.rollout and rollout_group
Rollout monitoring queries (existsByRolloutId, getStatusCountByRolloutId, getStatusCountByRolloutGroupId) filter by rollout or rollout_group on sp_action. The flyway baseline did not index either column, so Postgres falls back to Seq Scan on every monitoring poll. With 16k action rows this is meaningful — the group-count query takes ~500 ms without the index and ~27 ms with it (Index Only Scan, Heap Fetches: 0). Bench (16k rows, 1000 iter): - WHERE tenant=? AND rollout_group=? 18.6x faster on PG 17.6x faster on YugabyteDB - WHERE tenant=? AND rollout=? GROUP BY status 2.5x faster on PG 1.5x faster on YugabyteDB Adds V1_20_2 sibling migrations for POSTGRESQL, H2, and MYSQL.
1 parent eb53cfa commit 51c1316

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- See POSTGRESQL/V1_20_2__action_rollout_indexes__POSTGRESQL.sql for rationale.
2+
CREATE INDEX IF NOT EXISTS sp_idx_action_rollout_status ON sp_action (tenant, rollout, status);
3+
CREATE INDEX IF NOT EXISTS sp_idx_action_rollout_group ON sp_action (tenant, rollout_group);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- See POSTGRESQL/V1_20_2__action_rollout_indexes__POSTGRESQL.sql for rationale.
2+
-- MySQL ≤ 8.x has no native CREATE INDEX IF NOT EXISTS, so guard via INFORMATION_SCHEMA.
3+
4+
SET @stmt := IF(
5+
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
6+
WHERE table_schema = DATABASE()
7+
AND table_name = 'sp_action'
8+
AND index_name = 'sp_idx_action_rollout_status') = 0,
9+
'CREATE INDEX sp_idx_action_rollout_status ON sp_action (tenant, rollout, status)',
10+
'SELECT 1');
11+
PREPARE _create_idx FROM @stmt;
12+
EXECUTE _create_idx;
13+
DEALLOCATE PREPARE _create_idx;
14+
15+
SET @stmt := IF(
16+
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
17+
WHERE table_schema = DATABASE()
18+
AND table_name = 'sp_action'
19+
AND index_name = 'sp_idx_action_rollout_group') = 0,
20+
'CREATE INDEX sp_idx_action_rollout_group ON sp_action (tenant, rollout_group)',
21+
'SELECT 1');
22+
PREPARE _create_idx FROM @stmt;
23+
EXECUTE _create_idx;
24+
DEALLOCATE PREPARE _create_idx;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-- Add indexes covering rollout-monitoring queries on sp_action.
2+
--
3+
-- existsByRolloutId, getStatusCountByRolloutId, getStatusCountByRolloutGroupId
4+
-- (and similar JPA queries) filter by rollout / rollout_group; the baseline did
5+
-- not index either column, so Postgres falls back to Seq Scan over sp_action on
6+
-- every monitoring poll. With 16k action rows the group-count query takes
7+
-- ~500 ms without the index and ~27 ms with it (Index Only Scan, Heap Fetches: 0).
8+
--
9+
-- IF NOT EXISTS guards against deployments that already created these indexes
10+
-- out-of-band (e.g. via a forked repeatable migration applied prior to this
11+
-- versioned migration landing).
12+
CREATE INDEX IF NOT EXISTS sp_idx_action_rollout_status ON sp_action (tenant, rollout, status);
13+
CREATE INDEX IF NOT EXISTS sp_idx_action_rollout_group ON sp_action (tenant, rollout_group);

0 commit comments

Comments
 (0)