Re: More records after sort - Mailing list pgsql-general

From Tom Lane
Subject Re: More records after sort
Date
Msg-id 368621.1626791677@sss.pgh.pa.us
Whole thread Raw
In response to More records after sort  (Nicolas Seinlet <nicolas@seinlet.com>)
Responses Re: More records after sort  (Nicolas Seinlet <nicolas@seinlet.com>)
List pgsql-general
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 ,atable 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



pgsql-general by date:

Previous
From: Nicolas Seinlet
Date:
Subject: More records after sort
Next
From: Nicolas Seinlet
Date:
Subject: Re: More records after sort