X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5BA9A53FD3 for ; Tue, 10 May 2005 21:14:34 -0300 (ADT) 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 95484-10 for ; Wed, 11 May 2005 00:14:24 +0000 (GMT) Received: from priv-edtnes46.telusplanet.net (defout.telus.net [199.185.220.240]) by svr1.postgresql.org (Postfix) with ESMTP id 156AC53FCB for ; Tue, 10 May 2005 21:14:23 -0300 (ADT) Received: from localhost ([199.185.220.240]) by priv-edtnes46.telusplanet.net (InterMail vM.6.01.04.04 201-2131-118-104-20050224) with ESMTP id <20050511001426.HKFB7617.priv-edtnes46.telusplanet.net@localhost> for ; Tue, 10 May 2005 18:14:26 -0600 Received: from 209.17.183.249 ( [209.17.183.249]) as user a3a18850@204.209.205.53 by webmail.telus.net with HTTP; Tue, 10 May 2005 17:14:26 -0700 Message-ID: <1115770466.42814e62cb0e1@webmail.telus.net> Date: Tue, 10 May 2005 17:14:26 -0700 From: Mischa Sandberg To: pgsql-general@postgresql.org Subject: Re: [PERFORM] "Hash index" vs. "b-tree index" (PostgreSQL References: <427F6853.90308@cs.concordia.ca> <427F757A.8000407@samurai.com> <59d991c405050908271b55e673@mail.gmail.com> <427F8321.5030702@samurai.com> <20050509163423.GH35026@decibel.org> <427F9211.2090008@samurai.com> <20050509165133.GJ35026@decibel.org> <427FFCD3.1010803@samurai.com> <20050510153245.GA31103@decibel.org> <1115760957.4281293e0155b@webmail.telus.net> <1115765164.13684.25.camel@amateljan.mirlogic.com> In-Reply-To: <1115765164.13684.25.camel@amateljan.mirlogic.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.1-cvs X-Originating-IP: 209.17.183.249 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.043 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_POST, FORGED_RCVD_HELO X-Spam-Level: * X-Archive-Number: 200505/526 X-Sequence-Number: 77874 Quoting Mark Lewis : > If the original paper was published in 1984, then it's been more than > 20 years. Any potential patents would already have expired, no? Don't know, but the idea is pervasive among different vendors ... perhaps that's a clue. And having now read beyond the start of ExecHashJoin(), I can see that PG does indeed implement Grace hash; and the implementation is nice and clean. If there were room for improvement, (and I didn't see it in the source) it would be the logic to: - swap inner and outer inputs (batches) when the original inner turned out to be too large for memory, and the corresponding outer did not. If you implement that anyway (complicates the loops) then it's no trouble to just hash the smaller of the two, every time; saves some CPU. - recursively partition batches where both inner and outer input batch ends up being too large for memory, too; or where the required number of batch output buffers alone is too large for working RAM. This is only for REALLY big inputs. Note that you don't need a bad hash function to get skewed batch sizes; you only need a skew distribution of the values being hashed.