提交 019ee551 编写于 作者: martianzhang's avatar martianzhang

try to fix Rows.Scan with NULL able column

上级 19a0bc41
......@@ -785,7 +785,6 @@ func CompleteColumnsInfo(stmt sqlparser.Statement, cols []*common.Column, env *e
if find {
break
}
}
// 如果不依赖env环境,利用ast中包含的信息推理列的库表信息
......@@ -904,7 +903,7 @@ func (idxAdv *IndexAdvisor) calcCardinality(cols []*common.Column) []*common.Col
// 如果是不存在的表就会报错,报错的可能性有三个:
// 1.数据库错误 2.表不存在 3.临时表
// 而这三种错误都是不需要在这一层关注的,直接跳过
common.Log.Debug("calcCardinality error: %v", err)
common.Log.Warn("calcCardinality error: %v", err)
continue
}
......
......@@ -18,10 +18,11 @@ package database
import (
"fmt"
"github.com/XiaoMi/soar/common"
"regexp"
"strconv"
"strings"
"github.com/XiaoMi/soar/common"
)
// SHOW TABLE STATUS Syntax
......@@ -191,6 +192,10 @@ func NewTableIndexInfo(tableName string) *TableIndexInfo {
func (db *Connector) ShowIndex(tableName string) (*TableIndexInfo, error) {
tbIndex := NewTableIndexInfo(tableName)
if db.Database == "" || tableName == "" {
return nil, fmt.Errorf("database('%s') or table('%s') name should not empty", db.Database, tableName)
}
// 执行 show create table
res, err := db.Query(fmt.Sprintf("show index from `%s`.`%s`", db.Database, tableName))
if err != nil {
......@@ -456,12 +461,14 @@ func (db *Connector) FindColumn(name, dbName string, tables ...string) ([]*commo
var col common.Column
for res.Rows.Next() {
var character, collation string
res.Rows.Scan(&col.Table,
&col.DB,
&col.DataType,
&col.Character,
&col.Collation)
&character,
&collation)
col.Character = character
col.Collation = collation
// 填充字符集和排序规则
if col.Character == "" {
// 当从`INFORMATION_SCHEMA`.`COLUMNS`表中查询不到相关列的character和collation的信息时
......@@ -479,13 +486,13 @@ func (db *Connector) FindColumn(name, dbName string, tables ...string) ([]*commo
return columns, err
}
var tbCollation string
var tbCollation []byte
if newRes.Rows.Next() {
newRes.Rows.Scan(&tbCollation)
}
if tbCollation != "" {
col.Character = strings.Split(tbCollation, "_")[0]
col.Collation = tbCollation
if string(tbCollation) != "" {
col.Character = strings.Split(string(tbCollation), "_")[0]
col.Collation = string(tbCollation)
}
}
columns = append(columns, &col)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册