Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YXtPt-0001D3-AE for pgsql-performance@arkaria.postgresql.org; Tue, 17 Mar 2015 15:28:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YXtPs-0002P1-8q for pgsql-performance@arkaria.postgresql.org; Tue, 17 Mar 2015 15:28:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YXtPm-0002Ew-P9 for pgsql-performance@postgresql.org; Tue, 17 Mar 2015 15:28:18 +0000 Received: from mail-wi0-f173.google.com ([209.85.212.173]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YXtPh-0001st-5B for pgsql-performance@postgresql.org; Tue, 17 Mar 2015 15:28:16 +0000 Received: by wibg7 with SMTP id g7so48721376wib.1 for ; Tue, 17 Mar 2015 08:28:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:organization:user-agent :mime-version:to:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=2ExQV25GzaanCE/xBiPUU2ZdORjv1ruDYzldy7QVEnI=; b=JKnIePbxONPvg/6E9IQYhhDU/ZJ9IBpKDR2S0AQhjZ5bnZ6H03sGZvxu4UMECLHCcw 0jLsHsQGDRapCzVoayKFZXlQ5J5q72wZsGJx9Fiq22WYz2508mELQv7dWEIMCayeMoa8 40oivLQeIeZ0I6CdzxhM/aJn5YJ/IM1SbyubwNzSXdTODyoWZtQvyfUHZfk3Bi/paFke kpGUnjxJUYjLhvIMNaEHhVxmZCSvfS0qNx9b0pBAMZCNyAFfXylo4CzBWURHNgCFBDsw z3d+YFI8sZbCQbwuOBJEY2miOTk2nTcQCJh82xCG2UyNWwSB6y10rJxpTi+LW5wNw7Pa Stkw== X-Gm-Message-State: ALoCoQktJtb5rHN+TtiM03XFfqLW3Tzx5ooWs3kf6VhcWz21Or5iqGvi1tjyZM4/aTL6BcdQfxRGP201JDjiNt0uMilHyCILAdU0B0PpjfEQCn0x5gVdlDBaFhHBH6jNvezi58mGtOg8uWRrb0AvMsHaxIz/2TwE7/SnNyeCPw4uhJf6ZIikU4n1FpYK+Ilulfw5O2FL7eMr X-Received: by 10.180.79.35 with SMTP id g3mr49578160wix.42.1426606091482; Tue, 17 Mar 2015 08:28:11 -0700 (PDT) Received: from [192.168.1.163] (ip-78-45-139-138.net.upcbroadband.cz. [78.45.139.138]) by mx.google.com with ESMTPSA id v13sm3112363wij.10.2015.03.17.08.28.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Mar 2015 08:28:09 -0700 (PDT) Message-ID: <55084803.9030508@2ndquadrant.com> Date: Tue, 17 Mar 2015 16:28:03 +0100 From: Tomas Vondra Organization: 2ndQuadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: vjoshi@zetainteractive.com, pgsql-performance@postgresql.org Subject: Re: Performance issues References: <84a6fe4be04c3ef0a714851977860ac8@mail.gmail.com> <55034A48.4040409@2ndquadrant.com> <849e75d9463938372dd4c516f5c5d89c@mail.gmail.com> <55037CEA.5050906@2ndquadrant.com> <55073272.20209@BlueTreble.com> <55074424.9050506@2ndquadrant.com> <55076FFB.9090105@BlueTreble.com> c5231342781287ff8cbc9ac1f20ff036@mail.gmail.com <61a7 a27428e588411e8ac1817043205c@mail.gmail.com> <550813CD.7040605@2ndquadrant.com> d6a86358c5e8d7ffe923ff307c3e8c7e@mail.gmail.com <55083236.8070900@2ndquadrant.com> <55083D74.4000601@2ndquadrant.com> <087a57caebe1d71091670f3435d2c1e5@mail.gmail.com> In-Reply-To: <087a57caebe1d71091670f3435d2c1e5@mail.gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 17.3.2015 16:10, Vivekanand Joshi wrote: > The confusion for me here is that : > > > I am getting results from the view in around 3 seconds > (S_V_D_CAMPAIGN_HIERARCHY) and 25 seconds (S_V_F_PROMOTION_HISTORY_EMAIL) > > But when I am using these two views in the query as the joining > tables, it doesn't give any result. As per my understanding, the > planner is making new plan and that is costly instead of using > output from the view, which is actually understandable. In general, yes. The problem is that the plan is constructed based on the estimates, and those are very inaccurate in this case. The planner may do various changes, but let's assume that does not happen and the plans are executed and and the results are joined. For example what might happen is this: for each row in 's_v_d_campaign_hierarchy' (1 row expected): execute s_v_f_promotion_history_email & join (11644 rows exp.) But then it gets 45k rows from s_v_d_campaign_hierarchy, and ~400x more rows from s_v_f_promotion_history_email (I'm neglecting the join condition here, but that's not really significant). Kaboooom! In reality, the plan is reorganized (e.g. different join order), but the misestimates are still lurking there. > Is there a way, we can do anything about it? Rephrasing the query so that the planner can estimate it more accurately. -- Tomas Vondra http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance