pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Nicolas Seinlet <nicolas@seinlet.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: More records after sort
Date: Tue, 20 Jul 2021 10:34:37 -0400
Message-ID: <368621.1626791677@sss.pgh.pa.us> (raw)
In-Reply-To: <sccAkd2JVf0NntlWtYcU8-h-xCZxuwuCqF1vpTrIG1VR1DffM3t4QlMiMRrLR4VyJm5oyUa1n-TmPhnkCA6fLoT0tfAWGD2c7NlrihonP9Q=@seinlet.com>
References: <sccAkd2JVf0NntlWtYcU8-h-xCZxuwuCqF1vpTrIG1VR1DffM3t4QlMiMRrLR4VyJm5oyUa1n-TmPhnkCA6fLoT0tfAWGD2c7NlrihonP9Q=@seinlet.com>

Nicolas Seinlet <nicolas@seinlet.com> writes:
> I'm facing a strange behaviour and I don't understand why. From a wider query plan, https://explain.dalibo.com/plan/7yh ,a table is scanned and filter based on its primary key, returning 98 records. Then, those records are sorted on another field, and the output is 758,247,643 records.

You haven't showed us the whole plan; tsk tsk.

However, I'm going to bet that this sort is the inner input of a merge
join, and that the apparent "extra" tuples are caused by the merge backing
up and rescanning the sort result to deal with duplicate join keys in its
outer input.  There must be a heck of a lot of duplicates.  The planner
would typically avoid using merge join if it knew that, so I'm wondering
if you have up-to-date statistics for the outer side of the join.

			regards, tom lane





view thread (6+ messages)  latest in thread

Message-ID: <368621.1626791677@sss.pgh.pa.us>
Permalink:  ../368621.1626791677@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/368621.1626791677@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, nicolas@seinlet.com
  Subject: Re: More records after sort
  In-Reply-To: <368621.1626791677@sss.pgh.pa.us>
  References: <sccAkd2JVf0NntlWtYcU8-h-xCZxuwuCqF1vpTrIG1VR1DffM3t4QlMiMRrLR4VyJm5oyUa1n-TmPhnkCA6fLoT0tfAWGD2c7NlrihonP9Q=@seinlet.com> <368621.1626791677@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