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

2023-08-04 Thread Dane Foster
> > Hmm. The planner should avoid using a merge join if it knows that > to be true. Maybe analyze'ing that table would prompt it to use > some other join method? The planner has updated stats on the table and wants to use a nested loop: https://explain.dalibo.com/plan/3814d5356cc82528 But t

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

2023-08-04 Thread Tom Lane
Dane Foster writes: >> 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. Hmm. The pla

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

2023-08-04 Thread Dane Foster
> 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

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

2023-08-04 Thread Tom Lane
Dane Foster 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

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

2023-08-04 Thread Dane Foster
Thanks for the explanation. Dane On Fri, Aug 4, 2023 at 11:07 AM Jeff Janes wrote: > On Fri, Aug 4, 2023 at 11:00 AM Dane Foster wrote: > >> Hello, >> >> 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 pro

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

2023-08-04 Thread Jeff Janes
On Fri, Aug 4, 2023 at 11:00 AM Dane Foster wrote: > Hello, > > 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

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

2023-08-04 Thread Dane Foster
Hello, 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? https://explain.dalibo.com/plan/1