gpt4 book ai didi

MySQL:小表上的常量 "Searching rows for update"

转载 作者:行者123 更新时间:2023-11-29 20:26:35 25 4
gpt4 key购买 nike

我的 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,此(或任何)表上没有触发器。该表的主键未在任何其他表中引用。

我将以下查询列为阻止:

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 |
+----------------------+-------------+-----------+-----------+---------------------------------------+--------------------+------------+-----------+----------+-------------------------------------------------------------+

最佳答案

遇到同样的问题..

如果您通过 mysqladmin 刷新表/锁/线程,它应该可以解决它:https://dev.mysql.com/doc/refman/5.5/en/mysqladmin.html

关于MySQL:小表上的常量 "Searching rows for update",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39289005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com