MYSQL在大数据方面明显缓慢 - 第三方应用程序

时间:2012-05-18 21:42:26

标签: mysql indexing distinct sugarcrm

联系人中的记录数:245847 团队成员团队中的记录数量:348

 mysql> explain SELECT distinct contacts.id FROM contacts INNER JOIN 
team_sets_teams tst ON tst.team_set_id = contacts.team_set_id where
 ( contacts.phone_work LIKE '%487%1864%' or contacts.phone_mobile LIKE
'%487%1864%' or  contacts.phone_other LIKE '%487%1864%' or
contacts.phone_home LIKE '%487%1864%'  )  ORDER BY
contacts.last_name LIMIT 0,11 \G;


           id: 1
  select_type: SIMPLE
        table: contacts
         type: ALL
possible_keys: team_set_id
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 245628
        Extra: Using where; Using temporary; Using filesort
*************************** 2. row ***************************
           id: 1
  select_type: SIMPLE
        table: tst
         type: ref
possible_keys: idx_ud_set_id
          key: idx_ud_set_id
      key_len: 109
          ref: db.contacts.team_set_id
         rows: 2
        Extra: Using where; Using index; Distinct
2 rows in set (0.00 sec)

现在没有明显的:

 mysql> explain SELECT distinct contacts.id FROM contacts INNER JOIN 
team_sets_teams tst ON tst.team_set_id = contacts.team_set_id where
 ( contacts.phone_work LIKE '%487%1864%' or contacts.phone_mobile LIKE
'%487%1864%' or  contacts.phone_other LIKE '%487%1864%' or
contacts.phone_home LIKE '%487%1864%'  )  ORDER BY
contacts.last_name LIMIT 0,11 \G;

           id: 1
  select_type: SIMPLE
        table: contacts
         type: index
possible_keys: team_set_id
          key: last_name
      key_len: 303
          ref: NULL
         rows: 2
        Extra: Using where
*************************** 2. row ***************************
           id: 1
  select_type: SIMPLE
        table: tst
         type: ref
possible_keys: idx_ud_set_id
          key: idx_ud_set_id
      key_len: 109
          ref: karma.contacts.team_set_id
         rows: 2
        Extra: Using where; Using index
2 rows in set (0.00 sec)

您将使用哪些字段作为索引。该查询无法更改,因为它是第三方应用程序:

小组设置

mysql> show fields from team_sets_teams;
+---------------+------------+------+-----+---------+-------+
| Field         | Type       | Null | Key | Default | Extra |
+---------------+------------+------+-----+---------+-------+
| id            | char(36)   | NO   | PRI |         |       |
| team_set_id   | char(36)   | YES  | MUL | NULL    |       |
| team_id       | char(36)   | YES  | MUL | NULL    |       |
| date_modified | datetime   | YES  |     | NULL    |       |
| deleted       | tinyint(1) | YES  | MUL | 0       |       |
+---------------+------------+------+-----+---------+-------+
5 rows in set (0.00 sec)

联系人

mysql> show fields from contacts;
+----------------------------+--------------+------+-----+---------+-------+
| Field                      | Type         | Null | Key | Default | Extra |
+----------------------------+--------------+------+-----+---------+-------+
| id                         | char(36)     | NO   | PRI | NULL    |       |
| date_entered               | datetime     | YES  | MUL | NULL    |       |
| date_modified              | datetime     | YES  | MUL | NULL    |       |
| modified_user_id           | char(36)     | YES  | MUL | NULL    |       |
| created_by                 | char(36)     | YES  | MUL | NULL    |       |
| description                | text         | YES  |     | NULL    |       |
| deleted                    | tinyint(1)   | YES  |     | 0       |       |
| assigned_user_id           | char(36)     | YES  | MUL | NULL    |       |
| team_id                    | char(36)     | YES  | MUL | NULL    |       |
| team_set_id                | char(36)     | YES  | MUL | NULL    |       |
| salutation                 | varchar(100) | YES  |     | NULL    |       |
| first_name                 | varchar(100) | YES  | MUL | NULL    |       |
| last_name                  | varchar(100) | YES  | MUL | NULL    |       |
| title                      | varchar(100) | YES  |     | NULL    |       |
| department                 | varchar(255) | YES  |     | NULL    |       |
| do_not_call                | tinyint(1)   | YES  |     | 0       |       |
| phone_home                 | varchar(100) | YES  | MUL | NULL    |       |
| phone_mobile               | varchar(100) | YES  | MUL | NULL    |       |
| phone_work                 | varchar(100) | YES  | MUL | NULL    |       |
| phone_other                | varchar(100) | YES  | MUL | NULL    |       |
| phone_fax                  | varchar(100) | YES  | MUL | NULL    |       |
| assistant                  | varchar(75)  | YES  | MUL | NULL    |       |
+----------------------------+--------------+------+-----+---------+-------+

0 个答案:

没有答案