From: Tom Lane <tgl@sss.pgh.pa.us>
To: Palle Girgensohn <girgen@pingpong.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: select max(field) from table much faster with a group by clause?
Date: Thu, 01 Nov 2007 09:43:39 -0400
Message-ID: <4305.1193924619@sss.pgh.pa.us> (raw)
In-Reply-To: <D26563C7B9CCEB0A338FF08E@rambutan.pingpong.net>
References: <D26563C7B9CCEB0A338FF08E@rambutan.pingpong.net>
Palle Girgensohn <girgen@pingpong.net> writes:
> When running
> select max("when") from login where userid='userid'
> it takes a second or two, but when adding "group by userid" the planner
> decides on using another plan, and it gets *much* faster. See example below.
It's only faster for cases where there are few or no rows for the
particular userid ...
> Number of tuples per user varies from zero to a couple of thousands.
The planner is using an intermediate estimate of 406 rows. You might be
well advised to increase the statistics target for login.userid --- with
luck that would help it to choose the right plan type for both common
and uncommon userids.
regards, tom lane
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, girgen@pingpong.net
Subject: Re: select max(field) from table much faster with a group by clause?
In-Reply-To: <4305.1193924619@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