|
| 1 | +defmodule Algora.Repo.Migrations.AddTalentQueryPerformanceIndexes do |
| 2 | + use Ecto.Migration |
| 3 | + |
| 4 | + @disable_ddl_transaction true |
| 5 | + @disable_migration_lock true |
| 6 | + |
| 7 | + def change do |
| 8 | + # Index 1: Composite index for job_postings subquery (org-specific job exclusion) |
| 9 | + # Improves: SELECT id FROM job_postings WHERE user_id IN (...) |
| 10 | + create_if_not_exists index(:job_postings, [:user_id, :id], concurrently: true) |
| 11 | + |
| 12 | + # Index 2: Composite index for job_interviews lookup (org-specific interview exclusion) |
| 13 | + # Improves: WHERE ji.user_id = ? AND ji.status != 'initial' AND ji.job_posting_id IN (...) |
| 14 | + create_if_not_exists index(:job_interviews, [:user_id, :status, :job_posting_id], concurrently: true) |
| 15 | + |
| 16 | + # Index 3: Composite index for users handle lookup in subquery |
| 17 | + # Improves: SELECT id FROM users WHERE handle = ? |
| 18 | + create_if_not_exists index(:users, [:handle, :id], |
| 19 | + where: "handle IS NOT NULL", |
| 20 | + concurrently: true |
| 21 | + ) |
| 22 | + |
| 23 | + # Index 4: Composite index for main pipeline filter combination |
| 24 | + # Improves the base WHERE clause filters applied to all talent queries |
| 25 | + create_if_not_exists index( |
| 26 | + :users, |
| 27 | + [:type, :open_to_new_role, :country, :provider_login], |
| 28 | + where: "type = 'individual' AND open_to_new_role = true AND provider_login IS NOT NULL", |
| 29 | + concurrently: true, |
| 30 | + name: :users_pipeline_base_idx |
| 31 | + ) |
| 32 | + |
| 33 | + # Index 5: Index for job_matches user_id lookup |
| 34 | + # Improves: WHERE jm.user_id = ? AND jm.job_posting_id IN (...) |
| 35 | + create_if_not_exists index(:job_matches, [:user_id, :job_posting_id], concurrently: true) |
| 36 | + end |
| 37 | +end |
0 commit comments