Re: postgresql-14 slow query

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Kenny Bachman <kenny(dot)bachman17(at)gmail(dot)com>
Cc: Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: postgresql-14 slow query
Date: 2022-04-16 04:37:10
Message-ID: CAMkU=1zL5+zQzzYL3j+xHBoGAw0JvmAoz_5c7+JZszybzAug5Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Fri, Apr 15, 2022 at 4:59 PM Kenny Bachman <kenny(dot)bachman17(at)gmail(dot)com>
wrote:

> Hello Team,
>
> How can I tune this query? It got even slower when I created the index for
> (state_id, order_id desc). The following explain analyze output is
> without an index. It takes 13 seconds if I create that index. Could you
> help me?
>
> Thank you so much for your help.
>
> SELECT DISTINCT ON (order_history.order_id) order_id,
> order_history.creation_date AS c_date
> FROM work.order_history WHERE (order_history.state_id = ANY (ARRAY[30, 51,
> 63, 136, 195, 233, 348])) AND order_history.is_false = 0
> ORDER BY order_history.order_id DESC;
>

This query doesn't make much sense to me. You are selecting an arbitrary
creation_date for each order_id, which seems like a weird thing to do on
purpose. Is your ORDER BY supposed to list another column in it to break
the ties?

I wonder how much benefit you are actually getting from the parallel
workers. If you lower max_parallel_workers_per_gather, does the plan take
proportionally longer?

You should turn on track_io_timing, then repeat the query with EXPLAIN
(ANALYZE, BUFFERS).

Cheers,

Jeff

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Avinash Vallarapu 2022-04-16 05:21:52 Re: postgresql-14 slow query
Previous Message Bhupendra Babu 2022-04-16 04:14:25 Re: postgresql-14 slow query