Re: Index doesn't appear to be working. - Mailing list pgsql-general

From Thomas Lockhart
Subject Re: Index doesn't appear to be working.
Date
Msg-id 3C876F9D.6F3DA3B9@fourpalms.org
Whole thread Raw
In response to Index doesn't appear to be working.  ("John Oakes" <john@networkproductions.net>)
List pgsql-general
> and it tells me:
> Seq Scan on one (cost=0.00..263.02 rows=5613 width=56)
> Shouldn't it tell me
> Index Scan using one_passfail_idx on one?

Only if most of the students are failing ;)

Since most entries in this table are likely to be 'P', the optimizer
correctly concludes that it would be faster to sequentially scan the
table for rows. This is likely to be the optimizer choice for any
two-value column.

If the table has only a few rows (as might be true for a single class or
for a test dataset) then the optimizer will never choose an index scan.

If the table has more than a few hundred rows then you might get an
index scan if you search for students who are failing (again, assuming
that most are not). Make sure that you "vacuum analyze" after populating
the table to get correct statistics.

                      - Thomas

pgsql-general by date:

Previous
From: Hubert Palme
Date:
Subject: PL/pgSQL Syntax Problem
Next
From: "Randy Widell"
Date:
Subject: PostgreSQL under Cygwin...