X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A8265329D04 for ; Sat, 18 Sep 2004 20:48:24 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 18197-08 for ; Sat, 18 Sep 2004 19:48:19 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 72061329CFD for ; Sat, 18 Sep 2004 20:48:20 +0100 (BST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i8IJmEWO007262; Sat, 18 Sep 2004 15:48:14 -0400 (EDT) To: "Steinar H. Gunderson" Cc: pgsql-performance@postgresql.org Subject: Re: Planner having way wrong estimate for group aggregate In-reply-to: <20040918170117.GA3354@uio.no> References: <20040918170117.GA3354@uio.no> Comments: In-reply-to "Steinar H. Gunderson" message dated "Sat, 18 Sep 2004 19:01:17 +0200" Date: Sat, 18 Sep 2004 15:48:13 -0400 Message-ID: <7261.1095536893@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/196 X-Sequence-Number: 8324 "Steinar H. Gunderson" writes: > Now, my first notion was creating a functional index to help the planner: > ... > However, this obviously didn't help the planner (this came as a surprise to > me, but probably won't come as a surprise to the more seasoned users here :-) 7.4 doesn't have any statistics on expression indexes. 8.0 will do what you want though. (I just fixed an oversight that prevented it from doing so...) > Actually, it seems that the higher I set statistics on "tid", the worse the > estimate becomes. I believe that the estimate of number of groups will be exactly the same as the estimate of the number of values of tid --- there's no knowledge that date_trunc() might reduce the number of distinct values. > Any ideas for speeding this up? In 7.4, the only way I can see to force this to use a hash aggregate is to temporarily set enable_sort false or raise sort_mem. regards, tom lane