From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tim Uckun <timuckun@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Problems with adding a is not null to a query.
Date: Mon, 17 Jan 2011 18:55:49 -0500
Message-ID: <24112.1295308549@sss.pgh.pa.us> (raw)
In-Reply-To: <AANLkTinD_Bmgy34W70ywxXM0b1xOWBBEvR8hO95y9LzS@mail.gmail.com>
References: <AANLkTi=1DVjv6XdGSZ8H_LGvKdLBME4Gp15O0xnWv_8M@mail.gmail.com>
<28545.1295106303@sss.pgh.pa.us>
<AANLkTikFEyOOX2sWKB0vpCSeUKwaqo+vfTRJ_DMNTpcn@mail.gmail.com>
<9026.1295198134@sss.pgh.pa.us>
<AANLkTimFK6AWNo+k+RoMf3=4uu_iRcmTKtASwM3=eWO5@mail.gmail.com>
<AANLkTi=6wYtWRURpUtBgJcZEMPGUne+emSmxL_sGbP6y@mail.gmail.com>
<AANLkTim4je4KYdbUykmfoCCjWf1GHcGDGxUb_XuQ6d2T@mail.gmail.com>
<20744.1295297840@sss.pgh.pa.us>
<AANLkTinD_Bmgy34W70ywxXM0b1xOWBBEvR8hO95y9LzS@mail.gmail.com>
Tim Uckun <timuckun@gmail.com> writes:
>> Am I right in guessing that pg_stats.n_distinct is much too low for
>> the domain_id column?
> the domain_id is in the topical urls. A select count of domains shows
> that there are 700 domains, the pg_stats shows 170 which seems kind of
> low but maybe is not out of bounds because most domains are probably
> inactive.
It sounds like you've got one of those long-tail distributions where
there are lots and lots of the first couple hundred domains, and not
many at all of the last few. The problem with the stats as you've got
them is that the planner isn't aware of the long tail, so for this
specific domain id that's not even there at all, you're getting an
estimate of a couple of thousand matches --- which is why it goes for
the indexscan-according-to-ORDER-BY plan. It's figuring it will hit one
of those matches and be able to end the scan after reading much less
than all of the table.
As I've stated repeatedly, your next move needs to be to increase the
stats target, at least for that column if not globally. You probably
don't need to have it know about every last domain id, but you need to
have it know about enough that it realizes that domains not included in
the MCV list are going to appear less than a couple of thousand times.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, timuckun@gmail.com, robertmhaas@gmail.com
Subject: Re: Problems with adding a is not null to a query.
In-Reply-To: <24112.1295308549@sss.pgh.pa.us>
References: <AANLkTi=1DVjv6XdGSZ8H_LGvKdLBME4Gp15O0xnWv_8M@mail.gmail.com> <28545.1295106303@sss.pgh.pa.us> <AANLkTikFEyOOX2sWKB0vpCSeUKwaqo+vfTRJ_DMNTpcn@mail.gmail.com> <9026.1295198134@sss.pgh.pa.us> <AANLkTimFK6AWNo+k+RoMf3=4uu_iRcmTKtASwM3=eWO5@mail.gmail.com> <AANLkTi=6wYtWRURpUtBgJcZEMPGUne+emSmxL_sGbP6y@mail.gmail.com> <AANLkTim4je4KYdbUykmfoCCjWf1GHcGDGxUb_XuQ6d2T@mail.gmail.com> <20744.1295297840@sss.pgh.pa.us> <AANLkTinD_Bmgy34W70ywxXM0b1xOWBBEvR8hO95y9LzS@mail.gmail.com> <24112.1295308549@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox