pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marc Millas <marc.millas@mokadb.com>
Cc: Erik Wienhold <ewie@ewie.name>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: impact join syntax ?? and gist index ??
Date: Sat, 07 Jan 2023 16:32:57 -0500
Message-ID: <3481346.1673127177@sss.pgh.pa.us> (raw)
In-Reply-To: <CADX_1abdY44bNmLVW07u0GqWqJWMhH6q+MHfByP=macs7wur+Q@mail.gmail.com>
References: <CADX_1aabU_Og_tCEKX4MK=jkq1stgwFmxi0RsX5Qq8g1C1=LBg@mail.gmail.com>
	<832577793.126542.1673124009766@office.mailbox.org>
	<CADX_1abdY44bNmLVW07u0GqWqJWMhH6q+MHfByP=macs7wur+Q@mail.gmail.com>

Marc Millas <marc.millas@mokadb.com> writes:
> 2023=# explain (analyze, buffers) select A.x, count(B.x) from A left join B
> on st_within(B.geom, A.geom) group by A.x;

So the problem with this is that the only decently-performant way to
do the join is like

>                      ->  Nested Loop  (cost=0.13..6275745.36 rows=4971999 width=16) (actual time=0.505..11781.817 rows=210651 loops=2)
>                            ->  Parallel Seq Scan on B  (cost=0.00..18454.99 rows=248699 width=40) (actual time=0.005..22.859 rows=211395 loops=2)
>                            ->  Index Scan using A_geom_idx on A (cost=0.13..25.15 rows=1 width=17752) (actual time=0.054..0.055 rows=1 loops=422789)
>                                  Index Cond: (geom ~ B.geom)
>                                  Filter: st_within(B.geom, geom)

(Ignore the parallelism, it's not very relevant here.)  There's no
chance for merge or hash join because those require simple equality
join conditions.  The only way to avoid a stupid
compare-every-row-of-A-to-every-row-of-B nestloop is to use a
parameterized inner indexscan, as this plan does.  But that only works
if the join is inner or has the indexed table on the nullable side.
We have no support for nestloop right join, which is what would be
needed to make things run fast with no index on B.

			regards, tom lane





view thread (8+ messages)  latest in thread

Message-ID: <3481346.1673127177@sss.pgh.pa.us>
Permalink:  ../3481346.1673127177@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3481346.1673127177@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, marc.millas@mokadb.com, ewie@ewie.name
  Subject: Re: impact join syntax ?? and gist index ??
  In-Reply-To: <3481346.1673127177@sss.pgh.pa.us>
  References: <CADX_1aabU_Og_tCEKX4MK=jkq1stgwFmxi0RsX5Qq8g1C1=LBg@mail.gmail.com> <832577793.126542.1673124009766@office.mailbox.org> <CADX_1abdY44bNmLVW07u0GqWqJWMhH6q+MHfByP=macs7wur+Q@mail.gmail.com> <3481346.1673127177@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