免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

MySQL索引性能測試

MySQL索引性能測試

 

blog文檔結(jié)構(gòu)圖:

MySQL索引性能測試

 

在民和等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、做網(wǎng)站 網(wǎng)站設(shè)計制作按需求定制設(shè)計,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都全網(wǎng)營銷,成都外貿(mào)網(wǎng)站建設(shè),民和網(wǎng)站建設(shè)費用合理。

很長一段時間沒學(xué)習(xí)MySQL了,一直致力于oracle的研究,最近得空了就再拾起MySQL看看吧,記得去年發(fā)布過的2篇MySQL文章:

    MySQL 5.6.21下載安裝之下載篇(一)  : http://blog.itpub.net/26736162/viewspace-1349705/

    MySQL 5.6.21下載安裝之安裝篇(二): http://blog.itpub.net/26736162/viewspace-1349787/

今天我們就來看看mysql中索引的性能測試:

1 準備環(huán)境

1.1  在數(shù)據(jù)庫中創(chuàng)建測試表test1

[root@rhel6_lhr ~]# mysql -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 14

Server version: 5.6.21-enterprise-commercial-advanced MySQL Enterprise Server - Advanced Edition (Commercial)

 

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| db1                |

| db4                |

| lhr_test           |

| mysql              |

| opensource         |

| opesource          |

| performance_schema |

| test               |

| wyzc               |

+--------------------+

10 rows in set (0.00 sec)

 

mysql> use lhr_test;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

 

Database changed

mysql> create table test1(

    -> id int,

    -> num int,

    -> pass varchar(50)

    -> );

Query OK, 0 rows affected (0.01 sec)

 

mysql> desc test1;

+-------+-------------+------+-----+---------+-------+

| Field | Type        | Null | Key | Default | Extra |

+-------+-------------+------+-----+---------+-------+

| id    | int(11)     | YES  |     | NULL    |       |

| num   | int(11)     | YES  |     | NULL    |       |

| pass  | varchar(50) | YES  |     | NULL    |       |

+-------+-------------+------+-----+---------+-------+

3 rows in set (0.00 sec)

 

mysql> create table test2(

    ->  id int,

    ->  num int,

    ->  pass varchar(50),

    ->  index idIdx (id)

    ->  );

Query OK, 0 rows affected (0.24 sec)

 

mysql> create table test3(

    ->  id int,

    ->  num int,

    ->  pass varchar(50)

    ->  );

reset query cache;Query OK, 0 rows affected (0.09 sec)

 

 

 

 

1.2  在系統(tǒng)提示符下執(zhí)行如下語句創(chuàng)建100萬行數(shù)據(jù)

在操作系統(tǒng)執(zhí)行命令,生成100W條數(shù)據(jù),其中-plhr中的lhr為mysql的密碼,lhr_test為數(shù)據(jù)庫名,該命令為一整條命令:for ((i=1;i<=1000000;i++));do `mysql -plhr lhr_test -e "insert into test1 values($i,floor($i+rand()*$i),md5($i));"`; done > /tmp/mysql.txt   2>&1  

 

經(jīng)過漫長的等待后查看數(shù)據(jù),受不了了,直接20W做測試吧:

MySQL索引性能測試 

MySQL索引性能測試 

 

 

2 簡單測試索引性能

2.1  在有索引和沒有索引的情況下執(zhí)行查詢

 

mysql>select * from test1 limit 10;

+------+------+----------------------------------+

| id   | num  | pass                             |

+------+------+----------------------------------+

|    1 |    1 | c4ca4238a0b923820dcc509a6f75849b |

|    2 |    3 | c81e728d9d4c2f636f067f89cc14862c |

|    3 |    4 | eccbc87e4b5ce2fe28308fd9f2a7baf3 |

|    4 |    5 | a87ff679a2f3e71d9181a67b7542122c |

|    5 |    5 | e4da3b7fbbce2345d7772b0674a318d5 |

|    6 |    6 | 1679091c5a880faf6fb5e6087eb1b2dc |

