Re: query planner not using index, instead using squential scan - Mailing list pgsql-performance

From Tom Lane
Subject Re: query planner not using index, instead using squential scan
Date
Msg-id 560773.1622921370@sss.pgh.pa.us
Whole thread Raw
In response to query planner not using index, instead using squential scan  (Ayub Khan <ayub.hp@gmail.com>)
Responses Re: query planner not using index, instead using squential scan  (Vijaykumar Jain <vijaykumarjain.github@gmail.com>)
List pgsql-performance
Ayub Khan <ayub.hp@gmail.com> writes:
> could someone clarify why the LEFT JOIN order_offer_map oom using
> (order_id) in the below query is using sequential scan instead of
> using index on order_id which is defined in order_offer_map table.

Probably because it estimates the hash join to restaurant_order is
faster than a nestloop join would be.  I think it's likely right.
You'd need very optimistic assumptions about the cost of an
individual index probe into order_offer_map to conclude that 156K
of them would be faster than the 476ms that are being spent here
to read order_offer_map and join it to the result of the
indexscan on restaurant_order.

If, indeed, that *is* faster on your hardware, you might want
to dial down random_page_cost to get more-relevant estimates.

            regards, tom lane



pgsql-performance by date:

Previous
From: Ayub Khan
Date:
Subject: query planner not using index, instead using squential scan
Next
From: Vijaykumar Jain
Date:
Subject: Re: query planner not using index, instead using squential scan