X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 58B98329DD1 for ; Wed, 22 Sep 2004 18:38:18 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64801-05 for ; Wed, 22 Sep 2004 17:38:12 +0000 (GMT) Received: from stark.xeocode.com (gsstark.mtl.istop.com [66.11.160.162]) by svr1.postgresql.org (Postfix) with ESMTP id CED87329D14 for ; Wed, 22 Sep 2004 18:38:11 +0100 (BST) Received: from localhost ([127.0.0.1] helo=stark.xeocode.com) by stark.xeocode.com with smtp (Exim 3.36 #1 (Debian)) id 1CAB45-00035h-00; Wed, 22 Sep 2004 13:38:01 -0400 To: Dennis Bjorklund Cc: Greg Stark , Gaetano Mendola , Subject: Re: 7.4 vs 7.3 ( hash join issue ) References: In-Reply-To: From: Greg Stark Organization: The Emacs Conspiracy; member since 1992 Date: 22 Sep 2004 13:38:00 -0400 Message-ID: <87sm9acih3.fsf@stark.xeocode.com> Lines: 28 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/217 X-Sequence-Number: 8345 Dennis Bjorklund 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