pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jeff Janes <jeff.janes@gmail.com>
Cc: Tim Kelly <gtkelly@dialectronics.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: unoptimized nested loops
Date: Thu, 02 Jun 2022 00:32:40 -0400
Message-ID: <843004.1654144360@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMkU=1whHwiBkt4t4e8Y85NT_ReLyo-qjvdpOROuW2N7dQCSug@mail.gmail.com>
References: <62965CE8.7030500@dialectronics.com>
	<CAMkU=1whHwiBkt4t4e8Y85NT_ReLyo-qjvdpOROuW2N7dQCSug@mail.gmail.com>

Jeff Janes <jeff.janes@gmail.com> writes:
> On Tue, May 31, 2022 at 4:04 PM Tim Kelly <gtkelly@dialectronics.com> wrote:
>> I do not see evidence that the nested loop is trying to reduce overhead
>> by using the smaller set.  It seems to want to scan on data first either
>> way.

> The planner probably doesn't know which one is smaller.

There is not a lot of daylight between the cost estimates for
"a nestloop-join b" and "b nestloop-join a", if we're considering
plain seqscans on both tables and all else is equal.  It tends to
come down to factors like which one is more densely populated.

As best I can tell, the issue Tim's unhappy about is not so
much the use of a nestloop as the lack of use of any index.
But "string like '%foo%'" is not at all optimizable with a
btree index.  You might be able to get somewhere with a
pg_trgm GIN or GIST index.

			regards, tom lane





view thread (7+ messages)  latest in thread

Message-ID: <843004.1654144360@sss.pgh.pa.us>
Permalink:  ../843004.1654144360@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/843004.1654144360@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jeff.janes@gmail.com, gtkelly@dialectronics.com
  Subject: Re: unoptimized nested loops
  In-Reply-To: <843004.1654144360@sss.pgh.pa.us>
  References: <62965CE8.7030500@dialectronics.com> <CAMkU=1whHwiBkt4t4e8Y85NT_ReLyo-qjvdpOROuW2N7dQCSug@mail.gmail.com> <843004.1654144360@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox