Skip to content

Commit e7467dc

Browse files
guan404mingephraimbuddy
authored andcommitted
Add index on task_reschedule ti_id (#60931)
(cherry picked from commit 14e811c)
1 parent bb00374 commit e7467dc

6 files changed

Lines changed: 2321 additions & 2509 deletions

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4827b81c01c9a7993d9796da4990f2a950c2069687db4b0e9cba0c0ae851bd9c
1+
4afcc3a71762abf79a5fb3808aab1d52e7a6f170a74d1002e9663f2f35d00d6b

airflow-core/docs/img/airflow_erd.svg

Lines changed: 2255 additions & 2507 deletions
Loading

airflow-core/docs/migrations-ref.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ Here's the list of all the Database Migrations that are executed via when you ru
3939
+-------------------------+------------------+-------------------+--------------------------------------------------------------+
4040
| Revision ID | Revises ID | Airflow Version | Description |
4141
+=========================+==================+===================+==============================================================+
42-
| ``cc92b33c6709`` (head) | ``eaf332f43c7c`` | ``3.1.0`` | Add backward compatibility for serialized DAG format v3 to |
42+
| ``82dbd68e6171`` (head) | ``cc92b33c6709`` | ``3.1.8`` | Add index to task_reschedule ti_id . |
43+
+-------------------------+------------------+-------------------+--------------------------------------------------------------+
44+
| ``cc92b33c6709`` | ``eaf332f43c7c`` | ``3.1.0`` | Add backward compatibility for serialized DAG format v3 to |
4345
| | | | v2. |
4446
+-------------------------+------------------+-------------------+--------------------------------------------------------------+
4547
| ``eaf332f43c7c`` | ``a3c7f2b18d4e`` | ``3.1.0`` | add last_parse_duration to dag model. |
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
"""
20+
Add index to task_reschedule ti_id .
21+
22+
Revision ID: 82dbd68e6171
23+
Revises: cc92b33c6709
24+
Create Date: 2026-01-22 16:25:42.164449
25+
26+
"""
27+
28+
from __future__ import annotations
29+
30+
from alembic import op
31+
32+
# revision identifiers, used by Alembic.
33+
revision = "82dbd68e6171"
34+
down_revision = "cc92b33c6709"
35+
branch_labels = None
36+
depends_on = None
37+
airflow_version = "3.1.8"
38+
39+
40+
def upgrade():
41+
"""Add index to task_reschedule ti_id."""
42+
with op.batch_alter_table("task_reschedule", schema=None) as batch_op:
43+
batch_op.create_index("idx_task_reschedule_ti_id", ["ti_id"], unique=False)
44+
45+
46+
def downgrade():
47+
"""Remove index from task_reschedule ti_id."""
48+
dialect_name = op.get_context().dialect.name
49+
if dialect_name == "mysql":
50+
with op.batch_alter_table("task_reschedule", schema=None) as batch_op:
51+
batch_op.drop_constraint("task_reschedule_ti_fkey", type_="foreignkey")
52+
batch_op.drop_index("idx_task_reschedule_ti_id")
53+
batch_op.create_foreign_key(
54+
"task_reschedule_ti_fkey", "task_instance", ["ti_id"], ["id"], ondelete="CASCADE"
55+
)
56+
else:
57+
with op.batch_alter_table("task_reschedule", schema=None) as batch_op:
58+
batch_op.drop_index("idx_task_reschedule_ti_id")

airflow-core/src/airflow/models/taskreschedule.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from sqlalchemy import (
2626
Column,
2727
ForeignKey,
28+
Index,
2829
Integer,
2930
String,
3031
asc,
@@ -60,6 +61,8 @@ class TaskReschedule(Base):
6061
duration = Column(Integer, nullable=False)
6162
reschedule_date = Column(UtcDateTime, nullable=False)
6263

64+
__table_args__ = (Index("idx_task_reschedule_ti_id", ti_id),)
65+
6366
task_instance = relationship(
6467
"TaskInstance", primaryjoin="TaskReschedule.ti_id == foreign(TaskInstance.id)", uselist=False
6568
)

airflow-core/src/airflow/utils/db.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class MappedClassProtocol(Protocol):
111111
"3.0.0": "29ce7909c52b",
112112
"3.0.3": "fe199e1abd77",
113113
"3.1.0": "cc92b33c6709",
114+
"3.1.8": "82dbd68e6171",
114115
}
115116

116117

0 commit comments

Comments
 (0)