Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id C202DB035A6 for ; Fri, 30 Mar 2012 22:56:58 -0300 (ADT) Received: from mail-qa0-f42.google.com ([209.85.216.42]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SDnYk-00061q-Nr for pgsql-hackers@postgresql.org; Sat, 31 Mar 2012 01:56:57 +0000 Received: by qafi31 with SMTP id i31so1210341qaf.1 for ; Fri, 30 Mar 2012 18:56:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=rdpcmmHaIk5wJsYyktImI4b+I3p/kmEZWKFWOkAmcFU=; b=v/7eqbAXxaAf/F6VWAzzGbz/DAo2ypMV3uwEUiOgdVQxXsvjkUmffLerrRVJEUdxyX libsFUH7W2bu1EKQtHG/x6UhFQxYtQsAW0/9OI2JFS+S/XsOopN+K3Hkt5SaglXGAJiw k5LPb/8Nxks4zL2HlvO77jh9s/WhE5NjrLxi8e2NMbjJsiJtMp3FPP0+OCHOyXeq9DaV HRQmPePkb+UKg0mlrx2hPHV1X5BVKSooN8Vagmkr4aC32ZYCkdPyCNgNm/QqwAkhcAuV 5oVpKE9SpEcNDKiHH6lfWvVGt0/UuaCEw5RBfPcmUI95PzWgv7AZvF9MlI4CnlTPgTaS QEig== Received: by 10.224.187.142 with SMTP id cw14mr1226784qab.68.1333159001482; Fri, 30 Mar 2012 18:56:41 -0700 (PDT) Received: from speedbook.home.jay.fm (home.jay.fm. [173.166.48.118]) by mx.google.com with ESMTPS id fp8sm21528439qab.20.2012.03.30.18.56.39 (version=SSLv3 cipher=OTHER); Fri, 30 Mar 2012 18:56:40 -0700 (PDT) Message-ID: <4F766454.9040909@gmail.com> Date: Fri, 30 Mar 2012 21:56:36 -0400 From: Jay Levitt User-Agent: Postbox 3.0.3 (Macintosh/20120304) MIME-Version: 1.0 To: Tom Lane CC: Ants Aasma , PostgreSQL-development , Francois Deliege Subject: Re: [PATCH] Lazy hashaggregate when no aggregation is needed References: <22709.1332944158@sss.pgh.pa.us> In-Reply-To: <22709.1332944158@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) X-Archive-Number: 201203/1888 X-Sequence-Number: 205769 Tom Lane wrote: > Ants Aasma writes: >> A user complained on pgsql-performance that SELECT col FROM table >> GROUP BY col LIMIT 2; performs a full table scan. ISTM that it's safe >> to return tuples from hash-aggregate as they are found when no >> aggregate functions are in use. Attached is a first shot at that. > > As I commented in the other thread, the user would be a lot better off > if he'd had an index on the column in question. I'm not sure it's worth > complicating the hashagg logic when an indexscan + groupagg would > address the case better. Would this patch help in the case where "table" is actually a set-returning function, and thus can't have an index? (I don't yet know enough about the tree to know when hashaggs get used). I'm wondering if this is a useful exception to the "restrictions can't get pushed down through GROUP BYs" rule. Jay