Philip Semanchuk <philip@xxxxxxxxxxxxxxxxxxxxx> 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. regards, tom lane