Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bqOuM-0006be-DV for pgsql-hackers@arkaria.postgresql.org; Sat, 01 Oct 2016 18:21:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bqOuL-0007AJ-AI for pgsql-hackers@arkaria.postgresql.org; Sat, 01 Oct 2016 18:21:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bqOso-0005RO-HE for pgsql-hackers@postgresql.org; Sat, 01 Oct 2016 18:19:34 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bqOsg-0000TM-1B for pgsql-hackers@postgresql.org; Sat, 01 Oct 2016 18:19:33 +0000 Received: by mail-wm0-x22d.google.com with SMTP id b201so8690367wmb.0 for ; Sat, 01 Oct 2016 11:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=m8xrgIBix1dVJ7EtW49RCgOaYxQtad070+vFdjNBJSk=; b=gBMXXcdiR4EhNJViRG9u8N3I1NzJqTnumrEo8bRpZxYgXq5qNeLVI5ZjDbD8dGPO6k iiaKtA3WnkSkFZsQPfu0AzUMVyy764pCkt5cN4/nzYgULlmxOJchd22GXujeTwsjtSHS DEY8SabzzRtXhqEpQvQqTqoqM4rZjsVQhenJ3PiR6tBq7EmqeTVisASw/2k5Ba6QRZ1h UAIpDlVC85ImzpF4cjUlFJu7DyjK1LROiIhjqNrj7dTrxduFa91pLziGPIatkVLv0VPI NwSmjAi6I7paoXuyef1NQ8axW/6wmdXXAk6MkK58AywC+3wivnfGEbV5HjlQH5RSK8TC YMUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=m8xrgIBix1dVJ7EtW49RCgOaYxQtad070+vFdjNBJSk=; b=EvnoIfSPoD48lMtoYgZAACGcTu2PgkXC7dFWnx6dByafhqO/2IigcWq2ZdgkECFeCB Grx0LsZ/TT3+DzNwFpEE294O6Urp1FSenmx9nLlb1Z8m+2+9iLFtLATEFGtTJ/phtJnf uTtr+qm5noSIW2n0jQLqM8elMdA+GEhgmjVuwANQoD6ynRVq7DhtXPHtWnOpp735Nl3K e0LUrXVYc3S/N1pqRLYyNnsetnbLo19vxTRHKQHLEvgHBzcU0x0Sg+FDS2ZmJh1CecP1 BX9eiwvNS2WHDU1PMbOMzcWAUXGG5PWCyazyEsaYLxkBYUrcUSPv7WAr2E25OyCkCiTi xp0w== X-Gm-Message-State: AA6/9RmPdaWV68GTKE+DI8QwOa7s9YaOtB1nGmyUYwBwT6R6ABth1T7AAU9Z9IjgixRYB5i5YmJWsHnKHCwfPghdT3+I68mU56MWq86edNEL3fkcWgAppzL5kC4AAg2AnDyDlx+2BXSK0eKPnMQwyrNFMPRueaqmyLNhC0WcRRUMeaKelXTVjs52/Rql8goMpKLbjxpjvawy X-Received: by 10.194.246.166 with SMTP id xx6mr11444901wjc.149.1475345964364; Sat, 01 Oct 2016 11:19:24 -0700 (PDT) Received: from [10.137.2.17] (ip-89-177-44-58.net.upcbroadband.cz. [89.177.44.58]) by smtp.gmail.com with ESMTPSA id x124sm10291891wmf.22.2016.10.01.11.19.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Oct 2016 11:19:23 -0700 (PDT) Subject: Re: Macro customizable hashtable / bitmapscan & aggregation perf To: pgsql-hackers@postgresql.org References: <20160727004333.r3e2k2y6fvk2ntup@alap3.anarazel.de> <20161001004454.4wkqbmu67spvc3ak@alap3.anarazel.de> From: Tomas Vondra Message-ID: <41a178d4-a599-60e6-1657-e2489508858a@2ndquadrant.com> Date: Sat, 1 Oct 2016 20:19:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Thunderbird/46.0a2 MIME-Version: 1.0 In-Reply-To: <20161001004454.4wkqbmu67spvc3ak@alap3.anarazel.de> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 10/01/2016 02:44 AM, Andres Freund wrote: > Hi, > > On 2016-07-26 17:43:33 -0700, Andres Freund wrote: >> In the attached patch I've attached simplehash.h, which can be >> customized by a bunch of macros, before being inlined. There's also a >> patch using this for tidbitmap.c and nodeAgg/nodeSubplan/... via >> execGrouping.c. > > Attached is a significantly improved version of this series. The main > changes are: > > - The hash table now uses robin-hood style hash collision handling. See the > commit message of 0002 (or simplehash.h) for an introduction. That > significantly reduces the impact of "clustering" due to linear > addressing. Interesting. Have you looked at cuckoo hashing? That seems to be the go-to hashing in several database-related papers I've read recently, so I guess there's a reason for that (IIRC it has constant worst case for lookups, constant amortized time for inserts/deletes). Not sure how it compares to robin-hood hashing regarding cache-friendliness though. > - Significant comment and correctness fixes, both in simplehash.h > - itself, and 0003/0004. > - a lot of other random performance improvements for the hashing code. > > > Unfortunately I'm running out battery right now, so I don't want to > re-run the benchmarks posted upthread (loading takes a while). But the > last time I ran them all the results after the patches were better than > before. > Well, I have rather bad experience with running benchmarks on laptops anyway - a lot of noise due to power management, etc. What about running a bigger benchmark - say, TPC-DS - and evaluating the impact? I think a crucial part of the benchmarking will be identifying and measuring corner cases, e.g. a lot of rows with the same key, etc. Although that probably is not a major issue for the two places switched to the new implementation (e.g. execGrouping merges the duplicates to a single group, by definition). > > This patch series currently consists out of four patches: > - 0001 - add unlikely/likely() macros. The use here is not entirely > mandatory, but they do provide a quite consistent improvement. There > are other threads where they proved to be beneficial, so I see little > reason not to introduce them. > - 0002 - the customizable hashtable itself. It now contains documentation. > - 0003 - convert tidbitmap.c to use the new hashmap. This includes a fix > for the issue mentioned in [1], to improve peformance in heavily lossy > scenarios (otherwise we could regress in some extreme cases) > - 0004 - convert execGrouping.c, e.g. used by hash aggregates > > > While not quite perfect yet, I do think this is at a state where input > is needed. I don't want to go a lot deeper into this rabbit hole, > before we have some agreement that this is a sensible course of action. > So, is it the right time to do some benchmarking? > > I think there's several possible additional users of simplehash.h, > e.g. catcache.c - which has an open coded, not particularly fast hash > table and frequently shows up in profiles - but I think the above two > conversions are plenty to start with. > regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers