共計 6665 個字符,預計需要花費 17 分鐘才能閱讀完成。
這篇文章主要介紹“MySQL 特性有哪些”,在日常操作中,相信很多人在 MySQL 特性有哪些問題上存在疑惑,丸趣 TV 小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”MySQL 特性有哪些”的疑惑有所幫助!接下來,請跟著丸趣 TV 小編一起來學習吧!
ICP 測試
首先,咱們來看一下打開 ICP 與關閉 ICP 之間的性能區別,以下是測試過程:
準備數據:
create table icp(id int, age int, name varchar(30), memo varchar(600)) engine=innodb; alter table icp add index aind(age, name, memo); --let $i= 100000 while ($i)
{ --eval insert into icp values($i, 1, a$i , repeat( a$i , 100)) --dec $i }
PS: MySQL 有一個叫 profile 的東東,可以用來監視 SQL 語句在各個階段的執行情況,咱們可以使用這個工具來觀察 SQL 語句在各個階段的運行情況,關于 profile 的詳細說明可以參考官方文檔。
打開 ICP 的性能測試:
set profiling=on;
set optimizer_switch= index_condition_pushdown=on”; (default enabled)mysql select * from icp where age = 999 and name like %999%
+------+------+------+------+
| id | age | name | memo |
+------+------+------+------+
| NULL | 999 | 999 | 999 |
+------+------+------+------+
1 row in set (0.00 sec)
mysql explain select * from icp where age = 999 and name like %999%
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------+
| 1 | SIMPLE | icp | ref | aind | aind | 5 | const | 1 | Using index condition |
+----+-------------+-------+------+---------------+------+---------+-------+------+-----------------------+
1 row in set (0.00 sec)
mysql show profiles;
+----------+------------+-----------------------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+-----------------------------------------------------------------+
| 1 | 0.00043550 | select * from icp where age = 999 and name like %999% |
| 2 | 0.00043250 | explain select * from icp where age = 999 and name like %999% |
+----------+------------+-----------------------------------------------------------------+
2 rows in set, 1 warning (0.00 sec)
mysql show profile cpu,block io for query 2;
+----------------------+----------+----------+------------+--------------+---------------+
| Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+----------------------+----------+----------+------------+--------------+---------------+
| starting | 0.000084 | 0.000000 | 0.000000 | 0 | 0 |
| checking permissions | 0.000011 | 0.000000 | 0.000000 | 0 | 0 |
| Opening tables | 0.000064 | 0.000000 | 0.000000 | 0 | 0 |
| init | 0.000046 | 0.000000 | 0.000000 | 0 | 0 |
| System lock | 0.000010 | 0.000000 | 0.000000 | 0 | 0 |
| optimizing | 0.000020 | 0.000000 | 0.000000 | 0 | 0 |
| statistics | 0.000082 | 0.000000 | 0.000000 | 0 | 0 |
| preparing | 0.000022 | 0.000000 | 0.000000 | 0 | 0 |
| explaining | 0.000021 | 0.000000 | 0.000000 | 0 | 0 |
| query end | 0.000008 | 0.000000 | 0.000000 | 0 | 0 |
| closing tables | 0.000022 | 0.000000 | 0.000000 | 0 | 0 |
| freeing items | 0.000031 | 0.000000 | 0.000000 | 0 | 0 |
| cleaning up | 0.000013 | 0.000000 | 0.000000 | 0 | 0 |
+----------------------+----------+----------+------------+--------------+---------------+
13 rows in set, 1 warning (0.00 sec)
mysql show session status like %handler%
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| Handler_commit | 2 |
| Handler_delete | 0 |
| Handler_discover | 0 |
| Handler_external_lock | 4 |
| Handler_mrr_init | 0 |
| Handler_prepare | 0 |
| Handler_read_first | 0 |
| Handler_read_key | 1 |
| Handler_read_last | 0 |
| Handler_read_next | 1 |
| Handler_read_prev | 0 |
| Handler_read_rnd | 0 |
| Handler_read_rnd_next | 42 |
| Handler_rollback | 0 |
| Handler_savepoint | 0 |
| Handler_savepoint_rollback | 0 |
| Handler_update | 0 |
| Handler_write | 39 |
+----------------------------+-------+
18 rows in set (0.00 sec)
關閉 ICP 的性能測試:
mysql set optimizer_switch= index_condition_pushdown=off”;
mysql select * from icp where age = 1 and memo like %9999%
mysql select * from icp where age = 999 and name like %999%
+------+------+------+------+
| id | age | name | memo |
+------+------+------+------+
| NULL | 999 | 999 | 999 |
+------+------+------+------+
1 row in set (0.00 sec)
mysql explain select * from icp where age = 999 and name like %999%
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
| 1 | SIMPLE | icp | ref | aind | aind | 5 | const | 1 | Using where |
+----+-------------+-------+------+---------------+------+---------+-------+------+-------------+
1 row in set (0.00 sec)
mysql show profiles;
+----------+------------+-----------------------------------------------------------------+
| Query_ID | Duration | Query |
+----------+------------+-----------------------------------------------------------------+
| 1 | 0.00043550 | select * from icp where age = 999 and name like %999% |
| 2 | 0.00043250 | explain select * from icp where age = 999 and name like %999% |
| 3 | 0.00081350 | show session status like %handler% |
| 4 | 0.00010350 | set optimizer_switch= index_condition_pushdown=off |
| 5 | 0.00036525 | select * from icp where age = 999 and name like %999% |
| 6 | 0.00032950 | explain select * from icp where age = 999 and name like %999% |
+----------+------------+-----------------------------------------------------------------+
6 rows in set, 1 warning (0.00 sec)
mysql show profile cpu,block io for query 5;
+----------------------+----------+----------+------------+--------------+---------------+
| Status | Duration | CPU_user | CPU_system | Block_ops_in | Block_ops_out |
+----------------------+----------+----------+------------+--------------+---------------+
| starting | 0.000068 | 0.000000 | 0.000000 | 0 | 0 |
| checking permissions | 0.000007 | 0.000000 | 0.000000 | 0 | 0 |
| Opening tables | 0.000020 | 0.000000 | 0.000000 | 0 | 0 |
| init | 0.000032 | 0.000000 | 0.000000 | 0 | 0 |
| System lock | 0.000010 | 0.000000 | 0.000000 | 0 | 0 |
| optimizing | 0.000015 | 0.000000 | 0.000000 | 0 | 0 |
| statistics | 0.000088 | 0.000000 | 0.000000 | 0 | 0 |
| preparing | 0.000017 | 0.000000 | 0.000000 | 0 | 0 |
| executing | 0.000003 | 0.000000 | 0.000000 | 0 | 0 |
| Sending data | 0.000049 | 0.000000 | 0.000000 | 0 | 0 |
| end | 0.000005 | 0.000000 | 0.000000 | 0 | 0 |
| query end | 0.000007 | 0.000000 | 0.000000 | 0 | 0 |
| closing tables | 0.000008 | 0.000000 | 0.000000 | 0 | 0 |
| freeing items | 0.000024 | 0.000000 | 0.000000 | 0 | 0 |
| cleaning up | 0.000014 | 0.000000 | 0.000000 | 0 | 0 |
+----------------------+----------+----------+------------+--------------+---------------+
15 rows in set, 1 warning (0.00 sec)
正文完