Paijo commited on
update alembic/versions/92afc781690f_add_composite_index_for_query_.py
Browse files
alembic/versions/92afc781690f_add_composite_index_for_query_.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""add_composite_index_for_query_optimization
|
| 2 |
+
|
| 3 |
+
Revision ID: 92afc781690f
|
| 4 |
+
Revises: a77d14e2bb80
|
| 5 |
+
Create Date: 2026-01-13 13:01:07.438918
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from typing import Sequence, Union
|
| 10 |
+
|
| 11 |
+
from alembic import op
|
| 12 |
+
import sqlalchemy as sa
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
# revision identifiers, used by Alembic.
|
| 16 |
+
revision: str = "92afc781690f"
|
| 17 |
+
down_revision: Union[str, None] = "a77d14e2bb80"
|
| 18 |
+
branch_labels: Union[str, Sequence[str], None] = None
|
| 19 |
+
depends_on: Union[str, Sequence[str], None] = None
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def upgrade() -> None:
|
| 23 |
+
# Add composite index for optimizing the most common query pattern:
|
| 24 |
+
# WHERE is_working = true AND validation_status = 'validated' ORDER BY quality_score DESC
|
| 25 |
+
op.create_index(
|
| 26 |
+
"idx_proxy_working_status_quality",
|
| 27 |
+
"proxies",
|
| 28 |
+
["is_working", "validation_status", "quality_score"],
|
| 29 |
+
unique=False,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def downgrade() -> None:
|
| 34 |
+
# Remove the composite index
|
| 35 |
+
op.drop_index("idx_proxy_working_status_quality", table_name="proxies")
|