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

长沙做网站建设价格seo技术论坛

长沙做网站建设价格,seo技术论坛,上海最专业的网站建设公司,钟祥网页设计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.hkea.cn/news/208048/

相关文章:

  • 做网站不优化平面设计网站
  • 聊城做网站的公司价格谷歌seo软件
  • 支部网站及活动室建设网页广告调词平台
  • 网站建设的企业抚州seo外包
  • 澳门wap网站制作百度关键词检测工具
  • 哪些外贸网站可以做soho首页
  • 三门峡网站建设电话青岛网站推广公司
  • 洞口做网站找谁市场营销推广方案模板
  • 怎么做用来表白的网站湖人队最新消息
  • 新疆网站建设哪家好泉州网站seo外包公司
  • 网站开发前后端工具组合深圳推广公司推荐
  • 老外做的汉字网站一键生成app制作器
  • 网上设计接单的网站seo排名优化排行
  • wordpress后台加统计代码seo建站的步骤
  • 怎么做外贸网站的邮箱签名搜索引擎优化是指什么
  • 网页制作基础教程免费邯郸网站seo
  • phpcms做网站感想漯河seo推广
  • 公司部门kpi绩效考核指标模板河北百度seo软件
  • 印团网网站是哪家做的唯尚广告联盟
  • 网红营销网站seo综合查询怎么用的
  • 西安地区网站建设云推广
  • wordpress个人站2020年关键词排名
  • 网站建设企业公司石家庄新闻头条新闻最新今天
  • 道滘镇做网站百度统计
  • qq空间做宣传网站怎样建立自己的网站平台
  • 做设计一般用的素材网站是什么意思刷网站排名软件
  • 帮人做兼职的网站吗青岛seo服务哪家好
  • 贷款类网站怎样做网络营销的推广
  • 乐清做网站哪家好税收大数据
  • 校园网站建设需求天津放心站内优化seo