2017-01-08 6 views
3

최근에 작성된 복합 색인을 사용하지 않는 갱신 조회/조회 계획은 다음과 같습니다. 설명에 따르면 radacctupdate이라는 복합 인덱스를 사용하지 않으면 업데이트 쿼리를 더 빨리 수행 할 수 있다고합니다. 테이블에는 다른 쿼리에서 사용되는 다른 인덱스가 있습니다.mysql UPDATE 쿼리가 인덱스를 사용하도록 강제하는 방법은 무엇입니까? 어떻게 강제로 대신 자동으로 색인을 사용 mysql 엔진을 활성화하려면?

EXPLAIN UPDATE radacct SET acctstoptime = '2017-01-08 11:52:24', 
acctsessiontime = unix_timestamp('2017-01-08 11:52:24') - unix_timestamp(acctstarttime), 
acctterminatecause = '', acctstopdelay = 14855646 
WHERE acctstoptime IS NULL AND 
nasipaddress = '102.34.56.234' AND acctstarttime <= '2017-01-08 11:52:24'; 

************* 1. row *********** 
      id: 1 
    select_type: SIMPLE 
     table: radacct 
     type: range 
possible_keys: acctstarttime,acctstoptime,nasipaddress,radacctupdate 
      key: nasipaddress 
     key_len: 17 
      ref: const 
     rows: 94 
     Extra: Using where; Using MRR 

은 아래는 show index from <table> 업데이트 쿼리 방법 아래 사용하여 인덱스를 사용하도록 강제 할 수

+---------+------------+-----------------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 
| Table | Non_unique | Key_name  | Seq_in_index | Column_name  | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | 
+---------+------------+-----------------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 
| radacct |   0 | PRIMARY   |   1 | radacctid  | A   | 29299212 |  NULL | NULL |  | BTREE  |   |    | 
| radacct |   1 | username  |   1 | username  | A   |  NULL |  NULL | NULL |  | BTREE  |   |    | 
| radacct |   1 | framedipaddress |   1 | framedipaddress | A   |  NULL |  NULL | NULL |  | BTREE  |   |    | 
| radacct |   1 | acctsessionid |   1 | acctsessionid | A   |  NULL |  NULL | NULL |  | BTREE  |   |    | 
| radacct |   1 | acctsessiontime |   1 | acctsessiontime | A   |  NULL |  NULL | NULL | YES | BTREE  |   |    | 
| radacct |   1 | acctstarttime |   1 | acctstarttime | A   |  NULL |  NULL | NULL | YES | BTREE  |   |    | 
| radacct |   1 | acctstoptime |   1 | acctstoptime | A   |  NULL |  NULL | NULL | YES | BTREE  |   |    | 
| radacct |   1 | nasipaddress |   1 | nasipaddress | A   |  NULL |  NULL | NULL |  | BTREE  |   |    | 
| radacct |   1 | acctuniqueid |   1 | acctuniqueid | A   |  NULL |  NULL | NULL |  | BTREE  |   |    | 
| radacct |   1 | radacctupdate |   1 | acctstoptime | A   |  NULL |  NULL | NULL | YES | BTREE  |   |    | 
| radacct |   1 | radacctupdate |   2 | nasipaddress | A   |  NULL |  NULL | NULL |  | BTREE  |   |    | 
| radacct |   1 | radacctupdate |   3 | acctstarttime | A   |  NULL |  NULL | NULL | YES | BTREE  |   |    | 
+---------+------------+-----------------+--------------+-----------------+-----------+-------------+----------+--------+------+------------+---------+---------------+ 

답변

1

출력 :

UPDATE radacct use index(indexname_indx100) 
SET acctstoptime= '2017-01-08 14:58:27', 
acctsessiontime = unix_timestamp('2017-01-08 14:58:27')-         unix_timestamp(acctstarttime),acctterminatecause = '',    acctstopdelay=1483866808 
WHERE acctstoptime IS NULL AND nasipaddress='22.194.36.2' AND 
acctstarttime <= '2017-01-08 14:58:27';