Index not used. WHY?
От | Andrei Bintintan |
---|---|
Тема | Index not used. WHY? |
Дата | |
Msg-id | 014901c3ba76$ffd65650$0b00a8c0@andy обсуждение исходный текст |
Ответы |
Re: Index not used. WHY?
|
Список | pgsql-admin |
Hi,
I have the following table:
CREATE
TABLE public.rights (id int4 DEFAULT nextval('"rights_id_seq"'::text) NOT NULL,
id_user int4 NOT NULL,
id_modull int4 NOT NULL,
CONSTRAINT rights_pkey PRIMARY KEY (id)
)
and I created the following indexes:
CREATE INDEX right_id_modull_idx ON rights USING btree (id_modull);
CREATE INDEX right_id_user_idx ON rights USING btree (id_user);
Now the problem: EXPLAIN SELECT EXPLAIN SELECT
returnes:
Seq Scan on rights r (cost=0.00..12.30 rows=42 width=12)
Filter: (id_modull = 15)
returnes:
Index Scan using right_id_user_idx on rights r (cost=0.00..8.35 rows=11 width=12)
Index Cond: (id_user = 15)
Question: Why the right_id_modull_idx is NOT USED at the 1st query and the second query the right_id_user_idx index is used.
I don't understand this.
Thanx in advance.
Andy.
В списке pgsql-admin по дате отправления: