Re: Why doesn't it use indexes?

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: "Ahti Legonkov" <lego(at)127(dot)0(dot)0(dot)1>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Why doesn't it use indexes?
Date: 2002-07-03 07:42:58
Message-ID: GNELIHDDFBOCMGBFGEFOCEOMCCAA.chriskl@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

1. ANALYZE both tables. Go 'VACUUM ANALYZE;' to vacuum and analyze your
tables. Analyzing means to update the planner statistics for the tables,
which might make Postgres use your indices.

2. If you tables are very small (eg. only a few hundred rows) then using an
index is usually slower than just scanning the table, so Postgres won't use
the index until the table grows. (So long as you regularly update the
planner statistics)

Chris

> -----Original Message-----
> From: pgsql-sql-owner(at)postgresql(dot)org
> [mailto:pgsql-sql-owner(at)postgresql(dot)org]On Behalf Of Ahti Legonkov
> Sent: Tuesday, 2 July 2002 11:47 PM
> To: pgsql-sql(at)postgresql(dot)org
> Subject: [SQL] Why doesn't it use indexes?
>
>
> Hi,
>
> I have this query:
> select * from reo inner join usr on reo.owner_id=usr.user_id
>
> I also have created these indexes:
> CREATE INDEX "owner_id_reo_key" ON reo (owner_id);
> CREATE INDEX "user_id_user_key" ON usr (user_id);
>
> Explain tells me this:
> Merge Join (cost=1341.74..1481.12 rows=299697 width=461)
> -> Sort (cost=775.05..775.05 rows=6629 width=328)
> -> Seq Scan on apartment_reo reo (cost=0.00..354.29 rows=6629
> width=328)
> -> Sort (cost=566.69..566.69 rows=4521 width=133)
> -> Seq Scan on USER usr (cost=0.00..292.21 rows=4521 width=133)
>
> Why it does not use indexes I have created?
>
> --
> Ahti Legonkov
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2002-07-03 07:51:51 Re: pg_restore cannot restore function
Previous Message Christopher Kings-Lynne 2002-07-03 07:02:37 Re: constraint