Re: Query performance issue - Mailing list pgsql-performance

From David Rowley
Subject Re: Query performance issue
Date
Msg-id CAApHDvpUU3S4EOWE4vCDHSp+S4yxoH0hxH96GojPH7J9+ZhiAw@mail.gmail.com
Whole thread Raw
In response to Re: Query performance issue  (Nagaraj Raj <nagaraj.sf@yahoo.com>)
List pgsql-performance
On Sat, 5 Sep 2020 at 10:20, Nagaraj Raj <nagaraj.sf@yahoo.com> wrote:
> I added the index as you suggested and the planner going through the bitmap index scan,heap and the new planner is,
> HaOx | explain.depesz.com

In addition to that index, you could consider moving away from
standard SQL and use DISTINCT ON, which is specific to PostgreSQL and
should give you the same result.

EXPLAIN ANALYZE
SELECT DISTINCT ON (serial_no) serial_no,receivingplant,sku,r3_eventtime
FROM receiving_item_delivered_received
WHERE eventtype='LineItemdetailsReceived'
  AND replenishmenttype = 'DC2SWARRANTY'
  AND coalesce(serial_no,'') <> ''
ORDER BY serial_no,eventtime DESC;

The more duplicate serial_nos you have the better this one should
perform.  It appears you don't have too many so I don't think this
will be significantly faster, but it should be a bit quicker.

David



pgsql-performance by date:

Previous
From: Nagaraj Raj
Date:
Subject: Re: Query performance issue
Next
From: Michael Lewis
Date:
Subject: Re: Query performance issue