pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Greg Stark <gsstark@mit.edu>
Cc: pgsql-performance@postgresql.org
Subject: Re: optimizer picks smaller table to drive nested loops?
Date: Mon, 14 Jul 2003 18:41:25 -0400
Message-ID: <16143.1058222485@sss.pgh.pa.us> (raw)
In-Reply-To: <14110.1058216305@sss.pgh.pa.us>
References: <873chi2o53.fsf@stark.dyndns.tv>
	<10251.1058205875@sss.pgh.pa.us>
	<87znjhkl3u.fsf@stark.dyndns.tv>
	<14110.1058216305@sss.pgh.pa.us>

I said:
> I am not sure why the planner did not choose to stick a Materialize
> node atop the Subquery Scan, though.  It looks to me like it should
> have considered that option --- possibly the undercharging for Subquery
> Scan is the reason it wasn't chosen.

Indeed, after fixing the unrealistic estimate for SubqueryScan, I get
this:

regression=# explain analyze select * from tenk1, (select 1 union all select 2) as x;
                                                          QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------
 Nested Loop  (cost=0.06..858.06 rows=20000 width=248) (actual time=0.25..1448.19 rows=20000 loops=1)
   ->  Seq Scan on tenk1  (cost=0.00..458.00 rows=10000 width=244) (actual time=0.06..162.48 rows=10000 loops=1)
   ->  Materialize  (cost=0.06..0.08 rows=2 width=4) (actual time=0.01..0.03 rows=2 loops=10000)
         ->  Subquery Scan x  (cost=0.00..0.06 rows=2 width=4) (actual time=0.10..0.27 rows=2 loops=1)
               ->  Append  (cost=0.00..0.04 rows=2 width=0) (actual time=0.07..0.20 rows=2 loops=1)
                     ->  Subquery Scan "*SELECT* 1"  (cost=0.00..0.02 rows=1 width=0) (actual time=0.05..0.08 rows=1 loops=1)
                           ->  Result  (cost=0.00..0.01 rows=1 width=0) (actual time=0.03..0.03 rows=1 loops=1)
                     ->  Subquery Scan "*SELECT* 2"  (cost=0.00..0.02 rows=1 width=0) (actual time=0.03..0.06 rows=1 loops=1)
                           ->  Result  (cost=0.00..0.01 rows=1 width=0) (actual time=0.01..0.02 rows=1 loops=1)
 Total runtime: 1627.26 msec
(10 rows)

which is probably the best way to do it, all things considered.

			regards, tom lane



view thread (6+ messages)

Message-ID: <16143.1058222485@sss.pgh.pa.us>
Permalink:  ../16143.1058222485@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16143.1058222485@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, gsstark@mit.edu
  Subject: Re: optimizer picks smaller table to drive nested loops?
  In-Reply-To: <16143.1058222485@sss.pgh.pa.us>
  References: <873chi2o53.fsf@stark.dyndns.tv> <10251.1058205875@sss.pgh.pa.us> <87znjhkl3u.fsf@stark.dyndns.tv> <14110.1058216305@sss.pgh.pa.us> <16143.1058222485@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