Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 669969FA274 for ; Wed, 13 Dec 2006 17:49:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 35997-06 for ; Wed, 13 Dec 2006 17:49:43 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 6ACDF9F9F49 for ; Wed, 13 Dec 2006 17:49:46 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id kBDLmlwA011991; Wed, 13 Dec 2006 16:48:47 -0500 (EST) To: James Cloos cc: pgsql-performance@postgresql.org Subject: Re: Optimizing a query In-reply-to: References: Comments: In-reply-to James Cloos message dated "Wed, 13 Dec 2006 13:48:10 -0500" Date: Wed, 13 Dec 2006 16:48:47 -0500 Message-ID: <11990.1166046527@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/341 X-Sequence-Number: 22397 James Cloos writes: > ... and was doing queries of the form: > | select * from nanpa where npa=775 and nxx=413; If those are char(3) columns, shouldn't you be quoting the constants? select * from nanpa where npa='775' and nxx='413'; Any non-numeric input will fail entirely without the quotes, and I'm also not too confident that inputs of less than three digits will work as you expect (the blank-padding might not match what's in the table). Leading zeroes would be troublesome too. OTOH, if the keys are and always will be small integers, it's just stupid not to be storing them as integers --- integer comparison is far faster than string. Postgres' data type capabilities are exceptional. Learn to work with them, not against them --- that means thinking about what the data really is and declaring it appropriately. regards, tom lane