Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id D0F1A650E83 for ; Thu, 26 Jun 2008 03:24:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 70413-02 for ; Thu, 26 Jun 2008 03:24:04 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from relay-1.mail.nethere.net (relay-1.mail.nethere.net [66.63.128.161]) by postgresql.org (Postfix) with ESMTP id C7BF9650EFE for ; Thu, 26 Jun 2008 03:22:34 -0300 (ADT) Received: from scan-2.mail.nethere.net (scan-2.mail.nethere.net [66.63.128.133]) by relay-1.mail.nethere.net (Postfix) with ESMTP id D15AF291B2; Wed, 25 Jun 2008 23:22:33 -0700 (PDT) Received: from mta-1.mail.nethere.net by scan-2.mail.nethere.net with LMTP id EqEFKcAOgQuk; Wed, 25 Jun 2008 23:22:33 -0700 (PDT) Received: from lisa-james-computer.local (wsip-68-224-174-233.sd.sd.cox.net [68.224.174.233]) by mta-1.mail.nethere.net (Postfix) with ESMTP id 9783EF1814; Wed, 25 Jun 2008 23:22:33 -0700 (PDT) Message-ID: <4863359C.1040906@emolecules.com> Date: Wed, 25 Jun 2008 23:22:20 -0700 From: Craig James User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421) MIME-Version: 1.0 To: Tom Lane , pgsql-performance@postgresql.org Subject: Re: Typecast bug? References: <47FFA7FF.10801@postnewspapers.com.au> <544D07A2-EB3F-4D91-A749-0C4D5D38AB80@gmail.com> <481F992D.7070509@emolecules.com> <4820A3C2.4000307@emolecules.com> <4820C30A.8010709@emolecules.com> <4863186E.1000306@emolecules.com> <5564.1214458410@sss.pgh.pa.us> In-Reply-To: <5564.1214458410@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200806/158 X-Sequence-Number: 30508 Tom Lane wrote: > Craig James writes: >> This seems like a bug to me, but it shows up as a performance problem. > >> emol_warehouse_1=> explain analyze select version_id, parent_id from version where version_id = 999999999999999999999999999; > > If you actually *need* so many 9's here as to force it out of the range > of bigint, then why is your id column not declared numeric? > > This seems to me to be about on par with complaining that "intcol = 4.2e1" > won't be indexed. We have a numeric data type hierarchy, learn to > work with it ... Your suggestion of "learn to work with it" doesn't fly. A good design separates the database schema details from the application to the greatest extent possible. What you're suggesting is that every application that queries against a Postgres database should know the exact range of every numeric data type of every indexed column in the schema, simply because Postgres can't recognize an out-of-range numeric value. In this case, the optimizer could have instantly returned zero results with no further work, since the query was out of range for that column. This seems like a pretty simple optimization to me, and it seems like a helpful suggestion to make to this forum. BTW, this query came from throwing lots of junk at a web app in an effort to uncover exactly this sort of problem. It's not a real query, but then, hackers don't use real queries. The app checks that its input is a well-formed integer expression, but then assumes Postgres can deal with it from there. Craig