Re: Plan weirdness. A sort produces more rows than the node beneath it

From: Dane Foster <studdugie(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: psql-performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Plan weirdness. A sort produces more rows than the node beneath it
Date: 2023-08-04 15:15:40
Message-ID: CA+WxinK_PeQBeZ-SWVqheHNjyjtD3QGZ5gZSzVKxHRYgUG-ktw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> If the sort is the inner input to a merge join, this could reflect
> mark-and-restore rescanning of the sort's output. Are there a
> whole lot of duplicate keys on the merge's other side?

Yes. The course_id column's values repeat a LOT on the merge side.

Dane

On Fri, Aug 4, 2023 at 11:10 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Dane Foster <studdugie(at)gmail(dot)com> writes:
> > I'm trying to understand a bit of weirdness in a plan output. There is a
> > sort node above a sequential scan node where the scan node produces
> 26,026
> > rows yet the sort node above it produces 42,995,408. How is it possible
> to
> > sort more data than you received?
>
> If the sort is the inner input to a merge join, this could reflect
> mark-and-restore rescanning of the sort's output. Are there a
> whole lot of duplicate keys on the merge's other side?
>
> regards, tom lane
>

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2023-08-04 15:31:57 Re: Plan weirdness. A sort produces more rows than the node beneath it
Previous Message Tom Lane 2023-08-04 15:10:21 Re: Plan weirdness. A sort produces more rows than the node beneath it