Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFEFU-0006CC-8G for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2019 09:15:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iFEFS-0004GG-NT for pgsql-general@arkaria.postgresql.org; Tue, 01 Oct 2019 09:15:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFEFS-0004G4-Bh for pgsql-general@lists.postgresql.org; Tue, 01 Oct 2019 09:15:10 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFEFP-0004CN-N0 for pgsql-general@postgresql.org; Tue, 01 Oct 2019 09:15:10 +0000 Received: by mail-pf1-x42b.google.com with SMTP id q5so7445305pfg.13 for ; Tue, 01 Oct 2019 02:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:to:cc:subject:from:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=Rb4YjVNdS+FmiDRX9kZhgznQdTYwkgHIxeH6KAjknbU=; b=kTqe95m+Uzo7CmsCwk9hTVAM/2r69b2heaIeoTA+2orPcJHz345jTzcUhQvOY11y9t LcGj52nApmwgma7d1beoyxf1CHZE5RZ6qQhg73ocJyNLBrIlhFi8NuyH7ho2NMcW3JBl BxUPewbW2G9FhPKz5aHKBzAibVqQlmqXsGB+OvU3tPnyWvW8FWKCmWHqaykKmHEuC9Dq TNytWGxLCCVKY1TLiXJx6XuXp24N7XyjktlGtFl/B3HogkR5pp1ztkj5RwhNge2kTmPj 0Aiux/4MWlj4GDKHJfCEDAuFkK+/b8OtOgqSGbOGNbui54WkYKAZu1JWF3m69FtAxvvc H23A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:to:cc:subject:from:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Rb4YjVNdS+FmiDRX9kZhgznQdTYwkgHIxeH6KAjknbU=; b=RJ2BHD97WYEa5d8k6TDqmfiGAUZ0xl0tXbRQqQ4Z0wBvAmiiRwf8bGPOtzAunuxlzd 1kEz61VTw4oXR0AtMVunJAu2SMkXecY7E6HPjNXRYSKXxpDipeULT/iVcVoXV+6ifthB lVn5LCrxHFwvG7tjtAUBr6cifHsKSsWSp7XuyEqeAPI9Q1tI+GF/myAj2yWSNkTzWJZd 4xu2hy767ohYPiDZPXdQM4hNh4plUAW4HZHV0zSw2lLjuCtzLXP6iH8UYAwrcZ7Bz9G5 Ctrc0L6l946md3EvwAKyMyaLNzXSSDzUeB6UO4fbdEp+0o7J66wHN5iiupnavMMd2iAz 1IQw== X-Gm-Message-State: APjAAAUKgeu2wsaytPQ2FkoICCpddtL4wnWwe0ObLKyWPnM9KdiklChQ 1Y63Jsl4ep5Blpk55e0XT4g= X-Google-Smtp-Source: APXvYqzr1TN+I+c/KeVwWVoC175kqXe6n3A7D8CK4Gif86Ddur5+pahGE4F0f+hvdxUjhghgw/mUzw== X-Received: by 2002:a63:5724:: with SMTP id l36mr730194pgb.295.1569921305201; Tue, 01 Oct 2019 02:15:05 -0700 (PDT) Received: from localhost (w204177.dynamic.ppp.asahi-net.or.jp. [121.1.204.177]) by smtp.gmail.com with ESMTPSA id p66sm20474444pfg.127.2019.10.01.02.15.02 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 01 Oct 2019 02:15:04 -0700 (PDT) Date: Tue, 01 Oct 2019 18:15:00 +0900 (Tokyo Standard Time) Message-Id: <20191001.181500.129895819.horikyota.ntt@gmail.com> To: sonams1209@gmail.com Cc: pgsql-general@postgresql.org Subject: Re: Query Tuning From: Kyotaro Horiguchi In-Reply-To: References: User-Agent: Mew version 6.5 on Emacs 22.2 / Mule 5.0 =?iso-2022-jp?B?KBskQjpnGyhCKQ==?= / Meadow-3.01-dev (TSUBO-SUMIRE) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello. At Tue, 1 Oct 2019 12:42:24 +0530, Sonam Sharma wrote in > We have a query which is running slow and it's taking 26secs to complete.. > we have run the analyzer also and it's taking the same time. > > Any tool is there for query optimization or any suggestions. EXPLAIN ANALYZE (not just EXPLAIN) would be that. In many cases where a query takes an unexpectedly long time, rows estimation in some nodes would be largely different from actual rows. That leads to a wrong query plan. EXPLAIN ANALYZE may give you a clue for such kind of problem. The following output comes from EXPLAIN. I suppose that you already have a similar output having a "(actutal time=...)" clause after the "(cost=..)" clause. > My query plan looks like this : > > CTE Scan on approvalwflscreen (cost=8736.21..8737.25 rows=52 width=1214) > > CTE constants > > -> Result (cost=0.00..0.01 rows=1 width=44) > > CTE approval > > -> Sort (cost=7793.89..7805.22 rows=4530 width=292) regards. -- Kyotaro Horiguchi NTT Open Source Software Center