List Info

Thread: maia_mail_recipients_idx_mail_id redundant?




maia_mail_recipients_idx_mail_id redundant?
country flaguser name
Finland
2008-02-27 03:58:49
I was going through the maia database and noticed index in
maia_mail_recipients that I think is redundant and could be
removed.


maia=# d maia_mail_recipients
                                 Table
"public.maia_mail_recipients"
    Column    |     Type      | Modifiers
--------------+---------------+-----------
 mail_id      | integer       | not null
 recipient_id | integer       | not null
 type         | character(1)  | not null
 token        | character(64) | not null
Indexes:
    "maia_mail_recipients_pkey" PRIMARY KEY, btree
(mail_id, recipient_id)
    "maia_mail_recipients_idx_mail_id" btree
(mail_id)
    "maia_mail_recipients_idx_recipient_id" btree
(recipient_id)
    "maia_mail_recipients_idx_type" btree
("type")
    "token_idx" btree (token)

At least in PostgreSQL mail_id is already indexed first in
the primary
key index, so there should be no need to have another index
for it.
maia_mail_recipients_idx_mail_id index is used, but removing
it makes
Postgres use the primary key index.

maia=# EXPLAIN select mail_id from maia_mail_recipients
where mail_id = 1;
QUERY PLAN
------------------------------------------------------------
-----------
 Index Scan using maia_mail_recipients_idx_mail_id on
maia_mail_recipients  (cost=0.00..16.22 rows=3 width=4)
   Index Cond: (mail_id = 1)
(2 rows)

maia=# drop INDEX maia_mail_recipients_idx_mail_id;
DROP INDEX
maia=# EXPLAIN select mail_id from maia_mail_recipients
where mail_id = 1;
QUERY PLAN
------------------------------------------------------------
-----------
 Index Scan using maia_mail_recipients_pkey on
maia_mail_recipients
(cost=0.00..16.29 rows=3 width=4)
   Index Cond: (mail_id = 1)
(2 rows)


maia_mail_recipients table can grow quite large, so I think
having fewer
indexes might result in better performance.
_______________________________________________
Maia-users mailing list
Maia-usersrenaissoft.com
http://www.renaissoft.com/mailman/listinfo/maia-users

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )