pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Israel Brewster <ijbrewster@alaska.edu>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Worse performance with higher work_mem?
Date: Mon, 13 Jan 2020 19:19:37 -0500
Message-ID: <5228.1578961177@sss.pgh.pa.us> (raw)
In-Reply-To: <17AAA60F-6CC8-4D5A-9944-9C144A81E609@alaska.edu>
References: <17AAA60F-6CC8-4D5A-9944-9C144A81E609@alaska.edu>

Israel Brewster <ijbrewster@alaska.edu> writes:
> In looking at the explain analyze output, I noticed that it had an “external merge Disk” sort going on, accounting for about 1 second of the runtime (explain analyze output here: https://explain.depesz.com/s/jx0q <https://explain.depesz.com/s/jx0q;). Since the machine has plenty of RAM available, I went ahead and increased the work_mem parameter. Whereupon the query plan got much simpler, and performance of said query completely tanked, increasing to about 15.5 seconds runtime (https://explain.depesz.com/s/Kl0S <https://explain.depesz.com/s/Kl0S;), most of which was in a HashAggregate.
> How can I fix this? Thanks.

Well, the brute-force way not to get that plan is "set enable_hashagg =
false".  But it'd likely be a better idea to try to improve the planner's
rowcount estimates.  The problem here seems to be lack of stats for
either "time_bucket('1 week', read_time)" or "read_time::date".
In the case of the latter, do you really need a coercion to date?
If it's a timestamp column, I'd think not.  As for the former,
if the table doesn't get a lot of updates then creating an expression
index on that expression might be useful.

			regards, tom lane





view thread (9+ messages)  latest in thread

Message-ID: <5228.1578961177@sss.pgh.pa.us>
Permalink:  ../5228.1578961177@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5228.1578961177@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ijbrewster@alaska.edu
  Subject: Re: Worse performance with higher work_mem?
  In-Reply-To: <5228.1578961177@sss.pgh.pa.us>
  References: <17AAA60F-6CC8-4D5A-9944-9C144A81E609@alaska.edu> <5228.1578961177@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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