|    7 |   10 | 8f14e45fceea167a5a36dedd4bea2543 |

|    8 |   12 | c9f0f895fb98ab9159f51fd0297e236d |

|    9 |   12 | 45c48cce2e2d7fbdea1afc51c7c6ad26 |

|   10 |   12 | d3d9446802a44259755d38e6d163e820 |

+------+------+----------------------------------+

10 rows in set (0.00 sec)

 

mysql>reset query cache; ---清空緩存

Query OK, 0 rows affected (0.18 sec)

 

mysql> select num,pass   from test1 where id>=50000 and id<50050;

+-------+----------------------------------+

| num   | pass                             |

+-------+----------------------------------+

| 66755 | 1017bfd4673955ffee4641ad3d481b1c |

| 70239 | 334146de1b9346272cb013adf1a35aea |

| 93704 | f67fe69d3660b4d35a731817b538b21d |

| 90594 | 0cce9d48eb96fdf93fbae8640d547b8e |

| 94673 | 171ab172efb24344684eca5b04abffca |

| 51476 | e7beb1dcf073b1d1e700fb02eccaf064 |

| 78604 | 2432fc2efe99899b0ecff8ade0211e7d |

| 62059 | 1cc41f4ab8528178818a29b9ef5fabbb |

| 94777 | 79c3489e2392afd26733d285dee3abd0 |

| 71807 | f0547ecd4e64a31e247c34b64547f812 |

| 62106 | 3e53ae683f8e8c84221db763b30fe907 |

| 74578 | fbbbadb6d1a15c0c924c73b0b0a4b7cb |

| 91069 | 9ba86c2987b9321a45b4dbf1eff6bb4a |

| 71692 | 8ec41a3e649625a55ceafc35f6fa45e8 |

| 72179 | 87b0cba64000c51c883f57274c04519c |

| 96570 | f7c3c4088dfe80933e84ca084fa3524a |

| 70295 | 5a5a84625f44b7e7345b4ea6fde06627 |

| 68758 | 85dbdb1cbb78b9be83ccedd468732e0a |

| 77853 | 16d37a42180158171d57e1cc8122b415 |

| 81193 | c3a8217c9d3a5d9c5e76a77d8f4a8fde |

| 71512 | 4e2598d3fa41ae72d1927b81328dbd51 |

| 87838 | 81b993dae9d5735b0714c325c526aee5 |

| 51719 | d3d2a1a264feb84bd8ba9d0557aafca8 |

| 88469 | d5e390212ea61535b492b740102df78a |

| 92232 | cf50b28ef624912ff106c57ca9be41dc |

| 67030 | a4eacdf08e8fda83c7784c8fd21f7811 |

| 93650 | 9a84af5408986faab11f648a07867d84 |

| 70810 | 31bd7cc9213175d709fcfa2eeb4b202a |

| 77757 | 2d084a4acd512e6314d6e8ae111b8205 |

| 66555 | 2a12b41adeedc754b55ec468d1a41d09 |

| 77727 | 33702a9c691c0f5aaac103d7dd1952eb |

| 92189 | d081111dbdee3c687d1439b444d64004 |

| 90372 | dfdc9e0c03a33349408e99f28d07f899 |

| 91206 | 0610027c7b4268080e7c1c5f04af05a7 |

| 77903 | cb07accc409bbb4c0adc6afb26cf351b |

| 55402 | a1f3a4e959c66a4dd4f330f13ff4d808 |

| 75258 | 9f75e281cbe6072bd91a286e64fb6f0d |

| 88422 | 9bf3f8e2f454487987a4888544f9e1be |

| 76166 | 664a26f366b9ef4988631e95af9b366d |

| 87260 | f19ea2ad04c46f33134d405510650a60 |

| 73856 | 3b4421d0ab0e43c65932c51fb58f593f |

| 89850 | ca355f31b8e517abc70bf477ca77f4ce |

| 84650 | afa8024de2c03966e71d6f94a93b6b93 |

