Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eMErh-0008Tz-F5 for pgsql-bugs@arkaria.postgresql.org; Tue, 05 Dec 2017 15:10:33 +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 1eMErf-0002SB-ON for pgsql-bugs@arkaria.postgresql.org; Tue, 05 Dec 2017 15:10:31 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eMErf-0002S1-Fp for pgsql-bugs@lists.postgresql.org; Tue, 05 Dec 2017 15:10:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eMErc-0003dS-8s for pgsql-bugs@postgresql.org; Tue, 05 Dec 2017 15:10:29 +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 vB5FAKSt028068; Tue, 5 Dec 2017 10:10:20 -0500 From: Tom Lane To: jasc@gmx.net cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14948: cost overflow In-reply-to: <20171205105924.27108.93509@wrigleys.postgresql.org> References: <20171205105924.27108.93509@wrigleys.postgresql.org> Comments: In-reply-to jasc@gmx.net message dated "Tue, 05 Dec 2017 10:59:24 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28066.1512486620.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 05 Dec 2017 10:10:20 -0500 Message-ID: <28067.1512486620@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk jasc@gmx.net writes: > We have a server which reports negative costs in a query plan: The root of the weirdness seems to be here: > -> Bitmap Heap Scan on converting_touchpoints_attribution con= v (cost=3D-2021924572970281.75..-2021924572970244.00 rows=3D1 width=3D10) = (never executed) > Recheck Cond: ((t.touchpoint_id =3D touchpoint_fk) AND (= performance_attribution_model_fk =3D 2)) > -> BitmapAnd (cost=3D-2021924572970281.75..-20219245729= 70281.75 rows=3D1850 width=3D0) (never executed) > -> Bitmap Index Scan on converting_touchpoints_at= tribution__touchpoint_fk (cost=3D0.00..-2021911688068401.00 rows=3D1850 wi= dth=3D0) (never executed) > Index Cond: (t.touchpoint_id =3D touchpoint_= fk) > -> Bitmap Index Scan on converting_touchpoints_at= tribution__performance_attribution_mod (cost=3D0.00..-12884901880.97 rows=3D= 1850 width=3D0) (never executed) > Index Cond: (performance_attribution_model_f= k =3D 2) I'm not sure what to make of that, but it seems to be broken in more ways than just the wacko cost estimates. For one thing, the planner is suppose= d to set up index qual conditions in the form "indexedvar op something", and the (t.touchpoint_id =3D touchpoint_fk) condition appears to be backwards. The row estimate at the intermediate BitmapAnd node seems to be out of line as well, why doesn't it match the estimate for the heapscan node? Can you get a similarly broken plan if you try something involving just this table, say "select * from converting_touchpoints_attribution where touchpoint_fk =3D 42 and performance_attribution_model_fk =3D 2" ? Could we see the pg_stats rows for those two columns? What is in pg_class.reltuples and relpages for this table and these two indexes? regards, tom lane