pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Index usage
3+ messages / 3 participants
[nested] [flat]

* Index usage
@ 2001-06-09 03:27 Subra Radhakrishnan <subra100@yahoo.com>
  2001-06-09 03:39 ` Re: Index usage Stephan Szabo <sszabo@megazone23.bigpanda.com>
  2001-06-09 16:21 ` Re: Index usage Peter Eisentraut <peter_e@gmx.net>
  0 siblings, 2 replies; 3+ messages in thread

From: Subra Radhakrishnan @ 2001-06-09 03:27 UTC (permalink / raw)
  To: pgsql-sql

Hi All,

The index created by me is not being used while doing
select. I found that out by using the EXPLAIN. For
example:

Table department has 
----------------
dept_num
dept_desc


Table 'employee' looks like this:
--------------------------------
emp_num primary key,
emp_name,
dept_num (this is by way of foreign key relation from
department table)

Now, I create an index on the employee table using
'dept_num' as the attribute. And when I run select
which looks like:

Explain Select * from employee where dept_num =
'Finance';

It does not use the index and tells me that a
Sequential scan will be done on the table employee.

How do I fix this? 

Thanx in advance,

Subra

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Index usage
  2001-06-09 03:27 Index usage Subra Radhakrishnan <subra100@yahoo.com>
@ 2001-06-09 03:39 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Stephan Szabo @ 2001-06-09 03:39 UTC (permalink / raw)
  To: Subra Radhakrishnan <subra100@yahoo.com>; +Cc: pgsql-sql

On Fri, 8 Jun 2001, Subra Radhakrishnan wrote:

> Hi All,
> 
> The index created by me is not being used while doing
> select. I found that out by using the EXPLAIN. For
> example:
> 
> Table department has 
> ----------------
> dept_num
> dept_desc
> 
> 
> Table 'employee' looks like this:
> --------------------------------
> emp_num primary key,
> emp_name,
> dept_num (this is by way of foreign key relation from
> department table)
> 
> Now, I create an index on the employee table using
> 'dept_num' as the attribute. And when I run select
> which looks like:
> 
> Explain Select * from employee where dept_num =
> 'Finance';
> 
> It does not use the index and tells me that a
> Sequential scan will be done on the table employee.
> 
> How do I fix this? 

Have you run vacuum analyze, what's the full schema
(with types) and the explain output?





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Index usage
  2001-06-09 03:27 Index usage Subra Radhakrishnan <subra100@yahoo.com>
@ 2001-06-09 16:21 ` Peter Eisentraut <peter_e@gmx.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Peter Eisentraut @ 2001-06-09 16:21 UTC (permalink / raw)
  To: Subra Radhakrishnan <subra100@yahoo.com>; +Cc: pgsql-sql

Subra Radhakrishnan writes:

> Now, I create an index on the employee table using
> 'dept_num' as the attribute. And when I run select
> which looks like:
>
> Explain Select * from employee where dept_num =
> 'Finance';
>
> It does not use the index and tells me that a
> Sequential scan will be done on the table employee.
>
> How do I fix this?

Unless you can prove that an index scan is going to be faster than a
sequential scan, you don't.  Just because there's an index doesn't mean
it's always the best choice to use it.

-- 
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-06-09 16:21 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-09 03:27 Index usage Subra Radhakrishnan <subra100@yahoo.com>
2001-06-09 03:39 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>
2001-06-09 16:21 ` Peter Eisentraut <peter_e@gmx.net>

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