-- sql/indexes.sql
-- This file is part of Decimail; see http://decimail.org
-- (C) 2004-5 Philip Endecott
 
-- This is version $Name$
--   (if there is no version (e.g. V0-1) mentioned in the previous line,
--    this is probably a snapshot from between "official" releases.)
 
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 

drop index messages_by_owner;
drop index messages_by_date;
drop index messages_by_from_addr;
drop index messages_by_rfc822_messageid;
drop index messages_by_subject;
drop index messages_by_from_addr_domain;
drop index to_addrs_by_msg_id;
drop index cc_addrs_by_msg_id;
drop index bcc_addrs_by_msg_id;
drop index to_addrs_by_addr;
drop index cc_addrs_by_addr;
drop index bcc_addrs_by_addr;

begin;

create index messages_by_owner on messages ( owner );
create index messages_by_date on messages ( msgdate );
create index messages_by_from_addr on messages ( from_addr );
create index messages_by_rfc822_messageid on messages ( rfc822_messageid );
create index messages_by_subject on messages ( subject );
create index messages_by_from_addr_domain on messages
             (lower(split_part(from_addr,'@',2)));

create index to_addrs_by_msg_id on to_addrs ( msg_id );
create index cc_addrs_by_msg_id on cc_addrs ( msg_id );
create index bcc_addrs_by_msg_id on bcc_addrs ( msg_id );

create index to_addrs_by_addr on to_addrs ( addr );
create index cc_addrs_by_addr on cc_addrs ( addr );
create index bcc_addrs_by_addr on bcc_addrs ( addr );

end;
