Skip to content

Commit

Permalink
Remove unused index idx_last_scheduling_decision on dag_run table
Browse files Browse the repository at this point in the history
  • Loading branch information
pankajkoti committed Apr 26, 2024
1 parent 7683344 commit 6ae0e52
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
Expand Up @@ -48,7 +48,9 @@ def upgrade():

with op.batch_alter_table("dag_run", schema=None) as batch_op:
batch_op.add_column(sa.Column("last_scheduling_decision", TIMESTAMP, nullable=True))
batch_op.create_index("idx_last_scheduling_decision", ["last_scheduling_decision"], unique=False)
# Earlier we had here an index created on the last_scheduling_decision column.
# But we don't add it anymore since it's not useful.

batch_op.add_column(sa.Column("dag_hash", sa.String(32), nullable=True))

with op.batch_alter_table("dag", schema=None) as batch_op:
Expand Down Expand Up @@ -95,8 +97,14 @@ def downgrade():
if is_sqlite:
op.execute("PRAGMA foreign_keys=off")

# At 2.9.1 we removed idx_last_scheduling_decision index as it is not used, and changed this migration
# not to add it. So we use drop if exists (because it might not be there)
from contextlib import suppress

with suppress(sa.exc.DatabaseError): # mysql does not support drop if exists index
op.drop_index("idx_last_scheduling_decision", table_name="dag_run", if_exists=True)

with op.batch_alter_table("dag_run", schema=None) as batch_op:
batch_op.drop_index("idx_last_scheduling_decision")
batch_op.drop_column("last_scheduling_decision")
batch_op.drop_column("dag_hash")

Expand Down
@@ -0,0 +1,50 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

"""Remove idx_last_scheduling_decision index on last_scheduling_decision in dag_run table
Revision ID: bff083ad727d
Revises: 677fdbb7fc54
Create Date: 2024-04-26 12:58:00.594762
"""

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = 'bff083ad727d'
down_revision = '677fdbb7fc54'
branch_labels = None
depends_on = None
airflow_version = "2.9.1"


def upgrade():
"""Apply Remove idx_last_scheduling_decision index on last_scheduling_decision in dag_run table"""
# This index may have been created in 2.0.0, but we've since removed it from migrations
from contextlib import suppress

with suppress(sa.exc.DatabaseError): # mysql does not support drop if exists index
op.drop_index("idx_last_scheduling_decision", table_name="dag_run", if_exists=True)


def downgrade():
"""Unapply Remove idx_last_scheduling_decision index on last_scheduling_decision in dag_run table"""
pass
1 change: 0 additions & 1 deletion airflow/models/dagrun.py
Expand Up @@ -159,7 +159,6 @@ class DagRun(Base, LoggingMixin):
Index("dag_id_state", dag_id, _state),
UniqueConstraint("dag_id", "execution_date", name="dag_run_dag_id_execution_date_key"),
UniqueConstraint("dag_id", "run_id", name="dag_run_dag_id_run_id_key"),
Index("idx_last_scheduling_decision", last_scheduling_decision),
Index("idx_dag_run_dag_id", dag_id),
Index(
"idx_dag_run_running_dags",
Expand Down
2 changes: 1 addition & 1 deletion docs/apache-airflow/img/airflow_erd.sha256
@@ -1 +1 @@
77757e21aee500cb7fe7fd75e0f158633a0037d4d74e6f45eb14238f901ebacd
7d4476fcd1b0d32102dea401db1baaf9d32130beeff82aff13c0b01bad3e0fcf
5 changes: 4 additions & 1 deletion docs/apache-airflow/migrations-ref.rst
Expand Up @@ -39,7 +39,10 @@ Here's the list of all the Database Migrations that are executed via when you ru
+---------------------------------+-------------------+-------------------+--------------------------------------------------------------+
| Revision ID | Revises ID | Airflow Version | Description |
+=================================+===================+===================+==============================================================+
| ``677fdbb7fc54`` (head) | ``1949afb29106`` | ``2.10.0`` | add new executor field to db |
| ``bff083ad727d`` (head) | ``677fdbb7fc54`` | ``2.9.1`` | Remove idx_last_scheduling_decision index on |
| | | | last_scheduling_decision in dag_run table |
+---------------------------------+-------------------+-------------------+--------------------------------------------------------------+
| ``677fdbb7fc54`` | ``1949afb29106`` | ``2.10.0`` | add new executor field to db |
+---------------------------------+-------------------+-------------------+--------------------------------------------------------------+
| ``1949afb29106`` | ``ee1467d4aa35`` | ``2.9.0`` | update trigger kwargs type and encrypt |
+---------------------------------+-------------------+-------------------+--------------------------------------------------------------+
Expand Down

0 comments on commit 6ae0e52

Please sign in to comment.