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

廊坊建设质量监督局网站中国建设银行企业门户网站

廊坊建设质量监督局网站,中国建设银行企业门户网站,合肥建站比较便宜的公司,网站建设专业名词解释网站对于上面这两种 name>‘a’ 和 name>‘zzz’ 的执行结果,mysql最终是否选择走索引或者一张表涉及多个索引,mysql最终如何选择索引,我们可以用trace工具来一查究竟,开启trace工具会影响mysql性能,所以只能临时分析…

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
对于上面这两种 name>‘a’ 和 name>‘zzz’ 的执行结果,mysql最终是否选择走索引或者一张表涉及多个索引,mysql最终如何选择索引,我们可以用trace工具来一查究竟,开启trace工具会影响mysql性能,所以只能临时分析sql使用,用完之后立即关闭
trace工具用法:

mysql> set session optimizer_trace="enabled=on",end_markers_in_json=on;  --开启trace
mysql> select * from employees where name > 'a' order by position;
mysql> SELECT * FROM information_schema.OPTIMIZER_TRACE;查看trace字段:
{"steps": [{"join_preparation": {    --第一阶段:SQL准备阶段,格式化sql"select#": 1,"steps": [{"expanded_query": "/* select#1 */ select `employees`.`id` AS `id`,`employees`.`name` AS `name`,`employees`.`age` AS `age`,`employees`.`position` AS `position`,`employees`.`hire_time` AS `hire_time` from `employees` where (`employees`.`name` > 'a') order by `employees`.`position`"}] /* steps */} /* join_preparation */},{"join_optimization": {    --第二阶段:SQL优化阶段"select#": 1,"steps": [{"condition_processing": {    --条件处理"condition": "WHERE","original_condition": "(`employees`.`name` > 'a')","steps": [{"transformation": "equality_propagation","resulting_condition": "(`employees`.`name` > 'a')"},{"transformation": "constant_propagation","resulting_condition": "(`employees`.`name` > 'a')"},{"transformation": "trivial_condition_removal","resulting_condition": "(`employees`.`name` > 'a')"}] /* steps */} /* condition_processing */},{"substitute_generated_columns": {} /* substitute_generated_columns */},{"table_dependencies": [    --表依赖详情{"table": "`employees`","row_may_be_null": false,"map_bit": 0,"depends_on_map_bits": [] /* depends_on_map_bits */}] /* table_dependencies */},{"ref_optimizer_key_uses": [] /* ref_optimizer_key_uses */},{"rows_estimation": [    --预估表的访问成本{"table": "`employees`","range_analysis": {"table_scan": {     --全表扫描情况"rows": 10123,    --扫描行数"cost": 2054.7    --查询成本} /* table_scan */,"potential_range_indexes": [    --查询可能使用的索引{"index": "PRIMARY",    --主键索引"usable": false,"cause": "not_applicable"},{"index": "idx_name_age_position",    --辅助索引"usable": true,"key_parts": ["name","age","position","id"] /* key_parts */}] /* potential_range_indexes */,"setup_range_conditions": [] /* setup_range_conditions */,"group_index_range": {"chosen": false,"cause": "not_group_by_or_distinct"} /* group_index_range */,"analyzing_range_alternatives": {    --分析各个索引使用成本"range_scan_alternatives": [{"index": "idx_name_age_position","ranges": ["a < name"      --索引使用范围] /* ranges */,"index_dives_for_eq_ranges": true,"rowid_ordered": false,    --使用该索引获取的记录是否按照主键排序"using_mrr": false,"index_only": false,       --是否使用覆盖索引"rows": 5061,              --索引扫描行数"cost": 6074.2,            --索引使用成本"chosen": false,           --是否选择该索引"cause": "cost"}] /* range_scan_alternatives */,"analyzing_roworder_intersect": {"usable": false,"cause": "too_few_roworder_scans"} /* analyzing_roworder_intersect */} /* analyzing_range_alternatives */} /* range_analysis */}] /* rows_estimation */},{"considered_execution_plans": [{"plan_prefix": [] /* plan_prefix */,"table": "`employees`","best_access_path": {    --最优访问路径"considered_access_paths": [   --最终选择的访问路径{"rows_to_scan": 10123,"access_type": "scan",     --访问类型:为scan,全表扫描"resulting_rows": 10123,"cost": 2052.6,"chosen": true,            --确定选择"use_tmp_table": true}] /* considered_access_paths */} /* best_access_path */,"condition_filtering_pct": 100,"rows_for_plan": 10123,"cost_for_plan": 2052.6,"sort_cost": 10123,"new_cost_for_plan": 12176,"chosen": true}] /* considered_execution_plans */},{"attaching_conditions_to_tables": {"original_condition": "(`employees`.`name` > 'a')","attached_conditions_computation": [] /* attached_conditions_computation */,"attached_conditions_summary": [{"table": "`employees`","attached": "(`employees`.`name` > 'a')"}] /* attached_conditions_summary */} /* attaching_conditions_to_tables */},{"clause_processing": {"clause": "ORDER BY","original_clause": "`employees`.`position`","items": [{"item": "`employees`.`position`"}] /* items */,"resulting_clause_is_simple": true,"resulting_clause": "`employees`.`position`"} /* clause_processing */},{"reconsidering_access_paths_for_index_ordering": {"clause": "ORDER BY","steps": [] /* steps */,"index_order_summary": {"table": "`employees`","index_provides_order": false,"order_direction": "undefined","index": "unknown","plan_changed": false} /* index_order_summary */} /* reconsidering_access_paths_for_index_ordering */},{"refine_plan": [{"table": "`employees`"}] /* refine_plan */}] /* steps */} /* join_optimization */},{"join_execution": {    --第三阶段:SQL执行阶段"select#": 1,"steps": [] /* steps */} /* join_execution */}] /* steps */
}结论:全表扫描的成本低于索引扫描,所以mysql最终选择全表扫描mysql> select * from employees where name > 'zzz' order by position;
mysql> SELECT * FROM information_schema.OPTIMIZER_TRACE;查看trace字段可知索引扫描的成本低于全表扫描,所以mysql最终选择索引扫描mysql> set session optimizer_trace="enabled=off";    --关闭trace

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

