Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gtZfy-0008DA-Hh for pgsql-performance@arkaria.postgresql.org; Tue, 12 Feb 2019 15:08:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gtZfv-0001ef-5s for pgsql-performance@arkaria.postgresql.org; Tue, 12 Feb 2019 15:08:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gtZfu-0001eX-Qx for pgsql-performance@lists.postgresql.org; Tue, 12 Feb 2019 15:08:42 +0000 Received: from mout.kundenserver.de ([212.227.126.134]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gtZfi-0003L6-VN for pgsql-performance@lists.postgresql.org; Tue, 12 Feb 2019 15:08:41 +0000 Received: from [10.8.0.101] ([185.40.248.10]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.129]) with ESMTPSA (Nemesis) id 1MVMuN-1gTu2P32Qh-00SMBZ for ; Tue, 12 Feb 2019 16:08:26 +0100 X-Mozilla-News-Host: news://news.gmane.org:119 From: Thomas Kellerer Subject: Bloom index cost model seems to be wrong To: pgsql-performance@lists.postgresql.org Message-ID: Date: Tue, 12 Feb 2019 16:08:25 +0100 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:rI+dkkqyCvEZjv3Ck1O7xnPQbOphQe9UBTZP59rKZ/C3GmW1w5Y Kj6d8gWpYmtk50s8BiVdF9KHHYLw6xTiqNsD4wKM+Frhm24iu/6m+91y9UOCpyCzqKXb8Oc qqG+SVSNSyD7z3cp1FpcXnqNx/w4puB/4nQTU35yJ4jlSW0a7JbQMFlKPuGnAi03OvnDgqu pbt/SHM2u4XoN6/glsSTg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:4Jfotbf6KYc=:U5ShYvPoh4jtcui6fnWHRT mUm/k0rejtJdVBPNevUqZdzKQk1jFjEC8jti6M36zROYvriY8Gwy9ACIn0+Z8GMJKYuX4irQO 8p9fCLnzBwUoxBHPVUmHcqLvIl1miuGk8J4nGJ1vmY+xjbaw5sW0gDCFcaoHRgUGVltgavahx Euui6HChztsNqchQd22LQsdHb2aniMpoegkddLmRyGGpFwOd+Y7FwUnqysXCZns30yOk78zfm +hHLm1efCcfmBct0b3WZJSPuX4KVDQZ9Yh7xDnSxh1VVxZwbSkqY2EcBa7qsidvbssXQUsOSS y70QgwPghnSSzyZVvUEr48apyzpOk4Vhpyg5RfM2BY2Z1kCdGAAILaxWGth9YhC55PV4vjAjP hq2nGf3FdOV/0grUI2UyhigiBTahKee8gMu7BuzgowjtLexxnerraH7qAWYJumz+rS5km80/T 09bsbsvtcTFUeYUupBHI4aCg4SeFG/6uztPj1+M4rI9Ab7GpTXsZzB2xEhX2l2jbQKanamDih O5CZpU7bmMAF6x5sMDcNC3ISkjfPfhD1wrTqdiziaXVHk4bysnknn9qbmhSGfG8ZiIQAjm4Kj ULbw2fe9AskgwILrrXpCaXHTg1PMImMn82uABlmKcasBnpRcDSaKNmPNEVdOYvAMFDNdrLsny Ztnq7ZznqbSNU1nAZNSeBksse6fps0hLFBQBXZ7CJi5pK9HgrV+7NEXwSw6NxRC/hdbzq/xI6 eWatwHeIecjBfjCbVNTBOKOCDTg7ryQEtnWgVsaPRR2kn5qNnlODFPr0tYw= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I stumbled upon this question: https://dba.stackexchange.com/questions/229413 in a nutshell: the bloom index is not used with the example from the manual. The bloom index is only used if either Seq Scan is disabled or if the random_page_cost is set to 1 (anything about 1 triggers a Seq Scan on my Windows laptop). If parallel execution is disabled, then the bloom index is only used if the random_page_cost is lower than 4. This does not use the index: set random_page_cost = 4; set max_parallel_workers_per_gather=0; explain (analyze, buffers) select * from tbloom where i2 = 898732 and i5 = 123451; This uses the bloom index: set random_page_cost = 3.5; set max_parallel_workers_per_gather=0; explain (analyze, buffers) select * from tbloom where i2 = 898732 and i5 = 123451; And this uses the index also: set random_page_cost = 1; explain (analyze, buffers) select * from tbloom where i2 = 898732 and i5 = 123451; This is the plan with when the index is used (either through "enable_seqscan = off" or "random_page_cost = 1") Bitmap Heap Scan on tbloom (cost=138436.69..138440.70 rows=1 width=24) (actual time=42.444..42.444 rows=0 loops=1) Recheck Cond: ((i2 = 898732) AND (i5 = 123451)) Rows Removed by Index Recheck: 2400 Heap Blocks: exact=2365 Buffers: shared hit=21973 -> Bitmap Index Scan on bloomidx (cost=0.00..138436.69 rows=1 width=0) (actual time=40.756..40.756 rows=2400 loops=1) Index Cond: ((i2 = 898732) AND (i5 = 123451)) Buffers: shared hit=19608 Planning Time: 0.075 ms Execution Time: 42.531 ms And this is the plan when everything left at default settings: Seq Scan on tbloom (cost=0.00..133695.80 rows=1 width=24) (actual time=1220.116..1220.116 rows=0 loops=1) Filter: ((i2 = 898732) AND (i5 = 123451)) Rows Removed by Filter: 10000000 Buffers: shared hit=4697 read=58998 I/O Timings: read=354.670 Planning Time: 0.075 ms Execution Time: 1220.144 ms Can this be considered a bug in the cost model of the bloom index implementation? Or is it expected that this is only used if random access is really cheap? Thomas