Merge "Add database indices to improve query performance"
This commit is contained in:
commit
75f38d1e3c
@ -0,0 +1,210 @@
|
||||
# Copyright 2015 OpenStack Foundation.
|
||||
#
|
||||
# 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 database indices
|
||||
|
||||
Revision ID: 009
|
||||
Revises: 008
|
||||
Create Date: 2015-11-25 19:06:14.975474
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '009'
|
||||
down_revision = '008'
|
||||
|
||||
from alembic import op
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.create_index(
|
||||
'action_definitions_v2_action_class',
|
||||
'action_definitions_v2',
|
||||
['action_class'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'action_definitions_v2_is_system',
|
||||
'action_definitions_v2',
|
||||
['is_system'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'action_definitions_v2_project_id',
|
||||
'action_definitions_v2',
|
||||
['project_id'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'action_definitions_v2_scope',
|
||||
'action_definitions_v2',
|
||||
['scope'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'cron_triggers_v2_next_execution_time',
|
||||
'cron_triggers_v2',
|
||||
['next_execution_time'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'cron_triggers_v2_project_id',
|
||||
'cron_triggers_v2',
|
||||
['project_id'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'cron_triggers_v2_scope',
|
||||
'cron_triggers_v2',
|
||||
['scope'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'cron_triggers_v2_workflow_name',
|
||||
'cron_triggers_v2',
|
||||
['workflow_name'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.drop_constraint(
|
||||
'cron_triggers_v2_workflow_input_hash_workflow_name_pattern__key',
|
||||
'cron_triggers_v2',
|
||||
type_='unique'
|
||||
)
|
||||
|
||||
op.drop_constraint(
|
||||
'cron_triggers_v2_workflow_input_hash_workflow_name_pattern_key1',
|
||||
'cron_triggers_v2',
|
||||
type_='unique'
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'delayed_calls_v2_processing_execution_time',
|
||||
'delayed_calls_v2',
|
||||
['processing', 'execution_time'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'environments_v2_name',
|
||||
'environments_v2',
|
||||
['name'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'environments_v2_project_id',
|
||||
'environments_v2',
|
||||
['project_id'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'environments_v2_scope',
|
||||
'environments_v2',
|
||||
['scope'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'executions_v2_project_id',
|
||||
'executions_v2',
|
||||
['project_id'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'executions_v2_scope',
|
||||
'executions_v2',
|
||||
['scope'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'executions_v2_state',
|
||||
'executions_v2',
|
||||
['state'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'executions_v2_task_execution_id',
|
||||
'executions_v2',
|
||||
['task_execution_id'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'executions_v2_type',
|
||||
'executions_v2',
|
||||
['type'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'executions_v2_updated_at',
|
||||
'executions_v2',
|
||||
['updated_at'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'executions_v2_workflow_execution_id',
|
||||
'executions_v2',
|
||||
['workflow_execution_id'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'workbooks_v2_project_id',
|
||||
'workbooks_v2',
|
||||
['project_id'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'workbooks_v2_scope',
|
||||
'workbooks_v2',
|
||||
['scope'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'workflow_definitions_v2_is_system',
|
||||
'workflow_definitions_v2',
|
||||
['is_system'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'workflow_definitions_v2_project_id',
|
||||
'workflow_definitions_v2',
|
||||
['project_id'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
op.create_index(
|
||||
'workflow_definitions_v2_scope',
|
||||
'workflow_definitions_v2',
|
||||
['scope'],
|
||||
unique=False
|
||||
)
|
@ -54,6 +54,8 @@ class Workbook(Definition):
|
||||
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('name', 'project_id'),
|
||||
sa.Index('%s_project_id' % __tablename__, 'project_id'),
|
||||
sa.Index('%s_scope' % __tablename__, 'scope'),
|
||||
)
|
||||
|
||||
|
||||
@ -64,6 +66,9 @@ class WorkflowDefinition(Definition):
|
||||
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('name', 'project_id'),
|
||||
sa.Index('%s_is_system' % __tablename__, 'is_system'),
|
||||
sa.Index('%s_project_id' % __tablename__, 'project_id'),
|
||||
sa.Index('%s_scope' % __tablename__, 'scope'),
|
||||
)
|
||||
|
||||
|
||||
@ -74,6 +79,10 @@ class ActionDefinition(Definition):
|
||||
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('name', 'project_id'),
|
||||
sa.Index('%s_is_system' % __tablename__, 'is_system'),
|
||||
sa.Index('%s_action_class' % __tablename__, 'action_class'),
|
||||
sa.Index('%s_project_id' % __tablename__, 'project_id'),
|
||||
sa.Index('%s_scope' % __tablename__, 'scope'),
|
||||
)
|
||||
|
||||
# Main properties.
|
||||
@ -92,6 +101,14 @@ class Execution(mb.MistralSecureModelBase):
|
||||
|
||||
__tablename__ = 'executions_v2'
|
||||
|
||||
__table_args__ = (
|
||||
sa.Index('%s_project_id' % __tablename__, 'project_id'),
|
||||
sa.Index('%s_scope' % __tablename__, 'scope'),
|
||||
sa.Index('%s_state' % __tablename__, 'state'),
|
||||
sa.Index('%s_type' % __tablename__, 'type'),
|
||||
sa.Index('%s_updated_at' % __tablename__, 'updated_at'),
|
||||
)
|
||||
|
||||
type = sa.Column(sa.String(50))
|
||||
|
||||
__mapper_args__ = {
|
||||
@ -230,6 +247,12 @@ TaskExecution.executions = relationship(
|
||||
lazy='select'
|
||||
)
|
||||
|
||||
sa.Index(
|
||||
'%s_task_execution_id' % Execution.__tablename__,
|
||||
Execution.task_execution_id
|
||||
)
|
||||
|
||||
|
||||
# Many-to-one for 'TaskExecution' and 'WorkflowExecution'.
|
||||
|
||||
TaskExecution.workflow_execution_id = sa.Column(
|
||||
@ -245,6 +268,11 @@ WorkflowExecution.task_executions = relationship(
|
||||
lazy='select'
|
||||
)
|
||||
|
||||
sa.Index(
|
||||
'%s_workflow_execution_id' % TaskExecution.__tablename__,
|
||||
TaskExecution.workflow_execution_id
|
||||
)
|
||||
|
||||
|
||||
# Other objects.
|
||||
|
||||
@ -254,6 +282,14 @@ class DelayedCall(mb.MistralModelBase):
|
||||
|
||||
__tablename__ = 'delayed_calls_v2'
|
||||
|
||||
__table_args__ = (
|
||||
sa.Index(
|
||||
'%s_processing_execution_time' % __tablename__,
|
||||
'processing',
|
||||
'execution_time'
|
||||
),
|
||||
)
|
||||
|
||||
id = mb.id_column()
|
||||
factory_method_path = sa.Column(sa.String(200), nullable=True)
|
||||
target_method_name = sa.Column(sa.String(80), nullable=False)
|
||||
@ -271,6 +307,9 @@ class Environment(mb.MistralSecureModelBase):
|
||||
|
||||
__table_args__ = (
|
||||
sa.UniqueConstraint('name', 'project_id'),
|
||||
sa.Index('%s_name' % __tablename__, 'name'),
|
||||
sa.Index('%s_project_id' % __tablename__, 'project_id'),
|
||||
sa.Index('%s_scope' % __tablename__, 'scope'),
|
||||
)
|
||||
|
||||
# Main properties.
|
||||
@ -301,7 +340,14 @@ class CronTrigger(mb.MistralSecureModelBase):
|
||||
'workflow_input_hash', 'workflow_name', 'pattern', 'project_id',
|
||||
'workflow_params_hash', 'remaining_executions',
|
||||
'first_execution_time'
|
||||
)
|
||||
),
|
||||
sa.Index(
|
||||
'%s_next_execution_time' % __tablename__,
|
||||
'next_execution_time'
|
||||
),
|
||||
sa.Index('%s_project_id' % __tablename__, 'project_id'),
|
||||
sa.Index('%s_scope' % __tablename__, 'scope'),
|
||||
sa.Index('%s_workflow_name' % __tablename__, 'workflow_name'),
|
||||
)
|
||||
|
||||
id = mb.id_column()
|
||||
|
Loading…
Reference in New Issue
Block a user