bad plan using nested loops - Mailing list pgsql-performance

From Johan Fredriksson
Subject bad plan using nested loops
Date
Msg-id 1517481727.23675.3.camel@kth.se
Whole thread Raw
Responses Re: bad plan using nested loops  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-performance
Hello!

I brought this issue up about two years ago but without getting any
real explanation or solution. The problem is that PostgreSQL does
really bad plans using nested loops. With "enable_nestloop = 0" the
same query is run about 20 times faster.

The sugested solution I got back then was to upgrade to the latest
version of PostgreSQL (then 9.5). It did not help. The solution we
finally applied was a horribly ugly patch to the perl-module
SearchBuilder that recognized queries that would perform badly and put
them inside transaction blocks with "SET LOCAL enable_nestloop = 0".

Last week I upgraded PostgreSQL for this application (Request Tracker)
to version 10.1 and just for fun I decied to test to remove the patch
to see if the problem still persisted. For two cases it did not. The
planner handled them just fine. For one case however, the same problem
still remains.

Bad plan: https://explain.depesz.com/s/avtZ
Good plan: https://explain.depesz.com/s/SJSt

Any suggestions on how to make the planner make better decisions for
this query?


        / Eskil



pgsql-performance by date:

Previous
From: pavan95
Date:
Subject: Re: 8.2 Autovacuum BUG ?
Next
From: Nandakumar M
Date:
Subject: Query optimiser is not using 'not null' constraint when 'order bynulls last' clause is used