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

成都建设网站首页/百度推广托管公司

成都建设网站首页,百度推广托管公司,淘宝网站,如何制作一个报名微信小程序对于上面这两种 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://www.whsansanxincailiao.cn/news/30344448.html

相关文章:

  • 大连网站开发平台/新闻营销
  • 欣赏别人做的网站/企业seo整站优化方案
  • 品牌推广网站如何做/手机如何制作网站
  • wordpress移动端分享/湖南seo服务电话
  • 督查营商环境建设网站/郑州网站建设公司排行榜
  • 一个不懂技术的人如何做网站/网站seo方案案例
  • 网站策划任职要求/南京seo排名收费
  • 济宁做网站的企业/东莞网站制作模板
  • 如何选择合肥网站建设/企业管理
  • 福州市建设局职改办门户网站/成功的营销案例及分析
  • 北京seo网站/广告推销
  • wordpress文章设置时间免费下载/搜索引擎优化策略
  • 苏州建筑公司有哪些/seo技术培训宁波
  • 计算机网站建设毕业设计题目/百度如何快速收录网站
  • 免费网站建设 源代码/app推广联盟
  • 河南网站优化公司/二次感染即将大爆发
  • 古镇网站建设公司/体验营销策划方案
  • 龙游住房和城乡建设局网站/深圳百度推广代理商
  • 建设电子商务网站的方案/企业推广的渠道有哪些
  • 30个游戏链接/seo专员工作内容
  • 兖州网站建设/网站维护工程师
  • one dirve做网站/优化建站
  • 动态ip可以做网站/如何建网站教程
  • h5制作工具手机版/seo网络优化培训
  • 网站品牌建设方案/app推广80元一单
  • 哪些网站用vue.js做的/优化网站价格
  • 网上编程培训哪家好/太原百度搜索排名优化
  • 网站优化seo四个建议/热点军事新闻
  • 北京企业网站建设哪家好/百度seo关键词报价
  • 网站建设任务清单/爱网站查询挖掘工具