pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Stark <gsstark@mit.edu>
To: Dennis Bjorklund <db@zigo.dhs.org>
Cc: Greg Stark <gsstark@mit.edu>
Cc: Gaetano Mendola <mendola@bigfoot.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: 7.4 vs 7.3 ( hash join issue )
Date: 22 Sep 2004 13:38:00 -0400
Message-ID: <87sm9acih3.fsf@stark.xeocode.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0409221717010.9559-100000@zigo.dhs.org>
References: <Pine.LNX.4.44.0409221717010.9559-100000@zigo.dhs.org>


Dennis Bjorklund <db@zigo.dhs.org> writes:

> On 22 Sep 2004, Greg Stark wrote:
> 
> > Actually this looks like it's arguably a bug to me. Why does the hash
> > join execute the sequential scan at all? Shouldn't it also like the
> > merge join recognize that the other hashed relation is empty and skip
> > the sequential scan entirely?
> 
> I'm not sure you can classify that as a bug. It's just that he in one of 
> the plans started with the empty scan and bacause of that didn't need 
> the other, but with the hash join it started with the table that had 16 
> rows and then got to the empty one.

No, postgres didn't do things in reverse order. It hashed the empty table and
then went ahead and checked every record of the non-empty table against the
empty hash table.

Reading the code there's no check for this, and it seems like it would be a
useful low-cost little optimization.

I think postgres normally hashes the table it thinks is smaller, so you do
join against an empty relation it should end up on the hash side of the hash
join and allow postgres to avoid the scan of the outer table.

-- 
greg




view thread (13+ messages)  latest in thread

Message-ID: <87sm9acih3.fsf@stark.xeocode.com>
Permalink:  ../87sm9acih3.fsf@stark.xeocode.com/
Also on:    postgresql.org/message-id/87sm9acih3.fsf@stark.xeocode.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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: gsstark@mit.edu, db@zigo.dhs.org, mendola@bigfoot.com
  Subject: Re: 7.4 vs 7.3 ( hash join issue )
  In-Reply-To: <87sm9acih3.fsf@stark.xeocode.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