Re: [GENERAL] Basic question about indexes (6.5.2)

From: "Aaron J(dot) Seigo" <aaron(at)gtv(dot)ca>
To: "Alain TESIO" <tesio(at)easynet(dot)fr>, <pgsql-general(at)postgreSQL(dot)org>
Subject: Re: [GENERAL] Basic question about indexes (6.5.2)
Date: 1999-11-16 00:34:02
Message-ID: 99111517383005.15505@stilborne
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi...

On Mon, 15 Nov 1999, Alain TESIO wrote:
> create table T1 ( x int );
> create table T2 ( y int );
> < insert from 1 to 1000 in T1 and T2>
> create index idx_t1 on T1 ( x );
> create index idx_t2 on T2 ( y );
> explain select T1.x from T1,T2 where T1.x=T2.y;

instead try:

explain select T1.x from T1,T2 where T1.x=T2.y::int;

NOTICE: QUERY PLAN:

Nested Loop (cost=2093.00 rows=100001 width=8)
-> Seq Scan on t2 (cost=43.00 rows=1000 width=4)
-> Index Scan using idx_t1 on t1 (cost=2.05 rows=1000 width=4)

EXPLAIN

the reason for this is that unless the input is specifically known to be of the
right type (and it almost never does unless you force a typecast) it won't use
the index(es) available.

--
Aaron J. Seigo
Sys Admin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jason Leach 1999-11-16 03:29:05 Debian PKG.
Previous Message Alain TESIO 1999-11-16 00:20:52 Using functions with indexes