Re: [GENERAL] int8 index isn't used for query against number - Mailing list pgsql-general

From Peter Eisentraut
Subject Re: [GENERAL] int8 index isn't used for query against number
Date
Msg-id Pine.LNX.4.20.9911022213090.356-100000@peter-e.yi.org
Whole thread Raw
In response to int8 index isn't used for query against number  (Mark Dalphin <mdalphin@amgen.com>)
List pgsql-general
On Nov 2, Mark Dalphin mentioned:

> -- Without quotes, no Index scan; very slow
> db=> EXPLAIN
> db-> SELECT FileID, Contig_Accession, ByteOffset, SeqLength FROM Seq S
> db-> WHERE Contig_Accession=6739795;
> NOTICE:  QUERY PLAN:
>
> Seq Scan on seq s  (cost=105160.20 rows=1 width=22)
>
> EXPLAIN
>

Try ... WHERE Contig_Accession = 6739795::int8. The same thing happens
with int2 I believe because integers are all assumed to be int4's and the
backend isn't too smart in that regard one could say.

> -- With quotes, index scan and almost instantaneous responce.
> db=> explain
> db-> SELECT FileID, Contig_Accession, ByteOffset, SeqLength FROM Seq S
> db-> WHERE Contig_Accession='6739795';
> NOTICE:  QUERY PLAN:
>
> Index Scan using seq_contig_accession_key on seq s  (cost=2.05 rows=1 width=22)
>
> EXPLAIN

Interesting. Perhaps the the fact that you give it a string forces it to
undertake some sort of typecast and it actually casts it to int8.

--
Peter Eisentraut                  Sernanders vaeg 10:115
peter_e@gmx.net                   75262 Uppsala
http://yi.org/peter-e/            Sweden


pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: [GENERAL] error with user
Next
From: Tyson Oswald
Date:
Subject: selecting a certain number of rows