pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Marko Tiikkaja <marko@joh.to>
To: Maxim Boguk <maxim.boguk@gmail.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: BUG #13528: LATERAL vs. correlated scalar subquery
Date: Thu, 30 Jul 2015 14:24:47 +0200
Message-ID: <55BA178F.9050503@joh.to> (raw)
In-Reply-To: <CAK-MWwTOHzLEKVF+FahoMv+-r1E99AEQigCMYfUcHGjm9K170w@mail.gmail.com>
References: <20150730085352.9098.47740@wrigleys.postgresql.org>
	<CAK-MWwTOHzLEKVF+FahoMv+-r1E99AEQigCMYfUcHGjm9K170w@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 7/30/15 1:48 PM, Maxim Boguk wrote:
> You could see that the new plan have lower total cost than the old plan
> (​cost=1867.28..1873.03 vs ​cost=0.00..125498.75).
> I think it's primary reason why it been selected (planner could produce the
> old plan but new plan wins on the cost basis).

I'll have to admit I could've put more time into the original report, 
but I don't think that's accurate.  If I disable hashagg and hashjoin 
and tune the query to tell the planner that only one row is to be 
expected, the plan looks like this:

=#* explain analyze select u.elem, x.count from (SELECT u.elem FROM 
unnest(array[1]) u(elem) LIMIT 1) u(elem), lateral (select counts.count 
from counts where counts.a = u.elem) x;
                                                                   QUERY 
PLAN
----------------------------------------------------------------------------------------------------------------------------------------------
  Nested Loop  (cost=0.29..4778.86 rows=1 width=12) (actual 
time=0.060..52.380 rows=1 loops=1)
    Join Filter: (u.elem = data.a)
    Rows Removed by Join Filter: 99999
    ->  Limit  (cost=0.00..0.01 rows=1 width=4) (actual 
time=0.010..0.011 rows=1 loops=1)
          ->  Function Scan on unnest u  (cost=0.00..1.00 rows=100 
width=4) (actual time=0.009..0.009 rows=1 loops=1)
    ->  GroupAggregate  (cost=0.29..4774.33 rows=200 width=4) (actual 
time=0.047..45.634 rows=100000 loops=1)
          Group Key: data.a
          ->  Index Only Scan using data_pkey on data 
(cost=0.29..4298.32 rows=94802 width=4) (actual time=0.042..19.381 
rows=100000 loops=1)
                Heap Fetches: 100000
  Planning time: 0.147 ms
  Execution time: 52.429 ms
(11 rows)


which to me suggests that the planner just doesn't realize that it can 
push the condition on counts.a into the view.


.m


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (4+ messages)  latest in thread

Message-ID: <55BA178F.9050503@joh.to>
Permalink:  ../55BA178F.9050503@joh.to/
Also on:    postgresql.org/message-id/55BA178F.9050503@joh.to

 · 

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: marko@joh.to, maxim.boguk@gmail.com
  Subject: Re: BUG #13528: LATERAL vs. correlated scalar subquery
  In-Reply-To: <55BA178F.9050503@joh.to>
  References: <20150730085352.9098.47740@wrigleys.postgresql.org> <CAK-MWwTOHzLEKVF+FahoMv+-r1E99AEQigCMYfUcHGjm9K170w@mail.gmail.com> <55BA178F.9050503@joh.to>

* 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