mysql> set session optimizer_trace="enabled=on",end_markers_in_json=on;  --开启trace
mysql> select * from employees where name = 'zhuge' order by position;
mysql> select * from information_schema.OPTIMIZER_TRACE;trace排序部分结果:
"join_execution": {    --Sql执行阶段"select#": 1,"steps": [{"filesort_information": [{"direction": "asc","table": "`employees`","field": "position"}] /* filesort_information */,"filesort_priority_queue_optimization": {"usable": false,"cause": "not applicable (no LIMIT)"} /* filesort_priority_queue_optimization */,"filesort_execution": [] /* filesort_execution */,"filesort_summary": {                      --文件排序信息"rows": 10000,                           --预计扫描行数"examined_rows": 10000,                  --参与排序的行"number_of_tmp_files": 3,                --使用临时文件的个数,这个值如果为0代表全部使用的sort_buffer内存排序,否则使用的磁盘文件排序"sort_buffer_size": 262056,              --排序缓存的大小,单位Byte"sort_mode": "<sort_key, packed_additional_fields>"       --排序方式,这里用的单路排序} /* filesort_summary */}] /* steps */} /* join_execution */mysql> set max_length_for_sort_data = 10;    --employees表所有字段长度总和肯定大于10字节
mysql> select * from employees where name = 'zhuge' order by position;
mysql> select * from information_schema.OPTIMIZER_TRACE;trace排序部分结果:
"join_execution": {"select#": 1,"steps": [{"filesort_information": [{"direction": "asc","table": "`employees`","field": "position"}] /* filesort_information */,"filesort_priority_queue_optimization": {"usable": false,"cause": "not applicable (no LIMIT)"} /* filesort_priority_queue_optimization */,"filesort_execution": [] /* filesort_execution */,"filesort_summary": {"rows": 10000,"examined_rows": 10000,"number_of_tmp_files": 2,"sort_buffer_size": 262136,   "sort_mode": "<sort_key, rowid>"         --排序方式,这里用的双路排序} /* filesort_summary */}] /* steps */} /* join_execution */mysql> set session optimizer_trace="enabled=off";    --关闭trace

在这里插入图片描述
在这里插入图片描述

文档:04-mysql慢查询资料.note
链接:http://note.youdao.com/noteshare?id=c71f1e66b7f91dab989a9d3a7c8ceb8e&sub=0B91DF863FB846AA9A1CDDF431402C7B

在这里插入图片描述
在这里插入图片描述


文章转载自:

http://srBI2rsA.cwtrL.cn
http://HfPeIdNL.cwtrL.cn
http://0MrhhlBy.cwtrL.cn
http://2fQJSkhP.cwtrL.cn
http://ULk6Il3f.cwtrL.cn
http://q40DoWSP.cwtrL.cn
http://71lzCtkR.cwtrL.cn
http://ojzKIY37.cwtrL.cn
http://q6vMpV57.cwtrL.cn
http://R1Dfpjoi.cwtrL.cn
http://TqK5C7gS.cwtrL.cn
http://7aYqH5TH.cwtrL.cn
http://zDjBQcyT.cwtrL.cn
http://YgtBfDRY.cwtrL.cn
http://Xct2aOKe.cwtrL.cn
http://kQm2fc3v.cwtrL.cn
http://1dZPVtiK.cwtrL.cn
http://nZPc3B34.cwtrL.cn
http://fgfkGK10.cwtrL.cn
http://1xkatH5z.cwtrL.cn
http://kv4LZuuc.cwtrL.cn
http://5QXxWO4Y.cwtrL.cn
http://2IpRi1bG.cwtrL.cn
http://ojbV6wCV.cwtrL.cn
http://LWiV8jiE.cwtrL.cn
http://TD64D1cG.cwtrL.cn
http://JzJA698E.cwtrL.cn
http://dfZqMD9T.cwtrL.cn
http://3zEgbCJU.cwtrL.cn
http://UJiuSqsF.cwtrL.cn
http://www.dtcms.com/wzjs/695745.html

相关文章:

  • 个人网站备案资料深圳今天新增确诊名单
  • 响应式网站一般怎么设计网站10月份可以做哪些有意思的专题
  • 做网站的最佳方法黄石城乡建设网站
  • 网站备案要钱吗wordpress图片缓冲
  • 开发一个网站多少钱雏光 网络推广 网站建设
  • 海南专业网站建设百度竞价排名技巧
  • 建设网站图片网站建设zgkr
  • 用dw建设个人网站视频wordpress 访客文章
  • 湖北建设招标网 官方网站旅游网站建设设计公司
  • 滨州哪里有做网站的郴州网络推广公司在哪里
  • 小学校园门户网站建设方案兄弟们拿走不谢
  • 白银市做网站网站建设 图标
  • 优化网站排名公司网红营销模式分析
  • 建站平台软件怎么做建设网站
  • 网站建设技术服务的方式是什么建站平台入口
  • 如何提升网站转化率营销策划公司收费明细
  • 网站制作开发公司网站 微信
  • 电子产品网站建设策划方案胶州企业网站设计
  • 做视频的软件模板下载网站有哪些内容北京建设主管部门官方网站
  • 徐州网站优化价格菏泽网站网站建设
  • 专业做二手房的网站elementor做视频网站
  • 网站怎么做才不会被墙网站建设 人和商圈
  • 服装东莞网站建设广州平台公司
  • 忻州做网站怎么打开公众号
  • 长春长春网站建设公司企业外包
  • 用discuz建设企业网站设计公司排名前十
  • 海南省住房和城乡建设厅网站首页嵌入式和网站开发
  • 高端 旅游 网站建设浙江华临建设集团有限公司网站
  • 静态宠物网站设计论文专业营销的网站建设公司
  • 网站demo怎么做公司做网站费用怎么记账