Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMKnL-00079h-Vk for pgsql-bugs@arkaria.postgresql.org; Tue, 05 Dec 2017 21:30:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMKnL-0002GS-1M for pgsql-bugs@arkaria.postgresql.org; Tue, 05 Dec 2017 21:30:27 +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 1eMKnK-0002GI-S3 for pgsql-bugs@lists.postgresql.org; Tue, 05 Dec 2017 21:30:26 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eMKnH-00030s-Hb for pgsql-bugs@postgresql.org; Tue, 05 Dec 2017 21:30:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vB5LUG4F029107; Tue, 5 Dec 2017 16:30:16 -0500 From: Tom Lane To: Jan Schulz cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14948: cost overflow In-reply-to: References: <20171205105924.27108.93509@wrigleys.postgresql.org> <28067.1512486620@sss.pgh.pa.us> Comments: In-reply-to Jan Schulz message dated "Tue, 05 Dec 2017 18:48:42 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29105.1512509416.1@sss.pgh.pa.us> Date: Tue, 05 Dec 2017 16:30:16 -0500 Message-ID: <29106.1512509416@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jan Schulz writes: > On 5 December 2017 at 16:10, Tom Lane wrote: >> Can you get a similarly broken plan if you try something involving just >> this table, say "select * from converting_touchpoints_attribution where >> touchpoint_fk = 42 and performance_attribution_model_fk = 2" ? > EXPLAIN ( ANALYSE, BUFFERS ) > select * from m_dim.converting_touchpoints_attribution where > touchpoint_fk = 42 and performance_attribution_model_fk = 2 > Bitmap Heap Scan on converting_touchpoints_attribution > (cost=-25769803761.69..-25769803757.67 rows=1 width=16) (actual > time=0.005..0.005 rows=0 loops=1) > Recheck Cond: ((performance_attribution_model_fk = 2) AND (touchpoint_fk > = 42)) > -> BitmapAnd (cost=-25769803761.69..-25769803761.69 rows=1 width=0) > (actual time=0.004..0.004 rows=0 loops=1) > -> Bitmap Index Scan on > converting_touchpoints_attribution__performance_attribution_mod > (cost=0.00..-12884901880.97 rows=1 width=0) (actual > time=0.003..0.003 rows=0 loops=1) > Index Cond: (performance_attribution_model_fk = 2) > -> Bitmap Index Scan on > converting_touchpoints_attribution__touchpoint_fk > (cost=0.00..-12884901880.97 rows=1 width=0) (never executed) > Index Cond: (touchpoint_fk = 42) > Planning time: 0.122 ms > Execution time: 0.036 ms Hmph. That just raises even more questions --- for instance, why is the condition (performance_attribution_model_fk = 2) now estimated to select just 1 row, when previously it was estimated to select 1850 rows? Still, the fact that you can get a silly answer with just one table does eliminate some theories I'd been toying with. The index cost estimation code does have some potential for garbage-in-garbage-out results, but nothing very promising. One question is whether these indexes are on a non-default tablespace with a non-default random_page_cost. PG should prevent you from putting in a negative random_page_cost, but it's worth checking that. I looked at some other possibilities like a corrupted tree_height value, but none of them seem to fit the available info. For instance, the tree_height is only an int, so even if it were the max negative value it would not explain the cost value you're getting. Don't suppose you'd like to step through btcostestimate() with a debugger and see where it's going off the rails? regards, tom lane