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 1h9Smy-0002bw-4A for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Mar 2019 11:01:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h9Smw-0005Zq-PI for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Mar 2019 11:01:38 +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 1h9Qat-0005ya-Hm for pgsql-bugs@lists.postgresql.org; Thu, 28 Mar 2019 08:41:04 +0000 Received: from sonic313-10.consmr.mail.ne1.yahoo.com ([66.163.185.33]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9Qaq-00026R-NW for pgsql-bugs@lists.postgresql.org; Thu, 28 Mar 2019 08:41:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1553762458; bh=85VB5DoAnLnY50H9Ogb5dJq1LA+Iqs26X/zaBcx7mIE=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From:Subject; b=FlBLrxjpz8qW4Rlg7AVw61TaUK6F9It6SLsiyeUvqKFaOQaEax5qU48Zeq/RsM5/5htsUyM+P/o3C819YJMrnLZ+Wni/XdFp2lR4a5azwcEZDqMkj8zF9unofu18gBe0Yn0U+i4i1FU2vbzCmuUMgzfl3ENqCi02XnpaXKl+CBwAyQAp+GrBjhJ5+THEAJU/Nomx/ea2QlryE2I5UzyNc+hJ5lHlKXDNFaS7HSUIkSeEgY3huK8y+uRvhI5RZsOZetIR7feGUQNI9jddHsa0Mg0YyldKnr24cMPrqJmaI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TrL8nANYJ6A9zTIQwXgQyGxjpz.63RXpGQLYd5 3K.C_2xh3iphkMSSGllEcQalWYEdUspNiwA-- Received: from sonic.gate.mail.ne1.yahoo.com by sonic313.consmr.mail.ne1.yahoo.com with HTTP; Thu, 28 Mar 2019 08:40:58 +0000 Date: Thu, 28 Mar 2019 08:40:56 +0000 (UTC) From: Alex To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org Message-ID: <765434487.12847357.1553762456299@mail.yahoo.com> In-Reply-To: <11046.1553735962@sss.pgh.pa.us> References: <15717-e8df3cbc92d5d474@postgresql.org> <11046.1553735962@sss.pgh.pa.us> Subject: Re: BUG #15717: Index not used when ordering by left joined table column MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_12847356_1402481706.1553762456296" X-Mailer: WebService/1.1.13212 YMailNorrin Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0 Content-Length: 3686 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_12847356_1402481706.1553762456296 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Indeed, with an inner join the index is used.Thanks for the assistance. On Thursday, March 28, 2019, 3:19:30 AM GMT+2, Tom Lane wrote: =20 =20 PG Bug reporting form writes: > The following query runs slow, as it seq scans tables, without using any > index: >=C2=A0 select >=C2=A0 =C2=A0 =C2=A0 wp.id as id >=C2=A0 from >=C2=A0 =C2=A0 =C2=A0 web_page wp >=C2=A0 =C2=A0 =C2=A0 left join web_url_path url on wp.id=3Durl.page >=C2=A0 order by >=C2=A0 =C2=A0 =C2=A0 url.priority asc >=C2=A0 limit 1 > I was expecting the "priority" column index would be used to retrieve fir= st > 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. =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 regards, tom lane =20 ------=_Part_12847356_1402481706.1553762456296 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Indeed, with an inner join the index is used.
=
Thanks for the assistance.



=20
=20
On Thursday, March 28, 2019, 3:19:30 AM GMT+2, Tom Lane= <tgl@sss.pgh.pa.us> wrote:


PG Bug reporting form <n= oreply@postgresql.org> writes:
> The fo= llowing query runs slow, as it seq scans tables, without using any
> index:
>  select
>      wp.id as id
>  from
>    &n= bsp; web_page wp
>      left jo= in web_url_path url on wp.id=3Durl.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 rig= ht join.
But a nestloop plan cannot be driven fro= m the inside of an outer join,
and that's the cas= e this query presents.

            regards, tom lane=
------=_Part_12847356_1402481706.1553762456296--