X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id E56659F9B01 for ; Thu, 25 May 2006 18:15:38 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 33839-08 for ; Thu, 25 May 2006 18:15:33 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from exchange.g2switchworks.com (mail.g2switchworks.com [63.87.162.25]) by postgresql.org (Postfix) with ESMTP id 402A79F94EA for ; Thu, 25 May 2006 18:15:33 -0300 (ADT) Received: from 10.10.1.37 ([10.10.1.37]) by exchange.g2switchworks.com ([10.10.1.2]) with Microsoft Exchange Server HTTP-DAV ; Thu, 25 May 2006 21:15:29 +0000 Received: from state.g2switchworks.com by mail.g2switchworks.com; 25 May 2006 16:15:29 -0500 Subject: Re: is it possible to make this faster? From: Scott Marlowe To: Tom Lane Cc: Merlin Moncure , Postgresql Performance In-Reply-To: <15919.1148590347@sss.pgh.pa.us> References: <15919.1148590347@sss.pgh.pa.us> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1148591729.25526.57.camel@state.g2switchworks.com> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.6 (1.4.6-2) Date: Thu, 25 May 2006 16:15:29 -0500 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/480 X-Sequence-Number: 19267 On Thu, 2006-05-25 at 15:52, Tom Lane wrote: > "Merlin Moncure" writes: > > been doing a lot of pgsql/mysql performance testing lately, and there > > is one query that mysql does much better than pgsql...and I see it a > > lot in normal development: > > > select a,b,max(c) from t group by a,b; > > > t has an index on a,b,c. > > The index won't help, as per this comment from planagg.c: > > * We don't handle GROUP BY, because our current implementations of > * grouping require looking at all the rows anyway, and so there's not > * much point in optimizing MIN/MAX. > > Given the numbers you mention (300k rows in 2000 groups) I'm not > convinced that an index-based implementation would help much; we'd > still need to fetch at least one record out of every 150, which is > going to cost near as much as seqscanning all of them. > > > recent versions of mysql do much better, returning same set in < 20ms. > > Well, since they don't do MVCC they can answer this query from the > index without going to the heap at all. But that still seems remarkably > fast for something that has to grovel through 300k index entries. Well, they do, just with innodb tables. Merlin, have you tried this against innodb tables to see what you get?