On Mon, Nov 02, 2020 at 02:09:03PM -0500, Philip Semanchuk wrote: > Bien merci, yes, I've visited most of those links and learned an enormous > amount from them. I've downloaded many of them for re-reading, including > yours. :-) It's helpful to be reminded of them again. > > EXPLAIN ANALYZE tells me what choices the planner made, but it doesn't tell > me why the planner made those choices. For instance, Tomas Vondra's post > enabled me to calculate how the planner arrived at its estimate of 7 rows for > one node of my query. I would prefer not to reverse engineer the planner's > calculation, but instead have the planner just tell me. > > If I was able to combine that information with a summary of the planner's > algorithm (a lot to ask for!), then I could understand how the planner chose > its plan. > > 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.
I hestitate to suggest it, but maybe you'd want to use ./configure CFLAGS='-DOPTIMIZER_DEBUG=1' which will print out costs of each plan node considered. You could also read in selfuncs.c and costsize.c and related parts of the source. -- Justin