mysql trace optimizer
mysql> show variables like '%trace%';
+------------------------------+----------------------------------------------------------------------------+
| Variable_name | Value |
+------------------------------+----------------------------------------------------------------------------+
| optimizer_trace | enabled=off,one_line=off |
| optimizer_trace_features | greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=on |
| optimizer_trace_limit | 1 |
| optimizer_trace_max_mem_size | 16384 |
| optimizer_trace_offset | -1 |
+------------------------------+----------------------------------------------------------------------------+
5 rows in set (0.00 sec)
mysql> set optimizer_trace = "enabled=on"; --開啟跟蹤, 只能跟蹤自己session執行的,不能跟蹤別人的
Query OK, 0 rows affected (0.00 sec)
mysql> select * from test.ta where id=1;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
mysql> select * from information_schema.optimizer_trace\G
*************************** 1. row ***************************
QUERY: select * from test.ta where id=1
TRACE: {
"steps": [
{
"join_preparation": {
"select#": 1,
"steps": [
{
"expanded_query": "/* select#1 */ select `test`.`ta`.`id` AS `id` from `test`.`ta` where (`test`.`ta`.`id` = 1)"
}
]
}
},
{
"join_optimization": {
"select#": 1,
"steps": [
{
"condition_processing": {
"condition": "WHERE",
"original_condition": "(`test`.`ta`.`id` = 1)",
"steps": [
{
"transformation": "equality_propagation", --轉換
"resulting_condition": "multiple equal(1, `test`.`ta`.`id`)"
},
{
"transformation": "constant_propagation",
"resulting_condition": "multiple equal(1, `test`.`ta`.`id`)"
},
{
"transformation": "trivial_condition_removal",
"resulting_condition": "multiple equal(1, `test`.`ta`.`id`)"
}
]
}
},
{
"table_dependencies": [
{
"table": "`test`.`ta`",
"row_may_be_null": false,
"map_bit": 0,
"depends_on_map_bits": [
]
}
]
},
{
"ref_optimizer_key_uses": [
{
"table": "`test`.`ta`",
"field": "id",
"equals": "1",
"null_rejecting": false
}
]
},
{
"rows_estimation": [
{
"table": "`test`.`ta`",
"range_analysis": {
"table_scan": {
"rows": 9,
"cost": 4.9 --表掃描的cost
},
"potential_range_indices": [
{
"index": "idx_ta",
"usable": true,
"key_parts": [
"id"
]
}
],
"best_covering_index_scan": {
"index": "idx_ta",
"cost": 2.8107,
"chosen": true
},
"setup_range_conditions": [
],
"group_index_range": {
"chosen": false,
"cause": "not_group_by_or_distinct"
},
"analyzing_range_alternatives": {
"range_scan_alternatives": [
{
"index": "idx_ta",
"ranges": [
"1 <= id <= 1"
],
"index_dives_for_eq_ranges": true,
"rowid_ordered": true,
"using_mrr": false,
"index_only": true,
"rows": 1,
"cost": 2.21,
"chosen": true
}
],
"analyzing_roworder_intersect": {
"usable": false,
"cause": "too_few_roworder_scans"
}
},
"chosen_range_access_summary": {
"range_access_plan": {
"type": "range_scan",
"index": "idx_ta",
"rows": 1,
"ranges": [
"1 <= id <= 1"
]
},
"rows_for_plan": 1,
"cost_for_plan": 2.21,
"chosen": true
}
}
}
]
},
{
"considered_execution_plans": [
{
"plan_prefix": [
],
"table": "`test`.`ta`",
"best_access_path": {
"considered_access_paths": [
{
"access_type": "ref",
"index": "idx_ta",
"rows": 1,
"cost": 1.2,
"chosen": true --使用了這個執行計劃
},
{
"access_type": "range",
"cause": "heuristic_index_cheaper",
"chosen": false
}
]
},
"cost_for_plan": 1.2,
"rows_for_plan": 1,
"chosen": true
}
]
},
{
"attaching_conditions_to_tables": {
"original_condition": "(`test`.`ta`.`id` = 1)",
"attached_conditions_computation": [
],
"attached_conditions_summary": [
{
"table": "`test`.`ta`",
"attached": null
}
]
}
},
{
"refine_plan": [
{
"table": "`test`.`ta`"
}
]
}
]
}
},
{
"join_execution": {
"select#": 1,
"steps": [
]
}
}
]
}
MISSING_BYTES_BEYOND_MAX_MEM_SIZE: 0
INSUFFICIENT_PRIVILEGES: 0
1 row in set (0.00 sec)
-- 裡面包含條件的去除,查詢的轉換,選擇最好的執行計劃。
mysql> set optimizer_trace = "enabled=off"; --關閉跟蹤
Query OK, 0 rows affected (0.00 sec)
mysql> show create table information_schema.optimizer_trace;
+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| OPTIMIZER_TRACE | CREATE TEMPORARY TABLE `OPTIMIZER_TRACE` ( --這是一個臨時表,別的連線看不到本連線的內容,
`QUERY` longtext NOT NULL,
`TRACE` longtext NOT NULL,
`MISSING_BYTES_BEYOND_MAX_MEM_SIZE` int(20) NOT NULL DEFAULT '0',
`INSUFFICIENT_PRIVILEGES` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+-----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
轉載請註明源地址
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25099483/viewspace-1627237/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql之 explain、optimizer_trace 執行計劃MySqlAI
- MySql中執行計劃如何來的——Optimizer TraceMySql
- 100% 展示 MySQL 語句執行的神器-Optimizer TraceMySql
- 06、MySQL Case-通過optimizer_trace看優化器行為MySql優化
- 手把手教你認識OPTIMIZER_TRACE
- 單表掃描,MySQL索引選擇不正確 並 詳細解析OPTIMIZER_TRACE格式MySql索引
- 復現MySQL的索引選擇失誤以及透過OPTIMIZER_TRACE分析過程MySql索引
- Oracle OptimizerOracle
- OPTIMIZER_MODE、optimizer_index_cost_adjIndex
- OPTIMIZER_INDEX_CACHING & OPTIMIZER_INDEX_COST_ADJIndex
- OPTIMIZER_INDEX_CACHING和OPTIMIZER_INDEX_COST_ADJIndex
- 【MySQL】如何對SQL語句進行跟蹤(trace)?MySql
- MySQL 8.0 Reference Manual(讀書筆記75節--Optimizer Statistics for InnoDB (1))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記76節--Optimizer Statistics for InnoDB (2))MySql筆記
- Oracle Optimizer CBO RBOOracle
- [zt] OPTIMIZER_INDEX_CACHING和OPTIMIZER_INDEX_COST_ADJIndex
- Optimizer_mode引數
- OPTIMIZER_IDEX_COSTIDE
- 引數OPTIMIZER_MODE
- OPTIMIZER_MODE Initialization Parameter
- Zend Optimizer 配置指南 (轉)
- SQL TraceSQL
- trace errorstackError
- _optimizer_compute_index_statsIndex
- Oracle session traceOracleSession
- SQL_TRACESQL
- optimizer_index_cost_adj和optimizer_index_caching對CBO的影響Index
- sql_trace生成及使用tkprof檢視trace fileSQL
- optimizer_index_caching和optimizer_index_cost_adj兩個引數說明Index
- How to Run Statement Level/Java trace or a SQL Trace in Self Service ApplicationJavaSQLAPP
- MySQL 8.0 Reference Manual(讀書筆記60節--Controlling the Query Optimizer(1))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記61節--Controlling the Query Optimizer(2))MySql筆記
- MySQL 8.0 Reference Manual(讀書筆記59節--Controlling the Query Optimizer(3))MySql筆記
- trace top sql sessionSQLSession
- Oracle sql trace用法OracleSQL
- SQL Server TRACE FLAGSQLServer
- How to enable trace in OracleOracle
- Oracle Trace 及TKPROFOracle