pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #13817: Query planner strange choose while select/count small part of big table - complete
Date: Fri, 18 Dec 2015 19:27:13 +0100
Message-ID: <20151218182712.GD362@hjp.at> (raw)
In-Reply-To: <CAButoGF97JDZiQJuVgOYLvybRPRYbgH=+T+C5WCR-_r41Y1dkg@mail.gmail.com>
References: <20151214114527.11345.70373@wrigleys.postgresql.org>
	<CAK_s-G3RfevmWAeKhdZEaKmY6U0d2pOKEya=S=nMnvDgt0u3WA@mail.gmail.com>
	<CAButoGGBgzkeOw8wm53XZuLH_VPKEhtyn+hbLsdKTEh7TD9tRA@mail.gmail.com>
	<CAK_s-G1XnnqwcAoetpJKKd3TtO3uuriD_Qzye3hQEH2pbz43Ag@mail.gmail.com>
	<CAButoGF97JDZiQJuVgOYLvybRPRYbgH=+T+C5WCR-_r41Y1dkg@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 2015-12-17 16:19:24 +0100, Marcin Sieńko wrote:
> I've done it already. I've also already check rewrited query. No changes. But i
> have a idea. There is generated base and there are "normal" shipment_order_item
> with 3 - 100 maybe 10000 shipment_order_sub_item but one has 3 992 102. Could
> it be a problem?

A very skewed distribution can be a problem, yes. If the planner doesn't
know whether you will select a shipment_order_item with 3 subitems or
one with 3 million subitems, it can only use the average number of
subitems - which may be bad for either case.

But your plan looks worse than a single outlier of 3992102.

The nested loop semi join in line 3 of http://explain.depesz.com/s/Rus
(I'm using that as the reference because it's easier to read than your
line-wrapped plan and because the lines are numbered and easier to
reference) is expected to return 1 row. But the nested loop at line 2 is
expected to return 3992515 rows. Unless I'm missing something this means
that planner thinks that there are *on average* 3992515 subitems per
item. 

Can you post the output of these queries?

select * from pg_stats
where tablename='shipment_order_sub_item' and attname='shipment_order_item_id';

select count(*) from shipment_order_sub_item;

select count(distinct(shipment_order_item_id))
from shipment_order_sub_item;


> If yes that is my bad to ask You because I'belive there will not occur in
> production and counting could bye match faster.

Yeah, if you have unrealistic test data, it will produce unrealistic
results and you can probably ignore them. Although in my experience it
is usually the other way around: The test data has a nice, regular
distribution and the production data is skewed a lot more than anyone
expected.

	hp

-- 
   _  | Peter J. Holzer    | I want to forget all about both belts and
|_|_) |                    | suspenders; instead, I want to buy pants 
| |   | hjp@hjp.at         | that actually fit.
__/   | http://www.hjp.at/ |   -- http://noncombatant.org/

Attachments:

  signature.asc (application/pgp-signature, 810B) download

view thread (9+ messages)  latest in thread

Message-ID: <20151218182712.GD362@hjp.at>
Permalink:  ../20151218182712.GD362@hjp.at/
Also on:    postgresql.org/message-id/20151218182712.GD362@hjp.at

 · 

reply

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: hjp-pgsql@hjp.at
  Subject: Re: BUG #13817: Query planner strange choose while select/count small part of big table - complete
  In-Reply-To: <20151218182712.GD362@hjp.at>
  References: <20151214114527.11345.70373@wrigleys.postgresql.org> <CAK_s-G3RfevmWAeKhdZEaKmY6U0d2pOKEya=S=nMnvDgt0u3WA@mail.gmail.com> <CAButoGGBgzkeOw8wm53XZuLH_VPKEhtyn+hbLsdKTEh7TD9tRA@mail.gmail.com> <CAK_s-G1XnnqwcAoetpJKKd3TtO3uuriD_Qzye3hQEH2pbz43Ag@mail.gmail.com> <CAButoGF97JDZiQJuVgOYLvybRPRYbgH=+T+C5WCR-_r41Y1dkg@mail.gmail.com> <20151218182712.GD362@hjp.at>

* 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