pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Carey <scott@richrelevance.com>
To: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Query planner cost estimate less than the sum of its parts?
Date: Wed, 5 Nov 2008 12:00:38 -0800
Message-ID: <a1ec7d000811051200m64561fd9l5a10983d4d40f097@mail.gmail.com> (raw)

So, we had a query run accidentally without going through the right checks
to ensure that it had the right limits in a where clause for our table
partitioning, resulting in an attempt to scan TB's of data.

Obviously, we fixed the query, but the curious result is this explain plan
(shortened, in full form its ~3500 lines long).  A true cost estimate of ~ 4
million isn't a big deal on this server.  It is plainly wrong...  wouldn't a
nested loop of this sort estimate at least 128266*4100644 for the cost?  Or
something on that order of magnitude?
Certainly, a cost estimate that is ... LESS than one of the sub sections of
the query is wrong.   This was one hell of a broken query, but it at least
should have taken an approach that was not a nested loop, and I'm curious if
that choice was due to a bad estimate here.

Nested Loop IN Join  (cost=0.00..3850831.86 rows=128266 width=8)
   Join Filter: ((log.p_p_logs.s_id)::text = (log.s_r_logs.s_id)::text)
   ->  Append  (cost=0.00..6078.99 rows=128266 width=46)
         ->  Seq Scan on p_p_logs  (cost=0.00..1.01 rows=1 width=14)
               Filter: ((date >= '2008-10-27'::date) AND (sector = 12))
         ->  Seq Scan on p_p_logs_012_2008_10_27 p_p_logs
(cost=0.00..718.22 rows=15148 width=46)
               Filter: ((date >= '2008-10-27'::date) AND (sector = 12))
      [ Snipped ~ 10 more tables]

   ->  Append  (cost=0.00..4100644.78 rows=29850181 width=118)
         ->  Seq Scan on s_r_logs  (cost=0.00..1.01 rows=1 width=14)
               Filter: log.s_r_logs.source
         ->  Seq Scan on s_r_logs_002_2008_10_01 s_r_logs  (cost=0.00..91.00
rows=1050 width=33)
               Filter: p_log.s_r_logs.source
         ->  Seq Scan on s_r_logs_002_2008_10_02 s_r_logs  (cost=0.00..65.00
rows=750 width=33)
      [ Snipped ~1500 tables of various sizes ]

view thread (3+ messages)  latest in thread

Message-ID: <a1ec7d000811051200m64561fd9l5a10983d4d40f097@mail.gmail.com>
Permalink:  ../a1ec7d000811051200m64561fd9l5a10983d4d40f097@mail.gmail.com/
Also on:    postgresql.org/message-id/a1ec7d000811051200m64561fd9l5a10983d4d40f097@mail.gmail.com

 · 

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-performance@postgresql.org
  Cc: scott@richrelevance.com
  Subject: Re: Query planner cost estimate less than the sum of its parts?
  In-Reply-To: <a1ec7d000811051200m64561fd9l5a10983d4d40f097@mail.gmail.com>
  References: <a1ec7d000811051200m64561fd9l5a10983d4d40f097@mail.gmail.com>

* 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