Skip to content

Commit 72bf29e

Browse files
committed
Custom indexes
1 parent 5c248b5 commit 72bf29e

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

.claude/postgres-puzzle-query-optimization.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ SET
4747
END;
4848

4949
-- Index for filtering
50-
CREATE INDEX idx_pst_puzzling_type ON puzzle_solving_time (puzzling_type);
51-
CREATE INDEX idx_pst_puzzle_type ON puzzle_solving_time (puzzle_id, puzzling_type);
50+
CREATE INDEX custom_pst_puzzling_type ON puzzle_solving_time (puzzling_type);
51+
CREATE INDEX custom_pst_puzzle_type ON puzzle_solving_time (puzzle_id, puzzling_type);
5252
```
5353

5454
### 1.2 PuzzlingType Enum
@@ -772,7 +772,7 @@ CREATE INDEX idx_puzzle_ean ON puzzle (ean) WHERE ean IS NOT NULL;
772772
CREATE INDEX idx_puzzle_identification ON puzzle (identification_number) WHERE identification_number IS NOT NULL;
773773

774774
-- For puzzle_solving_time
775-
CREATE INDEX idx_pst_puzzle_id ON puzzle_solving_time (puzzle_id);
775+
CREATE INDEX custom_pst_puzzle_id ON puzzle_solving_time (puzzle_id);
776776
```
777777

778778
---

migrations/Version20260102230000.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ public function getDescription(): string
1717
public function up(Schema $schema): void
1818
{
1919
// Composite index for player statistics and ranking queries
20-
$this->addSql('CREATE INDEX idx_pst_player_puzzle_type ON puzzle_solving_time (player_id, puzzle_id, puzzling_type)');
20+
$this->addSql('CREATE INDEX custom_pst_player_puzzle_type ON puzzle_solving_time (player_id, puzzle_id, puzzling_type)');
2121

2222
// Index for date-based monthly queries (used after EXTRACT->date range optimization)
23-
$this->addSql('CREATE INDEX idx_pst_tracked_at_type ON puzzle_solving_time (tracked_at, puzzling_type)');
23+
$this->addSql('CREATE INDEX custom_pst_tracked_at_type ON puzzle_solving_time (tracked_at, puzzling_type)');
2424

2525
// Partial index for fastest players/groups/pairs queries
26-
$this->addSql('CREATE INDEX idx_pst_type_time_valid ON puzzle_solving_time (puzzling_type, seconds_to_solve) WHERE seconds_to_solve IS NOT NULL AND suspicious = false');
26+
$this->addSql('CREATE INDEX custom_pst_type_time_valid ON puzzle_solving_time (puzzling_type, seconds_to_solve) WHERE seconds_to_solve IS NOT NULL AND suspicious = false');
2727

2828
// GIN index for JSONB containment on team column (custom_ prefix = Doctrine won't manage it)
2929
$this->addSql('CREATE INDEX custom_pst_team_puzzlers_gin ON puzzle_solving_time USING GIN ((team::jsonb->\'puzzlers\') jsonb_path_ops) WHERE team IS NOT NULL');
3030
}
3131

3232
public function down(Schema $schema): void
3333
{
34-
$this->addSql('DROP INDEX IF EXISTS idx_pst_player_puzzle_type');
35-
$this->addSql('DROP INDEX IF EXISTS idx_pst_tracked_at_type');
36-
$this->addSql('DROP INDEX IF EXISTS idx_pst_type_time_valid');
34+
$this->addSql('DROP INDEX IF EXISTS custom_pst_player_puzzle_type');
35+
$this->addSql('DROP INDEX IF EXISTS custom_pst_tracked_at_type');
36+
$this->addSql('DROP INDEX IF EXISTS custom_pst_type_time_valid');
3737
$this->addSql('DROP INDEX IF EXISTS custom_pst_team_puzzlers_gin');
3838
}
3939
}

tests/bootstrap.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ function createCustomIndexes(): void
167167
$pdo->exec('CREATE INDEX IF NOT EXISTS custom_puzzle_alt_name_unaccent_trgm ON puzzle USING GIN (immutable_unaccent(alternative_name) gin_trgm_ops)');
168168

169169
// Query optimization composite indexes (Version20260102230000)
170-
$pdo->exec('CREATE INDEX IF NOT EXISTS idx_pst_player_puzzle_type ON puzzle_solving_time (player_id, puzzle_id, puzzling_type)');
171-
$pdo->exec('CREATE INDEX IF NOT EXISTS idx_pst_tracked_at_type ON puzzle_solving_time (tracked_at, puzzling_type)');
172-
$pdo->exec('CREATE INDEX IF NOT EXISTS idx_pst_type_time_valid ON puzzle_solving_time (puzzling_type, seconds_to_solve) WHERE seconds_to_solve IS NOT NULL AND suspicious = false');
170+
$pdo->exec('CREATE INDEX IF NOT EXISTS custom_pst_player_puzzle_type ON puzzle_solving_time (player_id, puzzle_id, puzzling_type)');
171+
$pdo->exec('CREATE INDEX IF NOT EXISTS custom_pst_tracked_at_type ON puzzle_solving_time (tracked_at, puzzling_type)');
172+
$pdo->exec('CREATE INDEX IF NOT EXISTS custom_pst_type_time_valid ON puzzle_solving_time (puzzling_type, seconds_to_solve) WHERE seconds_to_solve IS NOT NULL AND suspicious = false');
173173
$pdo->exec("CREATE INDEX IF NOT EXISTS custom_pst_team_puzzlers_gin ON puzzle_solving_time USING GIN ((team::jsonb->'puzzlers') jsonb_path_ops) WHERE team IS NOT NULL");
174174
}
175175

0 commit comments

Comments
 (0)