Re: Understanding bad estimate (related to FKs?)

From: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Philip Semanchuk <philip(at)americanefficient(dot)com>, Guillaume Lelarge <guillaume(at)lelarge(dot)info>, Justin Pryzby <pryzby(at)telsasoft(dot)com>, Michael Lewis <mlewis(at)entrata(dot)com>, postgres performance list <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Understanding bad estimate (related to FKs?)
Date: 2020-11-03 03:17:14
Message-ID: 20201103031714.5smwqn6lxy5pjzpi@development
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Mon, Nov 02, 2020 at 03:08:12PM -0500, Tom Lane wrote:
>Philip Semanchuk <philip(at)americanefficient(dot)com> writes:
>> The query I asked about in the original post of this thread has 13 relations in it. IIUC, that's 13! or > 6 billion possible plans. How did the planner pick one plan out of 6 billion? I'm curious, both for practical purposes (I want my query to run well) and also because it's fascinating.
>
>The twenty-thousand-foot overview is
>
>https://www.postgresql.org/docs/devel/planner-optimizer.html
>
>and then ten-thousand-foot level is the planner README file,
>
>https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob_plain;f=src/backend/optimizer/README;hb=HEAD
>
>and then you pretty much gotta start reading code. You could also dig
>into various planner expository talks that people have given at PG
>conferences. I don't have links at hand, but there have been several.
>

Yeah. The jump from high-level overviews to reading source code is a bit
brutal, though ...

FWIW a short list of relevant talks I'm aware of & would recommend:

* Explaining the Postgres Query Optimizer [Bruce Momjian]
https://www.postgresql.org/files/developer/tour.pdf

* Intro to Postgres Planner Hacking [Melanie Plageman]
https://www.pgcon.org/2019/schedule/events/1379.en.html

* Learning to Hack on Postgres Planner [Melanie Plageman]
https://www.pgcon.org/2019/schedule/attachments/540_debugging_planner_pgcon2019_v4.pdf

* What’s in a Plan? [Robert Haas]
https://www.postgresql.eu/events/pgconfeu2019/schedule/session/2741-whats-in-a-plan/

* A Tour of PostgreSQL Internals [Tom Lane]
https://www.postgresql.org/files/developer/tour.pdf

* Inside thePostgreSQL Query Optimizer [Neil Conway]
http://www.neilconway.org/talks/optimizer/optimizer.pdf

Some are a bit dated, but the overall principles don't change much.

regards

--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Ehrenreich, Sigrid 2020-11-03 13:20:10 Partition pruning with joins
Previous Message Michael Lewis 2020-11-02 23:09:52 Re: Understanding bad estimate (related to FKs?)