From: Tom Lane <tgl@sss.pgh.pa.us>
To: James Cloos <cloos@jhcloos.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Optimizing a query
Date: Wed, 13 Dec 2006 16:48:47 -0500
Message-ID: <11990.1166046527@sss.pgh.pa.us> (raw)
In-Reply-To: <m31wn3lji6.fsf@lugabout.jhcloos.org>
References: <m31wn3lji6.fsf@lugabout.jhcloos.org>
James Cloos <cloos@jhcloos.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, cloos@jhcloos.com
Subject: Re: Optimizing a query
In-Reply-To: <11990.1166046527@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox