bad plan using nested loops

From: Johan Fredriksson <eskil(at)kth(dot)se>
To: pgsql-performance(at)lists(dot)postgresql(dot)org
Subject: bad plan using nested loops
Date: 2018-02-01 10:42:07
Message-ID: 1517481727.23675.3.camel@kth.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Nandakumar M 2018-02-01 14:30:29 Query optimiser is not using 'not null' constraint when 'order by nulls last' clause is used
Previous Message pavan95 2018-02-01 06:18:00 Re: 8.2 Autovacuum BUG ?