gpt4 book ai didi

MySQL/MariaDB 在 PRIMARY KEY 上更新缓慢

转载 作者:行者123 更新时间:2023-11-30 22:47:52 25 4
gpt4 key购买 nike

查询:

UPDATE `cart` SET `user_id` = NULL, `completed` = 0 WHERE `id` = 6948;
Query OK, 0 rows affected (1.21 sec)
Rows matched: 1 Changed: 0 Warnings: 0

0 行受影响,但耗时 1210 毫秒。按 id 选择此行总是花费 0 毫秒。表格大小为(6,354 行)。

> show create table cart;
CREATE TABLE `cart` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
`completed` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'флаг, указывающий на оформление заказа из данной корзины',
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6964 DEFAULT CHARSET=utf8

> show index from cart;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| cart | 0 | PRIMARY | 1 | id | A | 6386 | NULL | NULL | | BTREE | | |
| cart | 1 | user_id | 1 | user_id | A | 2128 | NULL | NULL | YES | BTREE | | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+

这是此查询的 show profile all 的摘录

| Status               | Duration | CPU_user | CPU_system | Context_voluntary | Context_involuntary | Block_ops_in | Block_ops_out | Messages_sent | Messages_received | Page_faults_major | Page_faults_minor | Swaps | Source_function       | Source_file   | Source_line |

| query end | 2.502555 | 0.003000 | 0.000000 | 88 | 8 | 0| 136 | 0 | 0 | 0 | 0 | 0 | mysql_execute_command | sql_parse.cc | 5093 |

为什么 block_ops_out 如此不稳定,从 0 到 400,耗时 0ms ~ 2500ms???如何找到偏高的根本原因?

服务器版本:10.0.17-MariaDB-1~wheezy。 VPS 根本没有任何明显的负载。

UPD:在查询后添加了状态变量:

MariaDB> flush status; UPDATE `cart` SET `user_id` = NULL, `completed` = 0 WHERE `id` = 6948; SHOW SESSION STATUS LIKE 'Handler%';
Query OK, 0 rows affected (0.54 sec)

^[[A^[[BQuery OK, 0 rows affected (3.88 sec)
Rows matched: 1 Changed: 0 Warnings: 0

+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| Handler_commit | 2 |
| Handler_delete | 0 |
| Handler_discover | 0 |
| Handler_external_lock | 0 |
| Handler_icp_attempts | 0 |
| Handler_icp_match | 0 |
| Handler_mrr_init | 0 |
| Handler_mrr_key_refills | 0 |
| Handler_mrr_rowid_refills | 0 |
| Handler_prepare | 2 |
| Handler_read_first | 0 |
| Handler_read_key | 1 |
| Handler_read_last | 0 |
| Handler_read_next | 0 |
| Handler_read_prev | 0 |
| Handler_read_rnd | 0 |
| Handler_read_rnd_deleted | 0 |
| Handler_read_rnd_next | 0 |
| Handler_rollback | 0 |
| Handler_savepoint | 0 |
| Handler_savepoint_rollback | 0 |
| Handler_tmp_update | 0 |
| Handler_tmp_write | 0 |
| Handler_update | 1 |
| Handler_write | 0 |
+----------------------------+-------+
25 rows in set (0.00 sec)

最佳答案

我只能建议尝试将您的表和数据迁移到 Mysql MyIsam 引擎并执行相同的查询。也许您只是发现了 MariaDB 的一个弱点,或者配置错误或过度调整。

关于MySQL/MariaDB 在 PRIMARY KEY 上更新缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29060379/

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