Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1BF44200B0F for ; Fri, 17 Jun 2016 18:45:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 1A880160A61; Fri, 17 Jun 2016 16:45:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 62C28160A4C for ; Fri, 17 Jun 2016 18:45:09 +0200 (CEST) Received: (qmail 64635 invoked by uid 500); 17 Jun 2016 16:45:08 -0000 Mailing-List: contact commits-help@airflow.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airflow.incubator.apache.org Delivered-To: mailing list commits@airflow.incubator.apache.org Received: (qmail 64626 invoked by uid 99); 17 Jun 2016 16:45:08 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Jun 2016 16:45:08 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 341CE1A093F for ; Fri, 17 Jun 2016 16:45:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -5.446 X-Spam-Level: X-Spam-Status: No, score=-5.446 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id KWmtvDIcHRpG for ; Fri, 17 Jun 2016 16:45:07 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with SMTP id 098575F39A for ; Fri, 17 Jun 2016 16:45:06 +0000 (UTC) Received: (qmail 63675 invoked by uid 99); 17 Jun 2016 16:45:06 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Jun 2016 16:45:06 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id CD18C2C1F6C for ; Fri, 17 Jun 2016 16:45:05 +0000 (UTC) Date: Fri, 17 Jun 2016 16:45:05 +0000 (UTC) From: "Kengo Seki (JIRA)" To: commits@airflow.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Assigned] (AIRFLOW-246) dag_stats endpoint has a terrible query MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Fri, 17 Jun 2016 16:45:10 -0000 [ https://issues.apache.org/jira/browse/AIRFLOW-246?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Kengo Seki reassigned AIRFLOW-246: ---------------------------------- Assignee: Kengo Seki > dag_stats endpoint has a terrible query > --------------------------------------- > > Key: AIRFLOW-246 > URL: https://issues.apache.org/jira/browse/AIRFLOW-246 > Project: Apache Airflow > Issue Type: Bug > Components: webserver > Affects Versions: Airflow 1.7.1 > Environment: MySQL Backend through sqlalchemy > Reporter: Neil Hanlon > Assignee: Kengo Seki > > Hitting this endpoint creates a series of queries on the database which take over 20 seconds to run, causing the page to not load for that entire time. Luckily the main page (which includes this under "Recent Statuses") loads this synchronously, but still... waiting almost half a minute (at times more) to see the statuses for dags is really not fun. > We have less than a million rows in the task_instance table--so it's not even a problem with that. > Here's a query profile for the query: > https://gist.github.com/NeilHanlon/613f12724e802bc51c23fca7d46d28bf > We've done some optimizations on the database, but to no avail. > The query: > {code:sql} > SELECT task_instance.dag_id AS task_instance_dag_id, task_instance.state AS task_instance_state, count(task_instance.task_id) AS count_1 FROM task_instance LEFT OUTER JOIN (SELECT dag_run.dag_id AS dag_id, dag_run.execution_date AS execution_date FROM dag_run WHERE dag_run.state = 'running') AS running_dag_run ON running_dag_run.dag_id = task_instance.dag_id AND running_dag_run.execution_date = task_instance.execution_date LEFT OUTER JOIN (SELECT dag_run.dag_id AS dag_id, max(dag_run.execution_date) AS execution_date FROM dag_run GROUP BY dag_run.dag_id) AS last_dag_run ON last_dag_run.dag_id = task_instance.dag_id AND last_dag_run.execution_date = task_instance.execution_date WHERE task_instance.task_id IN ... AND (running_dag_run.dag_id IS NOT NULL OR last_dag_run.dag_id IS NOT NULL) GROUP BY task_instance.dag_id, task_instance.state; > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)