| 63982 | ce9e053a63f6a8aed199bed09f1e498e |

| 92551 | 3cf419e05d85881157b758a01c6ef399 |

| 80764 | af7994b458c40e4a18ec60f5e622e522 |

| 50054 | c3beb22d8bb8a4b874fd7bb8a8914643 |

| 72336 | 5f9f76d679371d223deeda050bdc9d85 |

| 85120 | 218171bd4087237acdcc6d3846b9cda5 |

| 85468 | d38aad5d5676be87eaf6ade964caff4f |

+-------+----------------------------------+

50 rows in set (0.15 sec)

 

 

mysql> insert into test2 select * from test1;

Query OK, 225494 rows affected(2.53 sec)

Records: 225494  Duplicates: 0  Warnings: 0

 

mysql>  reset query cache;

Query OK, 0 rows affected (0.00 sec)

 

mysql>explain select num,pass   from test2 where id>=50000 and id<50050;

+----+-------------+-------+-------+---------------+-------+---------+------+------+-----------------------+

| id | select_type | table | type  | possible_keys | key   | key_len | ref  | rows | Extra                 |

+----+-------------+-------+-------+---------------+-------+---------+------+------+-----------------------+

|  1 | SIMPLE      | test2 |range | idIdx         | idIdx | 5       | NULL |   49 | Using index condition |

+----+-------------+-------+-------+---------------+-------+---------+------+------+-----------------------+

1 row in set (0.00 sec)

 

mysql> explain select num,pass   from test1  where id>=50000 and id<50050;

+----+-------------+-------+------+---------------+------+---------+------+--------+-------------+

| id | select_type | table | type | possible_keys | key  | key_len | ref  | rows   | Extra       |

+----+-------------+-------+------+---------------+------+---------+------+--------+-------------+

|  1 | SIMPLE      | test1 |ALL  | NULL          | NULL | NULL    | NULL | 226851 | Using where |

+----+-------------+-------+------+---------------+------+---------+------+--------+-------------+

1 row in set (0.00 sec)

 

mysql> reset query cache;

Query OK, 0 rows affected (0.00 sec)

 

mysql>  select num,pass   from test2 where id>=50000 and id<50050;

+-------+----------------------------------+

| num   | pass                             |

+-------+----------------------------------+

| 66755 | 1017bfd4673955ffee4641ad3d481b1c |

| 70239 | 334146de1b9346272cb013adf1a35aea |

| 93704 | f67fe69d3660b4d35a731817b538b21d |

| 90594 | 0cce9d48eb96fdf93fbae8640d547b8e |

| 94673 | 171ab172efb24344684eca5b04abffca |

| 51476 | e7beb1dcf073b1d1e700fb02eccaf064 |

| 78604 | 2432fc2efe99899b0ecff8ade0211e7d |

| 62059 | 1cc41f4ab8528178818a29b9ef5fabbb |

| 94777 | 79c3489e2392afd26733d285dee3abd0 |

| 71807 | f0547ecd4e64a31e247c34b64547f812 |

| 62106 | 3e53ae683f8e8c84221db763b30fe907 |

| 74578 | fbbbadb6d1a15c0c924c73b0b0a4b7cb |

| 91069 | 9ba86c2987b9321a45b4dbf1eff6bb4a |

| 71692 | 8ec41a3e649625a55ceafc35f6fa45e8 |

| 72179 | 87b0cba64000c51c883f57274c04519c |

| 96570 | f7c3c4088dfe80933e84ca084fa3524a |

| 70295 | 5a5a84625f44b7e7345b4ea6fde06627 |

| 68758 | 85dbdb1cbb78b9be83ccedd468732e0a |

| 77853 | 16d37a42180158171d57e1cc8122b415 |

| 81193 | c3a8217c9d3a5d9c5e76a77d8f4a8fde |

| 71512 | 4e2598d3fa41ae72d1927b81328dbd51 |

| 87838 | 81b993dae9d5735b0714c325c526aee5 |

| 51719 | d3d2a1a264feb84bd8ba9d0557aafca8 |

| 88469 | d5e390212ea61535b492b740102df78a |

| 92232 | cf50b28ef624912ff106c57ca9be41dc |

| 67030 | a4eacdf08e8fda83c7784c8fd21f7811 |

| 93650 | 9a84af5408986faab11f648a07867d84 |

| 70810 | 31bd7cc9213175d709fcfa2eeb4b202a |

| 77757 | 2d084a4acd512e6314d6e8ae111b8205 |

| 66555 | 2a12b41adeedc754b55ec468d1a41d09 |

| 77727 | 33702a9c691c0f5aaac103d7dd1952eb |

| 92189 | d081111dbdee3c687d1439b444d64004 |

| 90372 | dfdc9e0c03a33349408e99f28d07f899 |

| 91206 | 0610027c7b4268080e7c1c5f04af05a7 |

| 77903 | cb07accc409bbb4c0adc6afb26cf351b |

| 55402 | a1f3a4e959c66a4dd4f330f13ff4d808 |

| 75258 | 9f75e281cbe6072bd91a286e64fb6f0d |

| 88422 | 9bf3f8e2f454487987a4888544f9e1be |

| 76166 | 664a26f366b9ef4988631e95af9b366d |

| 87260 | f19ea2ad04c46f33134d405510650a60 |

| 73856 | 3b4421d0ab0e43c65932c51fb58f593f |

| 89850 | ca355f31b8e517abc70bf477ca77f4ce |

| 84650 | afa8024de2c03966e71d6f94a93b6b93 |

| 63982 | ce9e053a63f6a8aed199bed09f1e498e |

| 92551 | 3cf419e05d85881157b758a01c6ef399 |

| 80764 | af7994b458c40e4a18ec60f5e622e522 |

| 50054 | c3beb22d8bb8a4b874fd7bb8a8914643 |

| 72336 | 5f9f76d679371d223deeda050bdc9d85 |

| 85120 | 218171bd4087237acdcc6d3846b9cda5 |

| 85468 | d38aad5d5676be87eaf6ade964caff4f |

+-------+----------------------------------+

50 rowsin set (0.00 sec)

 

 

 

2.2  在有索引和沒有索引的情況下新增數(shù)據(jù)

 

 

 

mysql>  reset query cache;

Query OK, 0 rows affected (0.00 sec)

 

mysql>  insert into test3 select * from test1;

Query OK, 225494 rows affected(1.67 sec)

Records: 225494  Duplicates: 0  Warnings: 0

 

mysql>

 

 

3 總結(jié)

表名

表屬性

查詢(單位:秒)

插入(單位:秒)

test1

無索引

0.15

 

test2

有索引

0.00

2.53

test3

無索引

 

1.67

 

 

結(jié)論:通常情況下,有索引的情況下查詢比較快,插入比較慢,所以在大批量的數(shù)據(jù)導(dǎo)入操作中應(yīng)該首先刪除索引,待數(shù)據(jù)導(dǎo)入完成后再建立索引,由于深入學(xué)習(xí)過oracle,感覺在這里說這些似乎是廢話,但認真做實驗是一種態(tài)度,本blog中總有一些你不知道的,o(∩_∩)o 哈哈。

 

 

 

 

 

.............................................................................................................................

本文作者:小麥苗,只專注于數(shù)據(jù)庫的技術(shù),更注重技術(shù)的運用

ITPUB BLOG:http://blog.itpub.net/26736162

本文地址: http://blog.itpub.net/26736162/viewspace-1466094/

QQ:642808185 注明:ITPUB的文章標題

<版權(quán)所有,文章允許轉(zhuǎn)載,但須以鏈接方式注明源地址,否則追究法律責(zé)任!>

.............................................................................................................................

 

 

新聞名稱:MySQL索引性能測試
網(wǎng)頁鏈接:http://m.newbst.com/article22/jicpcc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃品牌網(wǎng)站制作App開發(fā)企業(yè)建站網(wǎng)站制作云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)