提交 552ccf9a 编写于 作者: martianzhang's avatar martianzhang

fix explain result with multi rows error

上级 442f4147
......@@ -66,9 +66,9 @@ var ExplainType = map[string]int{
type ExplainInfo struct {
SQL string
ExplainFormat int
ExplainRows []*ExplainRow
ExplainRows []ExplainRow
ExplainJSON *ExplainJSON
Warnings []*ExplainWarning
Warnings []ExplainWarning
QueryCost float64
}
......@@ -419,12 +419,12 @@ func findTablesInJSON(explainJSON string, depth int) {
}
// FormatJSONIntoTraditional 将JSON形式转换为TRADITIONAL形式,方便前端展现
func FormatJSONIntoTraditional(explainJSON string) []*ExplainRow {
func FormatJSONIntoTraditional(explainJSON string) []ExplainRow {
// 查找JSON中的所有ExplainJSONTable
explainJSONTables = []*ExplainJSONTable{}
findTablesInJSON(explainJSON, 0)
var explainRows []*ExplainRow
var explainRows []ExplainRow
id := -1
for _, table := range explainJSONTables {
keyLen := table.KeyLength
......@@ -435,7 +435,7 @@ func FormatJSONIntoTraditional(explainJSON string) []*ExplainRow {
if filtered > 100.00 {
filtered = 100.00
}
explainRows = append(explainRows, &ExplainRow{
explainRows = append(explainRows, ExplainRow{
ID: id + 1,
SelectType: "",
TableName: table.TableName,
......@@ -456,7 +456,7 @@ func FormatJSONIntoTraditional(explainJSON string) []*ExplainRow {
// ConvertExplainJSON2Row 将 JSON 格式转成 ROW 格式,为方便统一做优化建议
// 但是会损失一些 JSON 特有的分析结果
func ConvertExplainJSON2Row(explainJSON *ExplainJSON) []*ExplainRow {
func ConvertExplainJSON2Row(explainJSON *ExplainJSON) []ExplainRow {
buf, err := json.Marshal(explainJSON)
if err != nil {
return nil
......@@ -751,7 +751,7 @@ func ParseExplainText(content string) (exp *ExplainInfo, err error) {
}
// 解析文本形式传统形式Explain信息
func parseTraditionalExplainText(content string) (explainRows []*ExplainRow, err error) {
func parseTraditionalExplainText(content string) (explainRows []ExplainRow, err error) {
LS := regexp.MustCompile(`^\+`) // 华丽的分隔线:)
// 格式正确性检查
......@@ -827,7 +827,7 @@ func parseTraditionalExplainText(content string) (explainRows []*ExplainRow, err
}
// 拼接结构体
explainRows = append(explainRows, &ExplainRow{
explainRows = append(explainRows, ExplainRow{
ID: id,
SelectType: colsMap["select_type"],
TableName: colsMap["table"],
......@@ -847,9 +847,9 @@ func parseTraditionalExplainText(content string) (explainRows []*ExplainRow, err
}
// 解析文本形式竖排版 Explain信息
func parseVerticalExplainText(content string) (explainRows []*ExplainRow, err error) {
func parseVerticalExplainText(content string) (explainRows []ExplainRow, err error) {
var lines []string
explainRow := &ExplainRow{
explainRow := ExplainRow{
Partitions: "NULL",
Filtered: 0.00,
}
......@@ -961,7 +961,7 @@ func ParseExplainResult(res QueryResult, formatType int) (exp *ExplainInfo, err
// Different MySQL version has different columns define
var selectType, table, partitions, accessType, possibleKeys, key, keyLen, ref, extra []byte
expRow := &ExplainRow{}
expRow := ExplainRow{}
explainFields := make([]interface{}, 0)
fields := map[string]interface{}{
"id": &expRow.ID,
......@@ -990,7 +990,7 @@ func ParseExplainResult(res QueryResult, formatType int) (exp *ExplainInfo, err
}
// 补全 ExplainRows
var explainRows []*ExplainRow
var explainRows []ExplainRow
for res.Rows.Next() {
err := res.Rows.Scan(explainFields...)
if err != nil {
......@@ -1020,8 +1020,8 @@ func ParseExplainResult(res QueryResult, formatType int) (exp *ExplainInfo, err
// check explain warning info
if common.Config.ShowWarnings {
for res.Warning.Next() {
var expWarning *ExplainWarning
err = res.Warning.Scan(expWarning.Level, expWarning.Code, expWarning.Message)
var expWarning ExplainWarning
err = res.Warning.Scan(&expWarning.Level, &expWarning.Code, &expWarning.Message)
if err != nil {
break
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册