Skip to content

Commit 8a4027f

Browse files
ubermenAlice Berard
authored and
Alice Berard
committed
[AIRFLOW-3001] Add index 'ti_dag_date' to taskinstance (apache#3885)
To optimize query performance
1 parent 3269f4e commit 8a4027f

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
"""add index to taskinstance
20+
21+
Revision ID: bf00311e1990
22+
Revises: dd25f486b8ea
23+
Create Date: 2018-09-12 09:53:52.007433
24+
25+
"""
26+
27+
from alembic import op
28+
29+
# revision identifiers, used by Alembic.
30+
revision = 'bf00311e1990'
31+
down_revision = 'dd25f486b8ea'
32+
branch_labels = None
33+
depends_on = None
34+
35+
36+
def upgrade():
37+
op.create_index(
38+
'ti_dag_date',
39+
'task_instance',
40+
['dag_id', 'execution_date'],
41+
unique=False
42+
)
43+
44+
45+
def downgrade():
46+
op.drop_index('ti_dag_date', table_name='task_instance')

airflow/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ class TaskInstance(Base, LoggingMixin):
887887

888888
__table_args__ = (
889889
Index('ti_dag_state', dag_id, state),
890+
Index('ti_dag_date', dag_id, execution_date),
890891
Index('ti_state', state),
891892
Index('ti_state_lkp', dag_id, task_id, execution_date, state),
892893
Index('ti_pool', pool, state, priority_weight),

0 commit comments

Comments
 (0)