Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aDVpE-0007YS-B0 for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Dec 2015 11:18:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aDVpD-00059N-TL for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Dec 2015 11:18:51 +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) (envelope-from ) id 1aDVp6-0004vQ-Vq for pgsql-hackers@postgresql.org; Mon, 28 Dec 2015 11:18:45 +0000 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aDVp2-000198-WB for pgsql-hackers@postgresql.org; Mon, 28 Dec 2015 11:18:44 +0000 Received: by mail-wm0-x232.google.com with SMTP id f206so4298539wmf.0 for ; Mon, 28 Dec 2015 03:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-type:content-transfer-encoding; bh=o89VENzMhC/C71srpq+zed1uSlRLiKbRcO15WbMq6oA=; b=c7zb6ZjMBsXTN9P+pNYjbEyMgg5pRJaqD/B4cEECLvTRCNIX7aU6IxPL4PgTh+kqZG 7YUWJJ5ZTZZvXp13lZQdOSQK+1gT6Snp70mOKlYsjTlmeu2NuHEXkPDWfJLyPjQcx/ek JDwNTR0QQZp2u8i9H82bRybXjrdMqXPlbRMTUjySjOq2+kqRLI2/9ZrT64fzCHFTbcOp TAu4D9hQAasY8ZXCU+8YAWYNLC6tYT55Xjhecml7FgYfazmGqay8dZqnZ4U6c8Upxh74 lno6ZrNNxGVVVa1H4TG+H8GOTsGojUDGdEBfVXfN4ZMvFOYMJK63XtdOKpmz9Cewy43J EwtQ== 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:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=o89VENzMhC/C71srpq+zed1uSlRLiKbRcO15WbMq6oA=; b=m7PT/MoynAXgFjWaaevCdjocmNa9Hh14Lt6zWvR68PuZuw2Ur2yybDnQyg7o5HD0d6 UrYmvAsPx+em0H1cSO1RtgQWSUFn2R50oCd24xH9oCGc2XVHLhDGuDMSZVSOLqUEEa3R FRPbLHqDE3CyCLOHdXK1Krj5y+x3ZEzJwaQWvVAhowM/IT+h+HHL4NtkekdY8QabNP0p aiQBrzc8kCrEA0IrJeD0pt82f6lguVQ7JeLptrH0sXT6SiOaL2GBcR/ABp6i4ig8nPr4 KrgfxMxWJOLsc9AilOqU5CM6bhlY0DTH1DSr2iPzJcWRtT7kYDqXFtFRmVzvoCKfwygz mxPA== X-Gm-Message-State: ALoCoQnySSAy+AsbAzfsuSe7NqfbevL3ZMJsGLuwts0JZrZTXqCsjbUEZso/KMUoEnFszBawlycubg5cz0uzzX6bIMOqpN+7CX9phE3+QVsOGAx5X/3KBbX6Jb1SNQz1KBk5mJ2vkdPoMuDyrtYvjf7CZonUdSiXi1y+jjY1ryWtbgoPsCINkeTGLpRHjgQvR4Q6XadWWgSK5CUauujkod1hPA+GvHZlzQ== X-Received: by 10.28.86.196 with SMTP id k187mr57013615wmb.61.1451301519799; Mon, 28 Dec 2015 03:18:39 -0800 (PST) Received: from [10.137.2.14] ([151.217.228.221]) by smtp.gmail.com with ESMTPSA id p9sm963487wjy.41.2015.12.28.03.18.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Dec 2015 03:18:38 -0800 (PST) Subject: Re: WIP: bloom filter in Hash Joins with batches To: David Rowley References: <5670946E.8070705@2ndquadrant.com> <5672D617.9060601@2ndquadrant.com> <56810D8C.3020309@2ndquadrant.com> <5681127F.9080301@2ndquadrant.com> Cc: "Shulgin, Oleksandr" , PostgreSQL Hackers From: Tomas Vondra Message-ID: <56811A8C.4020607@2ndquadrant.com> Date: Mon, 28 Dec 2015 12:18:36 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; 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 12/28/2015 11:52 AM, David Rowley wrote: > On 28 December 2015 at 23:44, Tomas Vondra > wrote: > > On 12/28/2015 11:38 AM, David Rowley wrote: > > If so, then a filter with all 1 bits set should be thrown away, as > > it'll never help us, and the filter should generally become more > worthwhile as it contains a higher ratio of 0 bits vs 1 bits. Of > course we don't have a count of how many Tuples matched each bit, so > this is based on the assumption that each bit matches an equal > number > of Tuples. Are you saying this is not an assumption that we should > make? > > > Sure we should check that. All I'm saying is it has nothing to do > with the first problem described in the first part of the e-mail. > > > Okay. I was merely suggesting this method as an alternative to checking > tracking and checking the usefulness of the filter during the hash > probe. I assumed that tracking and checking the usefulness during the > hash probe won't be free, and that it may be better if we can estimate > or determine the expected usefulness of the filter before the probe > stage, and throw it away before we waste cycles using it. Consider this example: CREATE TABLE t (id INT); INSERT INTO t SELECT i FROM generate_series(1,1000000) s(i); ANALYZE; SELECT * FROM t AS t1 JOIN t AS t2 ON (t1.id = t2.id) WHERE t1.id < 10000 AND t2.id < 10000; This will be executed like this: QUERY PLAN ----------------------------------------------------------------------- Hash Join (cost=17046.26..34008.58 rows=94 width=8) Hash Cond: (t1.id = t2.id) -> Seq Scan on t t1 (cost=0.00..16925.00 rows=9701 width=4) Filter: (id < 10000) -> Hash (cost=16925.00..16925.00 rows=9701 width=4) -> Seq Scan on t t2 (cost=0.00..16925.00 rows=9701 width=4) Filter: (id < 10000) (7 rows) But of course the problem is that the two relations are (trivially) correlated, which means that in reality it works like this: QUERY PLAN --------------------------------------------------------- Hash Join (actual rows=9999 loops=1) Hash Cond: (t1.id = t2.id) -> Seq Scan on t t1 (actual rows=9999 loops=1) Filter: (id < 10000) Rows Removed by Filter: 990001 -> Hash (actual rows=9999 loops=1) Buckets: 16384 Batches: 1 Memory Usage: 480kB -> Seq Scan on t t2 (actual rows=9999 loops=1) Filter: (id < 10000) Rows Removed by Filter: 990001 Planning time: 0.316 ms Execution time: 176.283 ms (12 rows) So while we have very good estimates on the scan nodes, the final estimate is off - we expect about the bloom filter to eliminate ~99% of rows, in reality 100% of rows matches (due to the correlation). And that's even if the bloom filter is "perfect" in the sense that it has very low false probability etc. This example illustrates that such cases can't be really solved before actually doing the lookups. Which does not make the checks you propose pointless, but they simply address different cases (and I indeed planned to implement them). 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