From 327adb62d60c496f148ccbfdca12f67d81ae33f7 Mon Sep 17 00:00:00 2001 From: Sergey Golitsynskiy Date: Wed, 7 Oct 2020 11:53:33 -0400 Subject: [PATCH] Add more missing indexes --- lib/galaxy/model/mapping.py | 10 ++-- .../versions/0170_add_more_missing_indexes.py | 60 +++++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) create mode 100644 lib/galaxy/model/migrate/versions/0170_add_more_missing_indexes.py diff --git a/lib/galaxy/model/mapping.py b/lib/galaxy/model/mapping.py index 11e84951eca..7d68dd3a8d4 100644 --- a/lib/galaxy/model/mapping.py +++ b/lib/galaxy/model/mapping.py @@ -1125,18 +1125,18 @@ model.WorkflowInvocationOutputDatasetAssociation.table = Table( "workflow_invocation_output_dataset_association", metadata, Column("id", Integer, primary_key=True), Column("workflow_invocation_id", Integer, ForeignKey("workflow_invocation.id"), index=True), - Column("workflow_step_id", Integer, ForeignKey("workflow_step.id")), + Column("workflow_step_id", Integer, ForeignKey("workflow_step.id"), index=True), Column("dataset_id", Integer, ForeignKey("history_dataset_association.id"), index=True), - Column("workflow_output_id", Integer, ForeignKey("workflow_output.id")), + Column("workflow_output_id", Integer, ForeignKey("workflow_output.id"), index=True), ) model.WorkflowInvocationOutputDatasetCollectionAssociation.table = Table( "workflow_invocation_output_dataset_collection_association", metadata, Column("id", Integer, primary_key=True), Column("workflow_invocation_id", Integer, ForeignKey("workflow_invocation.id", name='fk_wiodca_wii'), index=True), - Column("workflow_step_id", Integer, ForeignKey("workflow_step.id", name='fk_wiodca_wsi')), + Column("workflow_step_id", Integer, ForeignKey("workflow_step.id", name='fk_wiodca_wsi'), index=True), Column("dataset_collection_id", Integer, ForeignKey("history_dataset_collection_association.id", name='fk_wiodca_dci'), index=True), - Column("workflow_output_id", Integer, ForeignKey("workflow_output.id", name='fk_wiodca_woi')), + Column("workflow_output_id", Integer, ForeignKey("workflow_output.id", name='fk_wiodca_woi'), index=True), ) model.WorkflowInvocationOutputValue.table = Table( @@ -1160,7 +1160,7 @@ model.WorkflowInvocationStepOutputDatasetCollectionAssociation.table = Table( "workflow_invocation_step_output_dataset_collection_association", metadata, Column("id", Integer, primary_key=True), Column("workflow_invocation_step_id", Integer, ForeignKey("workflow_invocation_step.id", name='fk_wisodca_wisi'), index=True), - Column("workflow_step_id", Integer, ForeignKey("workflow_step.id", name='fk_wisodca_wsi')), + Column("workflow_step_id", Integer, ForeignKey("workflow_step.id", name='fk_wisodca_wsi'), index=True), Column("dataset_collection_id", Integer, ForeignKey("history_dataset_collection_association.id", name='fk_wisodca_dci'), index=True), Column("output_name", String(255), nullable=True), ) diff --git a/lib/galaxy/model/migrate/versions/0170_add_more_missing_indexes.py b/lib/galaxy/model/migrate/versions/0170_add_more_missing_indexes.py new file mode 100644 index 00000000000..d5f5fa54703 --- /dev/null +++ b/lib/galaxy/model/migrate/versions/0170_add_more_missing_indexes.py @@ -0,0 +1,60 @@ +""" +Migration script to create missing indexes. Adding new columns to existing tables via SQLAlchemy does not create the index, even if the column definition includes index=True. +""" + +import logging + +from sqlalchemy import MetaData + +from galaxy.model.migrate.versions.util import ( + add_index, + drop_index +) + +log = logging.getLogger(__name__) +metadata = MetaData() + +indexes = [ + [ + "ix_workflow_invocation_output_dataset_association_workflow_output_id", + "workflow_invocation_output_dataset_association", + "workflow_output_id" + ], + [ + "ix_workflow_invocation_output_dataset_association_workflow_step_id", + "workflow_invocation_output_dataset_association", + "workflow_step_id" + ], + [ + "ix_workflow_invocation_output_dataset_collection_association_workflow_output_id", + "workflow_invocation_output_dataset_collection_association", + "workflow_output_id" + ], + [ + "ix_workflow_invocation_output_dataset_collection_association_workflow_step_id", + "workflow_invocation_output_dataset_collection_association", + "workflow_step_id" + ], + [ + "ix_workflow_invocation_step_output_dataset_collection_association_workflow_step_id", + "workflow_invocation_step_output_dataset_collection_association", + "workflow_step_id" + ], +] + + +def upgrade(migrate_engine): + print(__doc__) + metadata.bind = migrate_engine + metadata.reflect() + + for ix, table, col in indexes: + add_index(ix, table, col, metadata) + + +def downgrade(migrate_engine): + metadata.bind = migrate_engine + metadata.reflect() + + for ix, table, col in indexes: + drop_index(ix, table, col, metadata)