Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YXc6j-0007QL-M1 for pgsql-performance@arkaria.postgresql.org; Mon, 16 Mar 2015 20:59:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YXc6j-0005EI-5H for pgsql-performance@arkaria.postgresql.org; Mon, 16 Mar 2015 20:59:29 +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 1YXc6i-0005EC-Ab for pgsql-performance@postgresql.org; Mon, 16 Mar 2015 20:59:28 +0000 Received: from mail-wi0-f176.google.com ([209.85.212.176]) by magus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YXc6e-0006CL-7Q for pgsql-performance@postgresql.org; Mon, 16 Mar 2015 20:59:27 +0000 Received: by wixw10 with SMTP id w10so54228135wix.0 for ; Mon, 16 Mar 2015 13:59:22 -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:cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=G/AMkhnqMkF5SlNIADLm+OeHdrIIMw6zHjTCSvozSS0=; b=S6hK1h5c/fZiy6bUHUFkcXCcVvF6eabDR6uhpnPGBwVKckQVR+93rfEnZZ9WEYY1Js yADVgVrcQO08FSBkLpYr+xtl6FhKh1QjtIjoTf9nmLIxqHF0AOxaCzBrLdaox7CCLRAq LNyOjTHYMRzsIafbmM6e2pA9XT2tYPaxgXopRDxs4gZpOt0PaE5zyhDPlr7vkil1UTsX GWzUHzf4uAVfTHstKkRpVgRVTut7rNaH67BbuyT6QHDU9+IU3iqVp1MvpWfk/xNycGyo OAV35OXB0WBJAw3lnXLJ7nBFK3CLhqyiNJWWFekdJqUOSSy1Nrpfuoa/RSWCWeOU8TSN HjVg== X-Gm-Message-State: ALoCoQn4HD9PkovK/FyEZ3LMTO5PVdfC2vixm9/xTcAM0xfrhPckBJ1MGeFm+aeKm6KQ5V4Mf02OU/dcfNbYuIQVsKz4ce+MnYsl8Pod272EhBCDdLFS7vJL478Jh1qKkyXozkaMdNKoncO330cOn/o86kwMcjj+46TADcmKboYu9L4VCTFhr9ZluouPlWQF5+eqmSak3qov X-Received: by 10.180.97.226 with SMTP id ed2mr164971419wib.4.1426539562336; Mon, 16 Mar 2015 13:59:22 -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 hl15sm16990905wib.3.2015.03.16.13.59.20 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Mar 2015 13:59:21 -0700 (PDT) Message-ID: <55074424.9050506@2ndquadrant.com> Date: Mon, 16 Mar 2015 21:59:16 +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: Jim Nasby , vjoshi@zetainteractive.com, Scott Marlowe , Varadharajan Mukundan CC: pgsql-performance@postgresql.org Subject: Re: Performance issues References: <84a6fe4be04c3ef0a714851977860ac8@mail.gmail.com> <160b8780d89add7f23c4eb9c3debb99d@mail.gmail.com> <55034A48.4040409@2ndquadrant.com> <849e75d9463938372dd4c516f5c5d89c@mail.gmail.com> <55037CEA.5050906@2ndquadrant.com> <55073272.20209@BlueTreble.com> In-Reply-To: <55073272.20209@BlueTreble.com> Content-Type: text/plain; charset=windows-1252 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 16.3.2015 20:43, Jim Nasby wrote: > On 3/13/15 7:12 PM, Tomas Vondra wrote: >> (4) I suspect many of the relations referenced in the views are not >> actually needed in the query, i.e. the join is performed but >> then it's just discarded because those columns are not used. >> Try to simplify the views as much has possible - remove all the >> tables that are not really necessary to run the query. If two >> queries need different tables, maybe defining two views is >> a better approach. > > A better alternative with multi-purpose views is to use an outer > join instead of an inner join. With an outer join if you ultimately > don't refer to any of the columns in a particular table Postgres will > remove the table from the query completely. Really? Because a quick test suggests otherwise: db=# create table test_a (id int); CREATE TABLE db=# create table test_b (id int); CREATE TABLE db=# explain select test_a.* from test_a left join test_b using (id); QUERY PLAN ---------------------------------------------------------------------- Merge Left Join (cost=359.57..860.00 rows=32512 width=4) Merge Cond: (test_a.id = test_b.id) -> Sort (cost=179.78..186.16 rows=2550 width=4) Sort Key: test_a.id -> Seq Scan on test_a (cost=0.00..35.50 rows=2550 width=4) -> Sort (cost=179.78..186.16 rows=2550 width=4) Sort Key: test_b.id -> Seq Scan on test_b (cost=0.00..35.50 rows=2550 width=4) (8 rows) Also, how would that work with duplicate rows in the referenced table? -- 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