Re: Wasteful nested loop join when there is `limit` in the query - Mailing list pgsql-general

From Tom Lane
Subject Re: Wasteful nested loop join when there is `limit` in the query
Date
Msg-id 744079.1739775701@sss.pgh.pa.us
Whole thread Raw
In response to Wasteful nested loop join when there is `limit` in the query  (WU Yan <4wuyan@gmail.com>)
Responses Re: Wasteful nested loop join when there is `limit` in the query
List pgsql-general
WU Yan <4wuyan@gmail.com> writes:
> Hello everyone, I am still learning postgres planner and performance
> optimization, so please kindly point out if I missed something obvious.

An index on employee.name would likely help here.  Even if we had
an optimization for pushing LIMIT down through a join (which you
are right, we don't) it could not push the LIMIT through a sort step.
So you need presorted output from the scan of "employee".  I think
this example would behave better with that.  You may also need to
test with non-toy amounts of data to get the plan you think is
better: an example with only half a dozen rows is going to be
swamped by startup costs.

            regards, tom lane



pgsql-general by date:

Previous
From: WU Yan
Date:
Subject: Wasteful nested loop join when there is `limit` in the query
Next
From: 馬 騰飛
Date:
Subject: The performance issues caused by upgrading PostgreSQL to version 16.3.