日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

MySQL内核调试_MySQL内核技术之“Opt_trace_系列”

發布時間:2025/3/12 数据库 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySQL内核调试_MySQL内核技术之“Opt_trace_系列” 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

MySQL代碼使用了大量Opt_trace相關結構,先看代碼中的一段注釋:

This optimizer trace is aimed at producing output, which is readable by

humans and by programs, to aid understanding of decisions and actions taken

by the MySQL Optimizer.

可以看出Opt_trace是用來記錄相關操作的,以便幫助開發人員進行調試。其并不具有功能性作用。先來看一下MySQL中是怎么使用Opt_trace的。在主執行函數mysql_execute_command中(位于sql_parse.cc):

Opt_trace_start ots(thd, all_tables, lex->sql_command, &lex->var_list,

thd->query().str, thd->query().length, NULL,

thd->variables.character_set_client);

Opt_trace_object trace_command(&thd->opt_trace);

Opt_trace_array trace_command_steps(&thd->opt_trace, "steps");

...

case SQLCOM_SELECT:

{

if (!res)

res= execute_sqlcom_select(thd, all_tables);

break;

}

在執行sql操作(如SELECT)前,基于thd->opt_trace創建出trace_command和trace_command_steps。注意:當執行完畢后,這兩個變量自動銷毀。

那么Opt_trace_context是什么呢?直接看注釋:

A per-session context which is always available at any point of execution,

It maintains properties of the session's regarding tracing: enabled/disabled

state, style (all trace on one line, or not, etc), a list of all remembered

traces of previous and current SQL statement (as restricted by OFFSET/LIMIT),

and a pointer to the current (being-generated) trace (which itself has a

pointer to its current open object/array).

簡單來說就是thd->opt_trace存了很多上下文信息。這些信息在整個query執行過程中都是需要的。最上面的代碼中:

Opt_trace_start ots(thd, all_tables, lex->sql_command, &lex->var_list,

thd->query().str, thd->query().length, NULL,

thd->variables.character_set_client);

就是用來初始化和賦值thd->opt_trace的。當執行完畢后,ots所在的函數體mysql_execute_command退出時就自動銷毀了,thd->opt_trace在ots的析構函數中被銷毀。除了

基類為Opt_trace_struct定義在opt_trace.h中。代碼用的最多的是兩個派生類Opt_trace_object和Opt_trace_array,以及Opt_trace_context

總結

以上是生活随笔為你收集整理的MySQL内核调试_MySQL内核技术之“Opt_trace_系列”的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。