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. Is there a way, we can do anything about it? I hope I am making some sense here. Regards, Vivek -----Original Message----- From: pgsql-performance-owner@xxxxxxxxxxxxxx [mailto:pgsql-performance-owner@xxxxxxxxxxxxxx] On Behalf Of Tomas Vondra Sent: Tuesday, March 17, 2015 8:13 PM To: pgsql-performance@xxxxxxxxxxxxxx Subject: Re: Performance issues On 17.3.2015 15:19, Thomas Kellerer wrote: > Tomas Vondra schrieb am 17.03.2015 um 14:55: >> (2) using window functions, e.g. like this: >> >> SELECT * FROM ( >> SELECT *, >> ROW_NUMBER() OVER (PARTITION BY touchpoint_execution_id >> ORDER BY FROM max_creation_dt) AS rn >> FROM s_f_touchpoint_execution_status_history >> ) foo WHERE rn = 1 >> >> But estimating this is also rather difficult ... > > > From my experience rewriting something like the above using DISTINCT > ON is usually faster. How do you get the last record (with respect to a timestamp column) using a DISTINCT ON? -- Tomas Vondra http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance -- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance