“6fa4d0867a61947103d4a488c5f39a27cf6e161b”上不存在“mobile/src/operators/kernel/flatten_kernel.h”
提交 a583e9d8 编写于 作者: martianzhang's avatar martianzhang

fix explain empty struct problem, null able column

上级 5d7071ab
...@@ -948,23 +948,31 @@ func ParseExplainResult(res QueryResult, formatType int) (exp *ExplainInfo, err ...@@ -948,23 +948,31 @@ func ParseExplainResult(res QueryResult, formatType int) (exp *ExplainInfo, err
return exp, err return exp, err
} }
/*
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
| 1 | SIMPLE | film | NULL | ALL | NULL | NULL | NULL | NULL | 1000 | 100.00 | NULL |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+-------+
*/
// Different MySQL version has different columns define // Different MySQL version has different columns define
var possibleKeys string var selectType, table, partitions, accessType, possibleKeys, key, keyLen, ref, extra []byte
expRow := &ExplainRow{} expRow := &ExplainRow{}
explainFields := make([]interface{}, 0) explainFields := make([]interface{}, 0)
fields := map[string]interface{}{ fields := map[string]interface{}{
"id": expRow.ID, "id": &expRow.ID,
"select_type": expRow.SelectType, "select_type": &selectType,
"table": expRow.TableName, "table": &table,
"partitions": expRow.Partitions, "partitions": &partitions,
"type": expRow.AccessType, "type": &accessType,
"possible_keys": &possibleKeys, "possible_keys": &possibleKeys,
"key": expRow.Key, "key": &key,
"key_len": expRow.KeyLen, "key_len": &keyLen,
"ref": expRow.Ref, "ref": &ref,
"rows": expRow.Rows, "rows": &expRow.Rows,
"filtered": expRow.Filtered, "filtered": &expRow.Filtered,
"extra": expRow.Extra, "Extra": &extra,
} }
cols, err := res.Rows.Columns() cols, err := res.Rows.Columns()
common.LogIfError(err, "") common.LogIfError(err, "")
...@@ -980,13 +988,20 @@ func ParseExplainResult(res QueryResult, formatType int) (exp *ExplainInfo, err ...@@ -980,13 +988,20 @@ func ParseExplainResult(res QueryResult, formatType int) (exp *ExplainInfo, err
// 补全 ExplainRows // 补全 ExplainRows
var explainRows []*ExplainRow var explainRows []*ExplainRow
for res.Rows.Next() { for res.Rows.Next() {
err := res.Rows.Scan(explainFields...) err := res.Rows.Scan(explainFields...)
if err != nil { if err != nil {
common.Log.Debug(err.Error()) common.Log.Warn(err.Error())
} }
expRow.PossibleKeys = strings.Split(possibleKeys, ",") expRow.SelectType = NullString(selectType)
expRow.TableName = NullString(table)
expRow.Partitions = NullString(partitions)
expRow.AccessType = NullString(accessType)
expRow.PossibleKeys = strings.Split(NullString(possibleKeys), ",")
expRow.Key = NullString(key)
expRow.KeyLen = NullString(keyLen)
expRow.Ref = strings.Split(NullString(ref), ",")
expRow.Extra = NullString(extra)
// MySQL bug: https://bugs.mysql.com/bug.php?id=34124 // MySQL bug: https://bugs.mysql.com/bug.php?id=34124
if expRow.Filtered > 100.00 { if expRow.Filtered > 100.00 {
......
...@@ -311,3 +311,11 @@ func TimeString(t time.Time) string { ...@@ -311,3 +311,11 @@ func TimeString(t time.Time) string {
} }
return t.Format(TimeFormat) return t.Format(TimeFormat)
} }
// NullString null able string
func NullString(buf []byte) string {
if buf == nil {
return "NULL"
}
return string(buf)
}
...@@ -184,3 +184,17 @@ func TestIsView(t *testing.T) { ...@@ -184,3 +184,17 @@ func TestIsView(t *testing.T) {
connTest.Database = originalDatabase connTest.Database = originalDatabase
common.Log.Debug("Exiting function: %s", common.GetFunctionName()) common.Log.Debug("Exiting function: %s", common.GetFunctionName())
} }
func TestNullString(t *testing.T) {
common.Log.Debug("Entering function: %s", common.GetFunctionName())
cases := [][]byte{
nil,
[]byte("NULL"),
}
for _, buf := range cases {
if NullString(buf) != "NULL" {
t.Errorf("%s want NULL", string(buf))
}
}
common.Log.Debug("Exiting function: %s", common.GetFunctionName())
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册