Re: Strange sort node/explain result

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Gunnar Nick Bluth <gunnar(dot)bluth(at)pro-open(dot)de>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, corrado(at)ficicchia(dot)net
Subject: Re: Strange sort node/explain result
Date: 2022-11-02 01:30:45
Message-ID: CAApHDvpTrP48-=+gdnxryuZVENB9jvoEVsXNjbJ5aBnQoa=TrQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, 2 Nov 2022 at 02:13, Gunnar "Nick" Bluth
<gunnar(dot)bluth(at)pro-open(dot)de> wrote:
> So the sort could also say
> "rows=366 loops=26926"
> instead of
> "rows=9855001 loops=1"
>
> (which I myself would find reasonable...)?

Maybe my example led you to believe that we rewind (rescan) the inner
node each time we finish matching an outer tuple, but that's not what
happens. We only restore back to the marked position, after we've just
fetched the next outer tuple and see that the new outer matches the
tuple that we've marked on the inner side.

The maths just wouldn't make any sense if we incremented the loop
counter each time we did a restore. When we call ExecRestrPos we
could either jump back 0 rows, or jump back to the very start of the
scan. It just depends on the marked position. I think you're under the
impression that if you multiply rows by loops that you'd get a number
that would actually make sense here. It wouldn't.

David

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2022-11-02 06:49:24 BUG #17674: undefined symbol: pg_fprintf
Previous Message Gunnar "Nick" Bluth 2022-11-01 13:13:38 Re: Strange sort node/explain result