Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 15A001337BE4 for ; Tue, 8 Feb 2011 18:05:17 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 36491-08-3 for ; Tue, 8 Feb 2011 22:05:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from outmail148153.authsmtp.net (outmail148153.authsmtp.net [62.13.148.153]) by mail.postgresql.org (Postfix) with ESMTP id 0737B1337BD8 for ; Tue, 8 Feb 2011 18:05:08 -0400 (AST) Received: from mail-c194.authsmtp.com (mail-c194.authsmtp.com [62.13.128.121]) by punt10.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id p18M54KY064390; Tue, 8 Feb 2011 22:05:04 GMT Received: from Sidney-Stratton.local (dsl081-245-111.sfo1.dsl.speakeasy.net [64.81.245.111]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2) with ESMTP id p18M50QC060937; Tue, 8 Feb 2011 22:05:01 GMT Message-ID: <4D51BE0B.1060404@agliodbs.com> Date: Tue, 08 Feb 2011 14:04:59 -0800 From: Josh Berkus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20090223 Thunderbird/3.0b2 MIME-Version: 1.0 To: Laszlo Nagy CC: pgsql-performance@postgresql.org, Daniel Fekete Subject: Re: Bad query plan when the wrong data type is used References: <4D514FFF.9060308@shopzeus.com> In-Reply-To: <4D514FFF.9060308@shopzeus.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Server-Quench: 79f9d885-33cf-11e0-80b9-0022640b883e X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdyZgscClZXSx8a IioLCC5HRQ8+YBZL BAkGMA9GIUINWEQK c1ACfh19PVdbHwkA AnYJWV5UVVdxWC1z bxRZbBtfZk9QXgRr T0pMQFdNFEsoABR8 Ax5/IRl0dwxFfzB0 bERrEHdSCk0ufU54 X01XRjsbZGY1aH0X UBJRagNUcgFMeh8X Ylh8AT1vNG8XDRoV JSEUBRUEdR9WJGxM XwwXPBoKRU8NViE8 ShZKATUiVVIfQCM8 ZxAvNldUAFcJPw0z KhM8Ql8UWwAB X-Authentic-SMTP: 61633136333939.1015:706 X-AuthFastPath: 0 (Was 255) X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201102/318 X-Sequence-Number: 42456 Laszlo, > Which is silly. I think that PostgreSQL converts the int side to a > float, and then compares them. > > It would be better to do this, for each item in the loop: > > * evaluate the right side (which is float) > * tell if it is an integer or not > * if not an integer, then discard the row immediately > * otherwise use its integer value for the index scan Not terribly likely, I'm afraid. Data type coercion is *way* more complex than you realize (consider the number of data types we have, and the ability to add UDTs, and then square it). And the functionality you propose would break backwards compatibility; many people currently use ".0" currently in order to force a coercion to Float or Numeric. I'm not saying that PostgreSQL couldn't do better on this kind of case, but that doing better is a major project, not a minor one. -- -- Josh Berkus PostgreSQL Experts Inc. http://www.pgexperts.com