pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marcin Gozdalik <gozdal@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Extremely inefficient merge-join
Date: Wed, 17 Mar 2021 16:47:35 -0400
Message-ID: <3610142.1616014055@sss.pgh.pa.us> (raw)
In-Reply-To: <CADu1mRO28n4FifmrJYQ6TfFFdWS7tvwksE=7FVmuqc7BsL2OeQ@mail.gmail.com>
References: <CADu1mRO28n4FifmrJYQ6TfFFdWS7tvwksE=7FVmuqc7BsL2OeQ@mail.gmail.com>

Marcin Gozdalik <gozdal@gmail.com> writes:
> Sometimes Postgres will choose very inefficient plan, which involves
> looping many times over same rows, producing hundreds of millions or
> billions of rows:

Yeah, this can happen if the outer side of the join has a lot of
duplicate rows.  The query planner is aware of that effect and will
charge an increased cost when it applies, so I wonder if your
statistics for the tables being joined are up-to-date.

			regards, tom lane





view thread (3+ messages)  latest in thread

Message-ID: <3610142.1616014055@sss.pgh.pa.us>
Permalink:  ../3610142.1616014055@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3610142.1616014055@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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, gozdal@gmail.com
  Subject: Re: Extremely inefficient merge-join
  In-Reply-To: <3610142.1616014055@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