X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id DC171D1E8FB for ; Sat, 17 Apr 2004 13:08:19 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 62629-01 for ; Sat, 17 Apr 2004 13:08:18 -0300 (ADT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 6B936D1E8A5 for ; Sat, 17 Apr 2004 13:08:17 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i3HG8Fik010604; Sat, 17 Apr 2004 12:08:16 -0400 (EDT) To: "Jim C. Nasby" Cc: pgsql-performance@postgreSQL.org Subject: Re: Horribly slow hash join In-reply-to: <20040416184541.GK87362@nasby.net> References: <20040416154502.GF87362@nasby.net> <450.1082133251@sss.pgh.pa.us> <20040416164644.GH87362@nasby.net> <808.1082135098@sss.pgh.pa.us> <20040416172523.GJ87362@nasby.net> <1263.1082138383@sss.pgh.pa.us> <20040416184541.GK87362@nasby.net> Comments: In-reply-to "Jim C. Nasby" message dated "Fri, 16 Apr 2004 13:45:41 -0500" Date: Sat, 17 Apr 2004 12:08:15 -0400 Message-ID: <10603.1082218095@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/236 X-Sequence-Number: 6536 [ resending because I fat-fingered the cc: to the list ] I see the problem: all the entries in your work_units column have the low 32 bits equal to zero. regression=# select distinct work_units % (2^32)::bigint from Trank_work_overall; ?column? ---------- 0 (1 row) The hash function for int8 only takes the low word into account, so all of the entries end up on the same hash chain, resulting in worst-case behavior. This applies to both your hash join and hash aggregate cases. We could change the hash function, perhaps, but then we'd just have different cases where there's a problem ... hashing will always fail on *some* set of inputs. (Also, I have been harboring some notions of supporting cross-type hash joins for integer types, which will not work unless small int8 values hash the same as int4 etc.) I guess the real issue is why are you encoding work_units like that? regards, tom lane