[ 
https://issues.apache.org/jira/browse/AIRFLOW-3001?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16647708#comment-16647708
 ] 

ASF GitHub Bot commented on AIRFLOW-3001:
-----------------------------------------

Fokko closed pull request #3885: [AIRFLOW-3001] Add index 'ti_dag_date' to 
taskinstance
URL: https://github.com/apache/incubator-airflow/pull/3885
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/airflow/migrations/versions/bf00311e1990_add_index_to_taskinstance.py 
b/airflow/migrations/versions/bf00311e1990_add_index_to_taskinstance.py
new file mode 100644
index 0000000000..528bd53b36
--- /dev/null
+++ b/airflow/migrations/versions/bf00311e1990_add_index_to_taskinstance.py
@@ -0,0 +1,46 @@
+#
+# 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.
+
+"""add index to taskinstance
+
+Revision ID: bf00311e1990
+Revises: dd25f486b8ea
+Create Date: 2018-09-12 09:53:52.007433
+
+"""
+
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision = 'bf00311e1990'
+down_revision = 'dd25f486b8ea'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+    op.create_index(
+        'ti_dag_date',
+        'task_instance',
+        ['dag_id', 'execution_date'],
+        unique=False
+    )
+
+
+def downgrade():
+    op.drop_index('ti_dag_date', table_name='task_instance')
diff --git a/airflow/models.py b/airflow/models.py
index 86a9cc2fc6..788bc54461 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -893,6 +893,7 @@ class TaskInstance(Base, LoggingMixin):
 
     __table_args__ = (
         Index('ti_dag_state', dag_id, state),
+        Index('ti_dag_date', dag_id, execution_date),
         Index('ti_state', state),
         Index('ti_state_lkp', dag_id, task_id, execution_date, state),
         Index('ti_pool', pool, state, priority_weight),


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Accumulative tis slow allocation of new schedule
> ------------------------------------------------
>
>                 Key: AIRFLOW-3001
>                 URL: https://issues.apache.org/jira/browse/AIRFLOW-3001
>             Project: Apache Airflow
>          Issue Type: Improvement
>          Components: scheduler
>    Affects Versions: 1.10.0
>            Reporter: Jason Kim
>            Assignee: Jason Kim
>            Priority: Major
>             Fix For: 2.0.0
>
>
> I have created very long term schedule in short interval. (2~3 years as 10 
> min interval)
> So, dag could be bigger and bigger as scheduling goes on.
> Finally, at critical point (I don't know exactly when it is), the allocation 
> of new task_instances get slow and then almost stop.
> I found that in this point, many slow query logs had occurred. (I was using 
> mysql as meta repository)
> queries like this
> "SELECT * FROM task_instance WHERE dag_id = 'some_dag_id' AND execution_date 
> = ''2018-09-01 00:00:00"
> I could resolve this issue by adding new index consists of dag_id and 
> execution_date.
> So, I wanted 1.10 branch to be modified to create task_instance table with 
> the index.
> Thanks.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to