pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Palle Girgensohn <girgen@pingpong.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-performance@postgresql.org
Subject: Re: select max(field) from table much faster with a group by clause?
Date: Thu, 01 Nov 2007 15:36:29 +0100
Message-ID: <DFCABF1E9EE0F7A9D44CA50A@rambutan.pingpong.net> (raw)
In-Reply-To: <4305.1193924619@sss.pgh.pa.us>
References: <D26563C7B9CCEB0A338FF08E@rambutan.pingpong.net>
	<4305.1193924619@sss.pgh.pa.us>



--On torsdag, november 01, 2007 09.43.39 -0400 Tom Lane <tgl@sss.pgh.pa.us> 
wrote:

> 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.

Unfortunately, altering statistics doesn't help. I see no difference when 
altering the value from 10 (default) to 100, 1000 or 100000. :-(

Are there any other things I can modify?

OH, btw, maybe something in the postgresql.conf sucks?

max_connections = 100
shared_buffers = 30000                  # min 16 or max_connections*2, 8KB 
each
temp_buffers = 2500                     # min 100, 8KB each
max_prepared_transactions = 100         # can be 0 or more
work_mem = 16384                        # min 64, size in KB
maintenance_work_mem = 16384            # min 1024, size in KB
max_stack_depth = 32768                 # min 100, size in KB
max_fsm_pages = 500000
max_fsm_relations = 20000
max_files_per_process = 2000
fsync = off
checkpoint_segments = 50                # in logfile segments, min 1, 16MB 
each
effective_cache_size = 10000            # typically 8KB each
random_page_cost = 1.8
geqo = on
geqo_threshold = 10
from_collapse_limit = 8
join_collapse_limit = 8         # 1 disables collapsing of explicit




view thread (11+ messages)  latest in thread

Message-ID: <DFCABF1E9EE0F7A9D44CA50A@rambutan.pingpong.net>
Permalink:  ../DFCABF1E9EE0F7A9D44CA50A@rambutan.pingpong.net/
Also on:    postgresql.org/message-id/DFCABF1E9EE0F7A9D44CA50A@rambutan.pingpong.net

 · 

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-performance@postgresql.org
  Cc: girgen@pingpong.net, tgl@sss.pgh.pa.us
  Subject: Re: select max(field) from table much faster with a group by clause?
  In-Reply-To: <DFCABF1E9EE0F7A9D44CA50A@rambutan.pingpong.net>
  References: <D26563C7B9CCEB0A338FF08E@rambutan.pingpong.net> <4305.1193924619@sss.pgh.pa.us> <DFCABF1E9EE0F7A9D44CA50A@rambutan.pingpong.net>

* 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