Re: Non-unique index performance

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: Sezai YILMAZ <sezai(dot)yilmaz(at)pro-g(dot)com(dot)tr>, pgsql-general(at)postgresql(dot)org
Subject: Re: Non-unique index performance
Date: 2005-06-24 14:39:28
Message-ID: 20050624143928.GB6779@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jun 24, 2005 at 11:23:54AM +0100, Richard Huxton wrote:
> >I qouted them to use indexes. The other method is type casting the
> >values to indexed column type. I prefer the quoting method.
>
> Sorry - this is just plain wrong.
>
> If you had an int8 column and a value such as 17, then PG looked at 17
> and said Ha! an int4. Then it would not use your index. In such cases
> you could either cast the value to int8, or quote it (so that the
> planner decided its type later in the process).
>
> This was never required if you had a value that was large enough to be
> int8 but not int4, nor when the column was int4. It is not an issue at
> all as of version 8.0.
>
> So - if the column is a plain old int4 - just do things normally.

Well, I'd have to disagree. If you're handcrafting every query and you
know the types of every column and you're confident they're not going
to change, then yes, you could leave off the quotes.

OTOH, if you want to be consistant, or you can't be sure your caller
passed the right type or you just don't know anything about the table
or function you're using, quoting is a simple effective method to make
sure you get it right. It costs nothing and is a hell of a lot easier.

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Scott Marlowe 2005-06-24 14:45:15 Re: problem calling psql from another program
Previous Message Michael Fuhr 2005-06-24 14:19:35 Re: fields and foreign keys