pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: scott.marlowe <scott.marlowe@ihs.com>
To: Neil Conway <neilc@samurai.com>
Cc: Pailloncy Jean-Gérard <pailloncy@ifrance.com>
Cc: PostgreSQL Performance <pgsql-performance@postgresql.org>
Subject: Re: slow plan for min/max
Date: Mon, 8 Sep 2003 15:40:48 -0700
Message-ID: <200309081540.48926.josh@agliodbs.com> (raw)
In-Reply-To: <Pine.LNX.4.33.0309081434150.11709-100000@css120.ihs.com>
References: <Pine.LNX.4.33.0309081434150.11709-100000@css120.ihs.com>

Scott,
 
> Not exactly.  While max(id) is easily optimized by query replacement, 
> more complex aggregates will still have perfomance issues that would not 
> be present in a row locking database.  i.e. max((field1/field2)*field3) is 
> still going to cost more to process, isn't it?

Sorry, no.   

The issue has nothing to do with MVCC.   It has everything to do with the fact 
that PostgreSQL allows you to create your own aggregates using functions in 
any of 11 languages.   This forces the planner to treat aggregates as a 
"black box" which does not allow index utilization, because the planner 
simply doesn't know what the aggregate is doing internally.

To put it another way, the planner sees SUM() or CONCAT() -- which require 
table scans as they must include all values -- as identical to MAX() and 
MIN().    

Escaping this would require programming a special exception for MAX() and 
MIN() into the planner and parser.   This has been discussed numerous times 
on HACKERS; the problem is, making special exceptions for MAX() and MIN() 
would then make it very difficult to implement MAX() or MIN() for new data 
types, as well as requiring a lot of debugging in numerous places.   So far, 
nobody has been frustrated enough to spend 3 months tackling the problem.

-- 
-Josh Berkus
 Aglio Database Solutions
 San Francisco




view thread (20+ messages)  latest in thread

Message-ID: <200309081540.48926.josh@agliodbs.com>
Permalink:  ../200309081540.48926.josh@agliodbs.com/
Also on:    postgresql.org/message-id/200309081540.48926.josh@agliodbs.com

 · 

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: josh@agliodbs.com, scott.marlowe@ihs.com, neilc@samurai.com, pailloncy@ifrance.com
  Subject: Re: slow plan for min/max
  In-Reply-To: <200309081540.48926.josh@agliodbs.com>
  References: <Pine.LNX.4.33.0309081434150.11709-100000@css120.ihs.com> <200309081540.48926.josh@agliodbs.com>

* 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