Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usused index on task instance #36737

Merged
merged 4 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@

def upgrade():
"""Apply Add index to task_instance table"""
op.create_index(
"ti_state_incl_start_date",
"task_instance",
["dag_id", "task_id", "state"],
postgresql_include=["start_date"],
)
# We don't add this index anymore because it's not useful.
pass


def downgrade():
"""Unapply Add index to task_instance table"""
op.drop_index("ti_state_incl_start_date", table_name="task_instance")
# At 2.8.1 we removed this index as it is not used, and changed this migration not to add it
# So we use drop if exists (cus it might not be there)
dstandish marked this conversation as resolved.
Show resolved Hide resolved
import sqlalchemy
from contextlib import suppress

with suppress(sqlalchemy.exc.DatabaseError): # mysql does not support drop if exists index
op.drop_index("ti_state_incl_start_date", table_name="task_instance", if_exists=True)
50 changes: 50 additions & 0 deletions airflow/migrations/versions/0133_2_8_1_refactor_dag_run_indexes.py
Original file line number Diff line number Diff line change
@@ -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.

"""Drop unused TI index

Revision ID: 88344c1d9134
Revises: 10b52ebd31f7
Create Date: 2024-01-11 11:54:48.232030

"""

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = "88344c1d9134"
down_revision = "10b52ebd31f7"
branch_labels = None
depends_on = None
airflow_version = "2.8.1"


def upgrade():
"""Apply refactor dag run indexes"""
# This index may have been created in 2.7 but we've since removed it from migrations
import sqlalchemy
from contextlib import suppress

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


def downgrade():
"""Unapply refactor dag run indexes"""
1 change: 0 additions & 1 deletion airflow/models/taskinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,6 @@ class TaskInstance(Base, LoggingMixin):
# Existing "ti_state_lkp" is not enough for such query when this table has millions of rows, since
# rows have to be fetched in order to retrieve the start_date column. With this index, INDEX ONLY SCAN
# is performed and that query runs within milliseconds.
Index("ti_state_incl_start_date", dag_id, task_id, state, postgresql_include=["start_date"]),
Index("ti_pool", pool, state, priority_weight),
Index("ti_job_id", job_id),
Index("ti_trigger_id", trigger_id),
Expand Down
1 change: 1 addition & 0 deletions airflow/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"2.6.2": "c804e5c76e3e",
"2.7.0": "405de8318b3a",
"2.8.0": "10b52ebd31f7",
"2.8.1": "88344c1d9134",
}


Expand Down
2 changes: 1 addition & 1 deletion docs/apache-airflow/img/airflow_erd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
194706fc390025f473f73ce934bfe4b394b50ce76748e5df33ae643e38538357
243075d59223245db8034a97c7d6f53bd8a39ee0dc02831229a6ec743c2c920a
4 changes: 2 additions & 2 deletions docs/apache-airflow/img/airflow_erd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion docs/apache-airflow/migrations-ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ Here's the list of all the Database Migrations that are executed via when you ru
+---------------------------------+-------------------+-------------------+--------------------------------------------------------------+
| Revision ID | Revises ID | Airflow Version | Description |
+=================================+===================+===================+==============================================================+
| ``10b52ebd31f7`` (head) | ``bd5dfbe21f88`` | ``2.8.0`` | Add processor_subdir to ImportError. |
| ``88344c1d9134`` (head) | ``10b52ebd31f7`` | ``2.8.1`` | Drop unused TI index |
+---------------------------------+-------------------+-------------------+--------------------------------------------------------------+
| ``10b52ebd31f7`` | ``bd5dfbe21f88`` | ``2.8.0`` | Add processor_subdir to ImportError. |
+---------------------------------+-------------------+-------------------+--------------------------------------------------------------+
| ``bd5dfbe21f88`` | ``f7bf2a57d0a6`` | ``2.8.0`` | Make connection login/password TEXT |
+---------------------------------+-------------------+-------------------+--------------------------------------------------------------+
Expand Down