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 16:58:25 -0400
Message-ID: <14110.1058216305@sss.pgh.pa.us> (raw)
In-Reply-To: <87znjhkl3u.fsf@stark.dyndns.tv>
References: <873chi2o53.fsf@stark.dyndns.tv>
<10251.1058205875@sss.pgh.pa.us>
<87znjhkl3u.fsf@stark.dyndns.tv>
Greg Stark <gsstark@mit.edu> writes:
> Tom Lane <tgl@sss.pgh.pa.us> writes:
>> However, it looks to me like the subquery-scan-outside plan probably
>> is the faster one, on both my machine and yours. I get
> Woah, that's pretty whacky. It seems like it ought to be way faster to do a
> single sequential scan and return two records for each tuple read rather than
> do an entire unnecessary sequential scan, even if most or even all of the
> second one is cached.
The problem is the CPU expense of executing "SELECT 1 UNION SELECT 2"
over and over. Doing that for every row of the outer table adds up.
We were both testing on relatively small tables --- I suspect the
results would be different if the outer table were too large to fit
in disk cache.
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.
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-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: <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>
* 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