1

I have two tables: Order Lines, Orders.

Orders table has a Status column, which is text. It can have values like 'Draft', 'Approved', 'Cancelled' etc. I need a query to return pending order lines for all approved orders. There is an index for pending lines in order Lines table, which performs quickly. When I add index on Status column for Orders, it is used while querying order table. When I join (left outer) Order Lines with Orders, and apply filter of Approved orders, index on Orders wouldn't be used, sequential scan on Orders is used instead.

It appears that the planner uses sequential scan, since most of the Orders have Approved status. This slows down the joined query. What is the best way to speed up this query?

  • 1
    Please take a look at this -- how to ask query performance questions. – mustaccio Nov 1 '18 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.