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 1h9Jhc-0006ya-Lx for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Mar 2019 01:19:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h9Jhb-0000vJ-78 for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Mar 2019 01:19:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9Jha-0000vC-SV for pgsql-bugs@lists.postgresql.org; Thu, 28 Mar 2019 01:19:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9JhU-0000SV-Dj for pgsql-bugs@lists.postgresql.org; Thu, 28 Mar 2019 01:19:29 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x2S1JM4i011047; Wed, 27 Mar 2019 21:19:22 -0400 From: Tom Lane To: cdalxndr@yahoo.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15717: Index not used when ordering by left joined table column In-reply-to: <15717-e8df3cbc92d5d474@postgresql.org> References: <15717-e8df3cbc92d5d474@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Wed, 27 Mar 2019 15:30:27 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <11045.1553735962.1@sss.pgh.pa.us> Date: Wed, 27 Mar 2019 21:19:22 -0400 Message-ID: <11046.1553735962@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk PG Bug reporting form writes: > The following query runs slow, as it seq scans tables, without using any > index: > select > wp.id as id > from > web_page wp > left join web_url_path url on wp.id=url.page > order by > url.priority asc > limit 1 > I was expecting the "priority" column index would be used to retrieve first > url then do a reverse join to get the corresponding page, and continue if no > page is found. It would probably do that if you used a plain join, or a right join. But a nestloop plan cannot be driven from the inside of an outer join, and that's the case this query presents. regards, tom lane