Skip site navigation (1) Skip section navigation (2)

Re: Optimizing a query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: James Cloos <cloos(at)jhcloos(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Optimizing a query
Date: 2006-12-13 21:48:47
Message-ID: 11990.1166046527@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-performance
James Cloos <cloos(at)jhcloos(dot)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

In response to

pgsql-performance by date

Next:From: Tom LaneDate: 2006-12-13 21:58:55
Subject: Re: strange query behavior
Previous:From: Guido NeitzerDate: 2006-12-13 19:59:31
Subject: Re: New to PostgreSQL, performance considerations

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group