-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create index to find non empty titles for assigments
A big time of the query time of get_assignments is spent finding assignments with not null titles. Create an index on that condition trying to speed it up.
- Loading branch information
Showing
2 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
lms/migrations/versions/b39108c0cd35_index_on_assignment_title_is_not_null.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Index on assignment.title is not null.""" | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
revision = "b39108c0cd35" | ||
down_revision = "3d0c022c716c" | ||
|
||
|
||
def upgrade() -> None: | ||
# CONCURRENTLY can't be used inside a transaction. Finish the current one. | ||
op.execute("COMMIT") | ||
|
||
op.create_index( | ||
"ix__assignment_title_is_not_null", | ||
"assignment", | ||
["title"], | ||
unique=False, | ||
postgresql_where=sa.text("title IS NOT NULL"), | ||
postgresql_concurrently=True, | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.execute("COMMIT") | ||
|
||
op.drop_index( | ||
"ix__assignment_title_is_not_null", | ||
table_name="assignment", | ||
postgresql_where=sa.text("title IS NOT NULL"), | ||
postgresql_concurrently=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters