Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uc1SA-0002JB-LH for pgsql-performance@arkaria.postgresql.org; Mon, 13 May 2013 22:42:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Uc1S9-0008Jf-EB for pgsql-performance@arkaria.postgresql.org; Mon, 13 May 2013 22:42:45 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uc1S8-0008JU-Ar for pgsql-performance@postgresql.org; Mon, 13 May 2013 22:42:44 +0000 Received: from [2404:130:0:10::40:2] (helo=mail.catalyst.net.nz) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uc1S3-0008U5-PV for pgsql-performance@postgresql.org; Mon, 13 May 2013 22:42:41 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.catalyst.net.nz (Postfix) with ESMTP id 26C7332FD1; Tue, 14 May 2013 10:42:35 +1200 (NZST) X-Virus-Scanned: Debian amavisd-new at catalyst.net.nz Received: from mail.catalyst.net.nz ([127.0.0.1]) by localhost (bertrand.catalyst.net.nz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uN5ESqKMWwJg; Tue, 14 May 2013 10:42:34 +1200 (NZST) Received: from [192.168.1.64] (122-60-64-230.jetstream.xtra.co.nz [122.60.64.230]) (Authenticated sender: mark.kirkwood) by mail.catalyst.net.nz (Postfix) with ESMTPSA id 04775325E3; Tue, 14 May 2013 10:42:33 +1200 (NZST) Message-ID: <51916C59.6010700@catalyst.net.nz> Date: Tue, 14 May 2013 10:42:33 +1200 From: Mark Kirkwood User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130404 Thunderbird/17.0.5 MIME-Version: 1.0 To: Marti Raudsepp , ach CC: "pgsql-performance@postgresql.org" Subject: Re: statistics target for columns in unique constraint? References: <1368457293547-5755256.post@n5.nabble.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2404:130:0:10::40:2 (failed) X-Pg-Spam-Score: 1.3 (+) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 14/05/13 10:10, Marti Raudsepp wrote: > On Mon, May 13, 2013 at 6:01 PM, ach wrote: >> what I'm wondering is, since >> the unique constraint already covers the whole table and all rows in >> entirety, is it really necessary for statistics to be set that high on >> those? > > AFAIK if there are exact-matching unique constraints/indexes for a > query's WHERE clause, the planner will deduce that the query only > returns 1 row and won't consult statistics at all. > >> Or does that only serve to slow down inserts to that table? > > It doesn't slow down inserts directly. Tables are analyzed in the > background by autovacuum. However, I/O traffic from autovacuum analyze > may slow down inserts running concurrently. > > A higher number in stats target means larger stats structures - which in turn means that the planning stage of *all* queries may be impacted - e.g takes up more memory, slightly slower as these larger structures are read, iterated over, free'd etc. So if your only access is via a defined unique key, then (as Marti suggests) - a large setting for stats target would seem to be unnecessary. If you have access to a test environment I'd recommend you model the effect of reducing stats target down (back to the default of 100 or even to the old version default of 10). A little - paranoia - maybe switch on statement logging and ensure that there are no *other* ways this table is accessed...the fact that the number was cranked up from the default is a little suspicious! Regards Mark -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance