Results 1 to 4 of 4

Thread: Help with a custom index

  1. #1
    stevec is offline Sugar Community Member
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,100

    Default Help with a custom index

    Hi,

    Just wondering if any mysql gurus can help with an index on the emails table. Ours is huge and emails listview can take a good 20 seconds. Slow query logging shows the query:

    Code:
    SELECT DISTINCT emails.*, users.user_name as assigned_user_name  FROM emails  LEFT JOIN teams ON emails.team_id=teams.id LEFT JOIN users ON emails.assigned_user_id=users.id WHERE  emails.deleted=0  ORDER BY date_sent DESC LIMIT 60,21;
    using mysql EXPLAIN it gives:

    Code:
    +----+-------------+--------+--------+---------------+---------+---------+----------------------------------+--------+----------------------------------------------+
    | id | select_type | table  | type   | possible_keys | key     | key_len | ref                              | rows   | Extra                                        |
    +----+-------------+--------+--------+---------------+---------+---------+----------------------------------+--------+----------------------------------------------+
    |  1 | SIMPLE      | emails | ALL    | NULL          | NULL    | NULL    | NULL                             | 477583 | Using where; Using temporary; Using filesort |
    |  1 | SIMPLE      | teams  | eq_ref | PRIMARY       | PRIMARY | 108     | sugarcrm.emails.team_id          |      1 | Using index                                  |
    |  1 | SIMPLE      | users  | eq_ref | PRIMARY       | PRIMARY | 108     | sugarcrm.emails.assigned_user_id |      1 |                                              |
    +----+-------------+--------+--------+---------------+---------+---------+----------------------------------+--------+----------------------------------------------+
    and current indicies are:

    Code:
    +--------+------------+-----------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+
    | Table  | Non_unique | Key_name              | Seq_in_index | Column_name      | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
    +--------+------------+-----------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+
    | emails |          0 | PRIMARY               |            1 | id               | A         |      479207 |     NULL | NULL   |      | BTREE      | NULL    |
    | emails |          1 | idx_email_name        |            1 | name             | A         |      479207 |     NULL | NULL   | YES  | BTREE      | NULL    |
    | emails |          1 | idx_email_parent_id   |            1 | parent_id        | A         |       28188 |     NULL | NULL   | YES  | BTREE      | NULL    |
    | emails |          1 | idx_email_team_status |            1 | team_id          | A         |          18 |     NULL | NULL   | YES  | BTREE      | NULL    |
    | emails |          1 | idx_email_team_status |            2 | status           | A         |          18 |     NULL | NULL   | YES  | BTREE      | NULL    |
    | emails |          1 | idx_email_assigned    |            1 | assigned_user_id | A         |          18 |     NULL | NULL   | YES  | BTREE      | NULL    |
    | emails |          1 | idx_email_assigned    |            2 | type             | A         |          18 |     NULL | NULL   | YES  | BTREE      | NULL    |
    | emails |          1 | idx_email_assigned    |            3 | status           | A         |          18 |     NULL | NULL   | YES  | BTREE      | NULL    |
    | emails |          1 | idx_emails_date_cstm  |            1 | date_modified    | A         |      479207 |     NULL | NULL   |      | BTREE      | NULL    |
    | emails |          1 | idx_message_id        |            1 | message_id       | A         |      479207 |     NULL | NULL   | YES  | BTREE      | NULL    |
    +--------+------------+-----------------------+--------------+------------------+-----------+-------------+----------+--------+------+------------+---------+
    Any thoughts on what index(es) to add that would help with the emails table?

    Thanks

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Help with a custom index

    Hi Stevec

    Try add new indexes:
    date_start, time_start, parent_type, mailbox_id, date_sent

    Remember adding new indexes will cause more memory usage.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    stevec is offline Sugar Community Member
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,100

    Default Re: Help with a custom index

    Will do - but there is no date_start and time_start fields in emails.

    Thanks

  4. #4
    stevec is offline Sugar Community Member
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,100

    Default Re: Help with a custom index

    I added all the other indices but the main query is still using temporary tables and file sorts. maybe it's the size of the result set that's forcing it to disc?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How do you Re - Index???
    By asieljason in forum Help
    Replies: 0
    Last Post: 2009-01-23, 05:11 PM
  2. Replies: 3
    Last Post: 2008-07-23, 07:09 AM
  3. How to index a field in a custom table
    By gregwatson in forum Developer Help
    Replies: 0
    Last Post: 2008-05-29, 03:53 PM
  4. Index.php help
    By jcollier in forum Help
    Replies: 2
    Last Post: 2006-09-12, 02:14 PM
  5. Urgente !!! index.php
    By psiclari in forum Italiano
    Replies: 0
    Last Post: 2006-03-15, 10:23 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •