当前位置: 首页 > news >正文

行业门户网站建设方案个人网站的制作模板

行业门户网站建设方案,个人网站的制作模板,做rom的网站,广州住建厅官方网站ICP 索引下推允许存储引擎直接利用索引中的字段值,在遍历索引时就对查询条件进行初步筛选,从而减少不必要的回表操作。 本人在一直使用的形象类比就是:过滤生活污水,污水处理站在处理污水的时候会先进行一次粗过滤,再…

ICP

索引下推允许存储引擎直接利用索引中的字段值,在遍历索引时就对查询条件进行初步筛选,从而减少不必要的回表操作。
本人在一直使用的形象类比就是:过滤生活污水,污水处理站在处理污水的时候会先进行一次粗过滤,再进行后续的净化处理,引申到索引下推的概念就是,在居民排水时就使用滤网进行一次粗过滤,污水站只需要进行细过滤,这样可以大大减少污水站的负荷。
例如,假设有一个联合索引 (name, age),查询条件为 name=‘张三’ AND age=18。在MySQL 5.6之前,系统会先用索引找到所有 name=‘张三’ 的记录,然后回表获取完整数据行,再检查 age=18 的条件是否满足。而在启用索引下推后,系统可以直接在索引中检查 age=18 的条件,只对符合条件的记录进行回表,从而减少了回表次数

具体用例:

select @@optimizer_switch LIKE '%index_condition_pushdown%';
+------------------------------------------------------+
| @@optimizer_switch LIKE '%index_condition_pushdown%' |
+------------------------------------------------------+
|                                                    1 |
+------------------------------------------------------+(root@localhost) [test]> create index idx on t100w (k1,k2);
Query OK, 0 rows affected (6.21 sec)
Records: 0  Duplicates: 0  Warnings: 0(root@localhost) [test]> show index from t100w;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| t100w |          1 | idx      |            1 | k1          | A         |        1173 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
| t100w |          1 | idx      |            2 | k2          | A         |      161727 |     NULL |   NULL | YES  | BTREE      |         |               | YES     | NULL       |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
2 rows in set (0.00 sec)从执行计划中看到只使用到了K1索引的rang scan,但是有使用到ICP
(root@localhost) [test]> desc format=json select * from t100w where k1 > 'Za' and k2='rsEF';
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| EXPLAIN                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {"query_block": {"select_id": 1,"cost_info": {"query_cost": "32077.70"},"table": {"table_name": "t100w","access_type": "range","possible_keys": ["idx"],"key": "idx","used_key_parts": [    <<=="k1"                 <<==],"key_length": "9","rows_examined_per_scan": 52502,"rows_produced_per_join": 5250,"filtered": "10.00","index_condition": "((`test`.`t100w`.`k2` = 'rsEF') and (`test`.`t100w`.`k1` > 'Za'))",  <<=="cost_info": {"read_cost": "31552.68","eval_cost": "525.02","prefix_cost": "32077.70","data_read_per_join": "205K"},"used_columns": ["id","num","k1","k2","dt"]}}
} |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)range  &&  Using index condition 
(root@localhost) [test]> desc select * from t100w where k1 > 'Za' and k2='rsEF';
+----+-------------+-------+------------+-------+---------------+------+---------+------+-------+----------+-----------------------+
| id | select_type | table | partitions | type  | possible_keys | key  | key_len | ref  | rows  | filtered | Extra                 |
+----+-------------+-------+------------+-------+---------------+------+---------+------+-------+----------+-----------------------+
|  1 | SIMPLE      | t100w | NULL       | range | idx           | idx  | 9       | NULL | 52502 |    10.00 | Using index condition |
+----+-------------+-------+------------+-------+---------------+------+---------+------+-------+----------+-----------------------+
1 row in set, 1 warning (0.00 sec)尝试压力测试可见运行时长3s不到
[root@node01 ~]# mysqlslap --defaults-file=/etc/my.cnf --concurrency=100 --iterations=1 --create-schema='test' --query="select * from test.t100w where k1 > 'Za' and k2='rsEF'" engine=innodb --number-of-queries=2000 -uroot -proot -verbose
mysqlslap: [Warning] Using a password on the command line interface can be insecure.
BenchmarkRunning for engine rboseAverage number of seconds to run all queries: 2.496 secondsMinimum number of seconds to run all queries: 2.496 secondsMaximum number of seconds to run all queries: 2.496 secondsNumber of clients running queries: 100Average number of queries per client: 20(root@localhost) [(none)]> SET global optimizer_switch='index_condition_pushdown=OFF';
Query OK, 0 rows affected (0.00 sec)关闭ICP后可见运行时长增长巨大[root@node01 ~]# mysqlslap --defaults-file=/etc/my.cnf --concurrency=100 --iterations=1 --create-schema='test' --query="select * from test.t100w where k1 > 'Za' and k2='rsEF'" engine=innodb --number-of-queries=2000 -uroot -proot -verbose
mysqlslap: [Warning] Using a password on the command line interface can be insecure.
BenchmarkRunning for engine rboseAverage number of seconds to run all queries: 220.215 secondsMinimum number of seconds to run all queries: 220.215 secondsMaximum number of seconds to run all queries: 220.215 secondsNumber of clients running queries: 100Average number of queries per client: 20

优化方式

删掉旧索引,重新组织索引的排列顺序:
(root@localhost) [test]> alter table test.t100w drop index idx;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0(root@localhost) [test]> alter table test.t100w add index idx (k2,k1);
Query OK, 0 rows affected (4.58 sec)
Records: 0  Duplicates: 0  Warnings: 0从执行计划上可以看到,其走到了两个字段的联合索引
(root@localhost) [test]> desc format=json select * from test.t100w where k1 > 'Za' and k2='rsEF';
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| EXPLAIN                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {"query_block": {"select_id": 1,"cost_info": {"query_cost": "12.03"},"table": {"table_name": "t100w","access_type": "range","possible_keys": ["idx"],"key": "idx","used_key_parts": ["k2","k1"],"key_length": "26","rows_examined_per_scan": 19,"rows_produced_per_join": 19,"filtered": "100.00","cost_info": {"read_cost": "10.13","eval_cost": "1.90","prefix_cost": "12.03","data_read_per_join": "760"},"used_columns": ["id","num","k1","k2","dt"],"attached_condition": "((`test`.`t100w`.`k2` = 'rsEF') and (`test`.`t100w`.`k1` > 'Za'))"}}
} |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
尝试压力测试,可以看到该种索引组织方式其性能更优越
[root@node01 ~]# mysqlslap --defaults-file=/etc/my.cnf --concurrency=100 --iterations=1 --create-schema='test' --query="select * from test.t100w where k1 > 'Za' and k2='rsEF'" engine=innodb --number-of-queries=2000 -uroot -proot -verbose
mysqlslap: [Warning] Using a password on the command line interface can be insecure.
BenchmarkRunning for engine rboseAverage number of seconds to run all queries: 0.201 secondsMinimum number of seconds to run all queries: 0.201 secondsMaximum number of seconds to run all queries: 0.201 secondsNumber of clients running queries: 100Average number of queries per client: 20将ICP打开后性能也有小幅的提升:
(root@localhost) [(none)]> SET global optimizer_switch='index_condition_pushdown=ON';
Query OK, 0 rows affected (0.00 sec)(root@localhost) [(none)]> exit
Bye
[root@node01 ~]# mysqlslap --defaults-file=/etc/my.cnf --concurrency=100 --iterations=1 --create-schema='test' --query="select * from test.t100w where k1 > 'Za' and k2='rsEF'" engine=innodb --number-of-queries=2000 -uroot -proot -verbose
mysqlslap: [Warning] Using a password on the command line interface can be insecure.
BenchmarkRunning for engine rboseAverage number of seconds to run all queries: 0.178 secondsMinimum number of seconds to run all queries: 0.178 secondsMaximum number of seconds to run all queries: 0.178 secondsNumber of clients running queries: 100Average number of queries per client: 20查看其执行计划                                                                                      
(root@localhost) [(none)]> desc format=json select * from test.t100w where k1 > 'Za' and k2='rsEF';
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| EXPLAIN                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {"query_block": {"select_id": 1,"cost_info": {"query_cost": "12.03"},"table": {"table_name": "t100w","access_type": "range","possible_keys": ["idx"],"key": "idx","used_key_parts": ["k2","k1"],"key_length": "26","rows_examined_per_scan": 19,"rows_produced_per_join": 19,"filtered": "100.00","index_condition": "((`test`.`t100w`.`k2` = 'rsEF') and (`test`.`t100w`.`k1` > 'Za'))","cost_info": {"read_cost": "10.13","eval_cost": "1.90","prefix_cost": "12.03","data_read_per_join": "760"},"used_columns": ["id","num","k1","k2","dt"]}}
} |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
http://www.shuangfujiaoyu.com/news/50632.html

相关文章:

  • 企业网站建设的成本百度首页广告
  • 团员建设网站百度热搜关键词排名
  • 如何做移动端网站广告软文小故事800字
  • 网站建设 乐达云创长春网站制作推广
  • 网站做等保是什么意思互联网营销是做什么的
  • 廊坊建设网站朋友圈推广
  • 心力建网站外贸订单一般在哪个平台接
  • 心理测试网站开发报价杭州网站建设网页制作
  • 电子类 购物网站seo是谁
  • 卯兔科技西安网站建设一键优化软件
  • 美女做暧暧视频网站天津优化代理
  • 建站软件免费版下载恢复2345网址导航
  • 典型的b2b网站有哪些推广seo优化公司
  • 哪个网站是专门做招商的平台济南网站建设制作
  • 山西做网站运营的公司搜索引擎优化的常用方法
  • 公司网站建设 阜阳长沙疫情最新消息今天封城了
  • 厚街外贸网站建设上海野猪seo
  • 用meteor框架做的微博网站南京seo关键词优化预订
  • 毕业设计做网站代码艺术培训学校招生方案
  • 网站建设公司国内技术最强广州百度seo排名
  • b2b2c模式是什么意思seo营销外包
  • 源丰建设有限公司网站如何制作自己的网站教程
  • 龙岗品牌网站建设流氓网站
  • phpcms 多语言网站常用的搜索引擎有
  • 烟台网站title优化seo赚钱培训
  • 做网站后期续费是怎么算的刚刚中国突然宣布
  • 网站注册备案品牌公关具体要做些什么
  • 网站做重新定向 对网站有影响吗站内优化seo
  • 定制网站开发技术株洲网络推广
  • 网站建设方案范文域名查询网站信息