2016-09-02 2 views
0

의 "업데이트에 대한 행을 검색"나는 내 MySQL의 스키마에 다음과 같은 테이블이 :MySQL은 : 일정한 작은 테이블

CREATE TABLE `security_token` (
`id` int(11) NOT NULL AUTO_INCREMENT, 
`customer_id` int(11) DEFAULT NULL, 
`expiration_date` datetime NOT NULL, 
`token_string` varchar(50) NOT NULL, 
`user_name` varchar(100) NOT NULL, 
PRIMARY KEY (`id`), 
KEY `security_token_token_string` (`token_string`) 
) ENGINE=InnoDB AUTO_INCREMENT=7054 DEFAULT CHARSET=latin1; 

다음 쿼리가 자주 실행 (여러 번 분) 때로는 초과한다 로 3 분 실행할 :

UPDATE security_token 
SET expiration_date = '2016-09-01 18:20:37' 
WHERE user_name = 'john.smith' AND token_string = 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU' AND customer_id = 3 

을 난 상태 인 SHOW PROCESSLIST을 수행하는 경우

| 33515563 | db_user | 192.168.0.7:41058 | application_schema | Query | 116 | Searching rows for update | UPDATE security_token SET expiration_date = '2016-09-02 18:12:28' WHERE user_name = 'john.smith' AND ... | 
| 33515576 | db_user | 192.168.0.7:41062 | application_schema | Query | 113 | Searching rows for update | UPDATE security_token SET expiration_date = '2016-09-02 18:12:28' WHERE user_name = 'john.smith' AND ... | 
| 33515587 | db_user | 192.168.0.7:41064 | application_schema | Query | 110 | Searching rows for update | UPDATE security_token SET expiration_date = '2016-09-02 18:12:29' WHERE user_name = 'john.smith' AND ... | 
| 33515609 | db_user | 192.168.0.7:41067 | application_schema | Query | 106 | Searching rows for update | UPDATE security_token SET expiration_date = '2016-09-02 18:12:30' WHERE user_name = 'john.smith' AND ... | 
| 33515631 | db_user | 192.168.0.7:41071 | application_schema | Query | 104 | Searching rows for update | UPDATE security_token SET expiration_date = '2016-09-02 18:12:45' WHERE user_name = 'john.smith' AND ... | 
| 33515665 | db_user | 192.168.0.7:41076 | application_schema | Query | 101 | Searching rows for update | UPDATE security_token SET expiration_date = '2016-09-02 18:13:12' WHERE user_name = 'john.smith' AND ... | 
| 33515708 | db_user | 192.168.0.7:41081 | application_schema | Query | 98 | Searching rows for update | UPDATE security_token SET expiration_date = '2016-09-02 18:13:28' WHERE user_name = 'john.smith' AND ... | 
| 33515710 | db_user | 192.168.0.7:41086 | application_schema | Query | 93 | Searching rows for update | UPDATE security_token SET expiration_date = '2016-09-02 18:13:29' WHERE user_name = 'john.smith' AND ... | 
| 33515711 | db_user | 192.168.0.7:41090 | application_schema | Query | 88 | Searching rows for update | UPDATE security_token SET expiration_date = '2016-09-02 18:13:36' WHERE user_name = 'john.smith' AND ... | 
| 33515712 | db_user | 192.168.0.7:41092 | application_schema | Query | 85 | Searching rows for update | UPDATE security_token SET expiration_date = '2016-09-02 18:13:58' WHERE user_name = 'john.smith' AND ... | 

테이블의 크기는 6k 행이며 크기는 1.2MB입니다. 전체 스키마 크기는 300MB이며 현재 Amazon RDS db.m4.xlarge 인스턴스에서 실행 중입니다.

이 쿼리가 왜 그렇게 많은 문제를 일으키는 지 잘 모르겠지만 아무에게도 포인터를 제공 할 수 있습니까? 불행히도 프로덕션 데이터베이스이므로 성능 스키마를 사용할 수 없습니다. 더 많은 정보

내가 버전 5.6.19-log를 실행하고와

업데이트,이 아무런 트리거 (또는) 테이블이 없습니다. 이 테이블의 기본 키는 다른 테이블에서 참조되지 않습니다.

I가 차단으로 나열 다음 쿼리 :

SELECT * FROM INNODB_LOCKS WHERE LOCK_TRX_ID IN (SELECT BLOCKING_TRX_ID FROM INNODB_LOCK_WAITS); 
+----------------------+-------------+-----------+-----------+---------------------------------------+--------------------+------------+-----------+----------+-------------------------------------------------------------+ 
| lock_id    | lock_trx_id | lock_mode | lock_type | lock_table       | lock_index   | lock_space | lock_page | lock_rec | lock_data             | 
+----------------------+-------------+-----------+-----------+---------------------------------------+--------------------+------------+-----------+----------+-------------------------------------------------------------+ 
| 535259585:349:43:132 | 535259585 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259584:349:43:132 | 535259584 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259583:349:43:132 | 535259583 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259581:349:43:132 | 535259581 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259575:349:43:132 | 535259575 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259574:349:43:132 | 535259574 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259573:349:43:132 | 535259573 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259570:349:43:132 | 535259570 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259554:349:43:132 | 535259554 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259551:349:43:132 | 535259551 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259546:349:43:132 | 535259546 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259544:349:43:132 | 535259544 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259543:349:43:132 | 535259543 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259541:349:43:132 | 535259541 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259525:349:43:132 | 535259525 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259522:349:43:132 | 535259522 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259521:349:43:132 | 535259521 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259520:349:43:132 | 535259520 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259519:349:43:132 | 535259519 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
| 535259517:349:43:132 | 535259517 | X   | RECORD | `application_schema`.`security_token` | security_token_idx |  349 |  43 |  132 | 'john.smith', 'mLBgrOXfVsXewCV333dVdvvDdxghJqQRU', 3, 70661 | 
+----------------------+-------------+-----------+-----------+---------------------------------------+--------------------+------------+-----------+----------+-------------------------------------------------------------+ 
+0

security_token 컬럼에 인덱스를 부여하십시오. – Ish

+0

다음 표에서는'alter table security_token add index security_token_idx (security_token);'과'alter table security_token add index token_string_idx (token_string)'및'alter table security_token table security_token add index customer_id_idx (customer_id)'where 절에서 같은 우선 순위를 따를 경우 복합 인덱스가 더 좋을 것입니다. 'alter table security_token add index user_token_customer_idx (user_name, token_string, customer_id)' –

+0

인덱스를 추가했습니다 :'create index security_token_idx on security_token (user_name, token_string, customer_id)'그리고이 점이 아무런 차이가 없다면, 나는 아직도이 쿼리가 (2 분) 실행 시간이 긴'show processlist'에서 빌드되는 것을 볼 수 있습니다. –

답변

0

같은 문제에 직면 ..

당신이 플러시 테이블/잠금/mysqladmin 데이터에 의해 스레드, 그것을 해결해야하는 경우 : https://dev.mysql.com/doc/refman/5.5/en/mysqladmin.html

+0

이 링크가 질문에 대답 할 수 있지만 여기에 답변의 핵심 부분을 포함하고 참조 용 링크를 제공하는 것이 좋습니다. 연결된 페이지가 변경되면 링크 전용 답변이 유효하지 않을 수 있습니다. –