Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id D66916324A1 for ; Sun, 11 Apr 2010 19:50:00 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 79447-10 for ; Sun, 11 Apr 2010 22:49:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gx0-f214.google.com (mail-gx0-f214.google.com [209.85.217.214]) by mail.postgresql.org (Postfix) with ESMTP id 5ACB56322E8 for ; Sun, 11 Apr 2010 19:49:50 -0300 (ADT) Received: by gxk6 with SMTP id 6so2675411gxk.14 for ; Sun, 11 Apr 2010 15:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=t/LAWzLAM7z+V/sbmsswab0AbUHZZ6seglrneqVsHqo=; b=FxdXJUP0Kr00CVaYmTQSvnrnZDNtbqSu0O+4Yao0kKzkkUBU/P4r01canstU0SC/l7 riHKIGUVCoVcgV04IoAlHPbobkoNBrr09sncQIQL3ET7hH4MNjStYCxCK734pKzEEZ1f 6uZR8kjXLxVSGFVG4vVr/e66DMjsRlQBJmCVI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=ozSBrbjm0epgyBTNj2ig8TWjxw5kvAzPL9PBxYpJB5023yy72XFrwh9rq8QGqT32Lt MPCkTPwlW150EOJL+Ll2Nz4igUwjFlM+lawJNyqvZ8/Gs7fI7qbQGZT/jh9QHxQc8MDB O4z47waXPRFqkKuEtDcD+trO9porxnTdlo/H0= MIME-Version: 1.0 Received: by 10.150.198.15 with HTTP; Sun, 11 Apr 2010 15:49:49 -0700 (PDT) In-Reply-To: <4BC2500F.5000306@gmail.com> References: <4BC23B3E.5020500@gmail.com> <4BC2500F.5000306@gmail.com> Date: Sun, 11 Apr 2010 16:49:49 -0600 Received: by 10.151.16.4 with SMTP id t4mr2936892ybi.107.1271026189147; Sun, 11 Apr 2010 15:49:49 -0700 (PDT) Message-ID: Subject: Re: planer chooses very bad plan From: Scott Marlowe To: Corin Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=-10 required=5 tests=FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201004/145 X-Sequence-Number: 38395 On Sun, Apr 11, 2010 at 4:41 PM, Corin wrote: > On 11.04.2010 23:18, Scott Marlowe wrote: >> >> In both instances your number of rows estimated is WAY higher than the >> actual number of rows returned. =A0Perhaps if you increased >> default_statistics_target to 100, 200, 500 etc. re-analyzed, and then >> reun explain analyze again. >> >> Also increasing work_mem might encourage the bitmap index scans to occur= . >> > > Increasing the statistics >=3D 500 indeed helped a lot and causes the pla= nner > to choose a good plan. :) > > I'm now thinking about increasing the default_statistics_target of the wh= ole > server from the default (100) to 1000, because I have many tables with > similar data. As the size of the table index seems not change at all, I > wonder how much additional storage is needed? I only care about runtime > performance: are inserts/updates affected by this change? Or is only anal= yze > affected (only run once during the night)? default stats target has more to do with how many distinct values / ranges of values you have. If your data has a nice smooth curve of distribution smaller values are ok. Large datasets with very weird data distributions can throw off the planner. There's a cost for both analyzing and for query planning. If 500 fixes this table, and all the other tables are fine at 100 then it might be worth doing an alter table alter column for just this column. However, then you've got to worry about time spent monitoring and analyzing queries in the database for if / when they need a higher stats target. Also, look at increasing effective cache size if the db fits into memory. Lowering random page cost helps too.