-
Notifications
You must be signed in to change notification settings - Fork 996
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add index to Provenance.file_id (#17677)
When used as a JOIN condition in `legacy.api.json.release` for the release's files, the `provenance` table is consulted for any records related to the `file_id`. Currently unindexed, this is a sequential scan of the table of ~164k rows, and ~87% of the total query cost. Add an index to what is effectively a primary key to prevent further slowdown as the provenance table grows with more projects publishing. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
- Loading branch information
1 parent
034bc3f
commit bd56b0b
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
warehouse/migrations/versions/635b80625fc9_add_index_to_provenance_file_id.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,43 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
Add index to Provenance.file_id | ||
Revision ID: 635b80625fc9 | ||
Revises: 2f5dbc74c770 | ||
Create Date: 2025-02-28 17:41:58.763011 | ||
""" | ||
|
||
from alembic import op | ||
|
||
revision = "635b80625fc9" | ||
down_revision = "2f5dbc74c770" | ||
|
||
|
||
def upgrade(): | ||
# CREATE INDEX CONCURRENTLY cannot happen inside a transaction. We'll close | ||
# our transaction here and issue the statement. | ||
op.get_bind().commit() | ||
with op.get_context().autocommit_block(): | ||
op.create_index( | ||
"ix_provenance_file_id", | ||
"provenance", | ||
["file_id"], | ||
unique=False, | ||
postgresql_concurrently=True, | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_index( | ||
"ix_provenance_file_id", table_name="provenance", 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