Re: Query performance issue - Mailing list pgsql-performance

From Tom Lane
Subject Re: Query performance issue
Date
Msg-id 12017.1315149499@sss.pgh.pa.us
Whole thread Raw
In response to Re: Query performance issue  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Responses Re: Query performance issue  (Jayadevan <Jayadevan.Maymala@ibsplc.com>)
List pgsql-performance
"Kevin Grittner" <Kevin.Grittner@wicourts.gov> writes:
> Thanks for posting the query and related schema.  I tried working
> through it, but I keep coming back to this sort, and wondering how a
> sort can have 1121 rows as input and 2673340321 rows as output.  Does
> anyone have any ideas on what could cause that?

Mergejoin rescan.  There really are only 1121 rows in the data, but
the parent merge join is pulling them over and over again --- evidently
there are a lot of equal keys in the data.  The EXPLAIN ANALYZE
machinery counts each fetch as a new row, even after a mark/restore.

The planner does know about that effect and will penalize merge joins
when it realizes there are a lot of duplicate keys in the input.  In
this case I'm thinking that the drastic underestimate of the size of the
other side of the join results in not penalizing the merge enough.

(On the other hand, hash joins don't like equal keys that much either...)

            regards, tom lane

pgsql-performance by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: Query performance issue
Next
From: Jayadevan
Date:
Subject: Re: Query performance issue