pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Help with tuning slow query
2+ messages / 2 participants
[nested] [flat]

* Help with tuning slow query
@ 2018-05-18 20:32  Kotapati, Anil <Anil_Kotapati@comcast.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Kotapati, Anil @ 2018-05-18 20:32 UTC (permalink / raw)
  To: pgsql-performance; +Cc: Kossi, Edem <Edem_Kossi@comcast.com>; Yadav, Rahul <Rahul_Yadav2@comcast.com>; Mukherjee, Pallavi (Contractor) <Pallavi_Mukherjee@comcast.com>

Hi Team,

We are facing issues with one of our query, when we use order by count it is taking lot of time to execute the query. To be precise it is taking 9 min to execute the query from table which has ~220 million records. Is there a way to make this query run faster and efficiently using order by count. Below is the query which I’m trying to run

Select account_number, sum(count_of_event) as "error_count"
FROM event_daily_summary
group by account_number,event_date,process_name
having event_date >= '2018-05-07'
and process_name='exp90d_xreerror'
order by sum(count_of_event) desc
limit 5000


Thanks,
Anil


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Help with tuning slow query
@ 2018-05-19 15:57  Justin Pryzby <pryzby@telsasoft.com>
  parent: Kotapati, Anil <Anil_Kotapati@comcast.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Justin Pryzby @ 2018-05-19 15:57 UTC (permalink / raw)
  To: Kotapati, Anil <Anil_Kotapati@comcast.com>; +Cc: pgsql-performance; Kossi, Edem <Edem_Kossi@comcast.com>; Yadav, Rahul <Rahul_Yadav2@comcast.com>; Mukherjee, Pallavi (Contractor) <Pallavi_Mukherjee@comcast.com>

On Fri, May 18, 2018 at 08:32:55PM +0000, Kotapati, Anil wrote:
> We are facing issues with one of our query, when we use order by count it is taking lot of time to execute the query. To be precise it is taking 9 min to execute the query from table which has ~220 million records. Is there a way to make this query run faster and efficiently using order by count. Below is the query which I’m trying to run
> 
> Select account_number, sum(count_of_event) as "error_count"
> FROM event_daily_summary
> group by account_number,event_date,process_name
> having event_date >= '2018-05-07'
> and process_name='exp90d_xreerror'
> order by sum(count_of_event) desc
> limit 5000

Would you provide the information listed here ?  Table definition, query plan, etc
https://wiki.postgresql.org/wiki/Slow_Query_Questions

Also, why "HAVING" ? Shouldn't you use WHERE ?

Does the real query have conditions on event_date and process name or is that
just for testing purposes?

Justin




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2018-05-19 15:57 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-05-18 20:32 Help with tuning slow query Kotapati, Anil <Anil_Kotapati@comcast.com>
2018-05-19 15:57 ` Justin Pryzby <pryzby@telsasoft.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox