Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id D78821337BD1 for ; Sat, 23 Apr 2011 16:33:42 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 79278-10 for ; Sat, 23 Apr 2011 19:33:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-yi0-f46.google.com (mail-yi0-f46.google.com [209.85.218.46]) by mail.postgresql.org (Postfix) with ESMTP id 339BF1337B93 for ; Sat, 23 Apr 2011 16:33:35 -0300 (ADT) Received: by yia27 with SMTP id 27so358428yia.19 for ; Sat, 23 Apr 2011 12:33:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:references:in-reply-to:mime-version :content-transfer-encoding:content-type:message-id:cc:x-mailer:from :subject:date:to; bh=T4YHr/OA6KK6w7clKiGy65Jb95EO7+iRc3G4e8YB6dI=; b=QaE0j93ec4/WYlgWFWEkFUZc/CEgwlwsu3o3KWr7G8Lnni6Fw5HLogrjoUUc4WRFUE 5OOeJVkgtoYF6vNX9Od/K7/dAufC4ywwHEGJH9ph7v/rsBi5gH+/lUxvMowoM5MQFFBo nX/f7D0sR9nPOfBhAD/vSok91VpmDuQJ/dYFQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=references:in-reply-to:mime-version:content-transfer-encoding :content-type:message-id:cc:x-mailer:from:subject:date:to; b=A9dzINEdGJ0Gh0JqrGSZf6WEnhlua/BcpA6oT5bD/wi/3l3+u8a5fe4pCqaHjAMCxf I9/kAJJy/S0Cds1rkkjhmyOsYxmK1etNIGX6TUgadH2HDPrv41h4iJRgVhBsvTBmk7Ob 4VLV2d6fq0y3nKnvymHWNI/TFqB4srws+DNLQ= Received: by 10.101.206.16 with SMTP id i16mr1266881anq.160.1303587214463; Sat, 23 Apr 2011 12:33:34 -0700 (PDT) Received: from [10.4.195.72] ([198.228.194.51]) by mx.google.com with ESMTPS id q8sm2657176ann.45.2011.04.23.12.33.30 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 23 Apr 2011 12:33:32 -0700 (PDT) References: In-Reply-To: Mime-Version: 1.0 (iPhone Mail 8A293) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Message-Id: <4B594466-0554-4AF8-A8BC-8FDA9C393DF9@gmail.com> Cc: "pgsql-performance@postgresql.org" X-Mailer: iPhone Mail (8A293) From: Robert Haas Subject: Re: big distinct clause vs. group by Date: Sat, 23 Apr 2011 15:34:11 -0400 To: Uwe Bartels X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.897 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, MIME_QP_LONG_LINE=0.001, RFC_ABUSE_POST=0.001 X-Spam-Level: X-Archive-Number: 201104/334 X-Sequence-Number: 43396 On Apr 18, 2011, at 1:13 PM, Uwe Bartels wrote: > Hi Robert, >=20 > thanks for your answer. > the aggregate function I was talking about is the function I need to use f= or the non-group by columns like min() in my example. > There are of course several function to choose from, and I wanted to know w= hich causes as less as possible resources. Oh, I see. min() is probably as good as anything. You could also create a cu= stom aggregate that just always returns its first input. I've occasionally w= ished we had such a thing as a built-in. Another option is to try to rewrite the query with a subselect so that you d= o the aggregation first and then add the extra columns by joining against th= e output of the aggregate. If this can be done without joining the same tabl= e twice, it's often much faster, but it isn't always possible. :-( ...Robert=