提交 027e992f 编写于 作者: martianzhang's avatar martianzhang

FIXME: SUPPORT VIEW

上级 16f00375
...@@ -189,11 +189,14 @@ func (db *Connector) ColumnCardinality(tb, col string) float64 { ...@@ -189,11 +189,14 @@ func (db *Connector) ColumnCardinality(tb, col string) float64 {
common.Log.Debug("(db *Connector) ColumnCardinality() No table status: %s", tb) common.Log.Debug("(db *Connector) ColumnCardinality() No table status: %s", tb)
return 1 return 1
} }
rowTotal := tbStatus.Rows[0].Rows rowTotal, err := strconv.ParseUint(string(tbStatus.Rows[0].Rows), 10, 64)
if rowTotal == 0 { if rowTotal == 0 || err != nil {
if common.Config.Sampling { if common.Config.Sampling {
common.Log.Debug("ColumnCardinality, %s rowTotal == 0", tb) common.Log.Debug("ColumnCardinality, %s rowTotal == 0", tb)
} }
if err != nil {
common.Log.Error("ColumnCardinality, Error:", err.Error())
}
return 1 return 1
} }
......
...@@ -19,6 +19,7 @@ package database ...@@ -19,6 +19,7 @@ package database
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"strconv"
"strings" "strings"
"time" "time"
...@@ -74,9 +75,12 @@ func (db *Connector) SamplingData(onlineConn *Connector, tables ...string) error ...@@ -74,9 +75,12 @@ func (db *Connector) SamplingData(onlineConn *Connector, tables ...string) error
return nil return nil
} }
tableRows := tableStatus.Rows[0].Rows tableRows, err := strconv.ParseUint(string(tableStatus.Rows[0].Rows), 10, 64)
if tableRows == 0 { if tableRows == 0 || err != nil {
common.Log.Info("SamplingData, Table %s with no data, stop sampling", table) common.Log.Info("SamplingData, Table %s with no data, stop sampling", table)
if err != nil {
common.Log.Error("SamplingData, Error: ", err.Error())
}
return nil return nil
} }
......
...@@ -41,25 +41,25 @@ type tableStatusRow struct { ...@@ -41,25 +41,25 @@ type tableStatusRow struct {
Engine []byte // 该表使用的存储引擎 Engine []byte // 该表使用的存储引擎
Version []byte // 该表的 .frm 文件版本号 Version []byte // 该表的 .frm 文件版本号
RowFormat []byte // 该表使用的行存储格式 RowFormat []byte // 该表使用的行存储格式
Rows uint64 // 表行数, InnoDB 引擎中为预估值,甚至可能会有40%~50%的数值偏差 Rows []byte // 表行数, InnoDB 引擎中为预估值,甚至可能会有40%~50%的数值偏差
AvgRowLength uint64 // 平均行长度 AvgRowLength []byte // 平均行长度
// MyISAM: Data_length 为数据文件的大小,单位为 bytes // MyISAM: Data_length 为数据文件的大小,单位为 bytes
// InnoDB: Data_length 为聚簇索引分配的近似内存量,单位为 bytes, 计算方式为聚簇索引数量乘以 InnoDB 页面大小 // InnoDB: Data_length 为聚簇索引分配的近似内存量,单位为 bytes, 计算方式为聚簇索引数量乘以 InnoDB 页面大小
// 其他不同的存储引擎中该值的意义可能不尽相同 // 其他不同的存储引擎中该值的意义可能不尽相同
DataLength uint64 DataLength []byte
// MyISAM: Max_data_length 为数据文件长度的最大值。这是在给定使用的数据指针大小的情况下,可以存储在表中的数据的最大字节数 // MyISAM: Max_data_length 为数据文件长度的最大值。这是在给定使用的数据指针大小的情况下,可以存储在表中的数据的最大字节数
// InnoDB: 未使用 // InnoDB: 未使用
// 其他不同的存储引擎中该值的意义可能不尽相同 // 其他不同的存储引擎中该值的意义可能不尽相同
MaxDataLength uint64 MaxDataLength []byte
// MyISAM: Index_length 为 index 文件的大小,单位为 bytes // MyISAM: Index_length 为 index 文件的大小,单位为 bytes
// InnoDB: Index_length 为非聚簇索引分配的近似内存量,单位为 bytes,计算方式为非聚簇索引数量乘以 InnoDB 页面大小 // InnoDB: Index_length 为非聚簇索引分配的近似内存量,单位为 bytes,计算方式为非聚簇索引数量乘以 InnoDB 页面大小
// 其他不同的存储引擎中该值的意义可能不尽相同 // 其他不同的存储引擎中该值的意义可能不尽相同
IndexLength uint64 IndexLength []byte
DataFree uint64 // 已分配但未使用的字节数 DataFree []byte // 已分配但未使用的字节数
AutoIncrement []byte // 下一个自增值 AutoIncrement []byte // 下一个自增值
CreateTime []byte // 创建时间 CreateTime []byte // 创建时间
UpdateTime []byte // 最近一次更新时间,该值不准确 UpdateTime []byte // 最近一次更新时间,该值不准确
......
...@@ -38,16 +38,15 @@ func TestShowTableStatus(t *testing.T) { ...@@ -38,16 +38,15 @@ func TestShowTableStatus(t *testing.T) {
} }
pretty.Println(ts) pretty.Println(ts)
// FIXME: too much column NULL ABLE connTest.Database = "sakila"
//connTest.Database = "sakila" ts, err = connTest.ShowTableStatus("actor_info")
//ts, err = connTest.ShowTableStatus("actor_info") if err != nil {
//if err != nil { t.Error("ShowTableStatus Error: ", err)
// t.Error("ShowTableStatus Error: ", err) }
//} if string(ts.Rows[0].Comment) != "VIEW" {
//if string(ts.Rows[0].Comment) != "VIEW" { t.Error("actor_info should be VIEW", ts.Rows[0].Comment)
// t.Error("actor_info should be VIEW", ts.Rows[0].Comment) }
//} pretty.Println(ts)
//pretty.Println(ts)
connTest.Database = orgDatabase connTest.Database = orgDatabase
common.Log.Debug("Exiting function: %s", common.GetFunctionName()) common.Log.Debug("Exiting function: %s", common.GetFunctionName())
} }
......
...@@ -259,14 +259,13 @@ func TestCreateTable(t *testing.T) { ...@@ -259,14 +259,13 @@ func TestCreateTable(t *testing.T) {
"rental", "rental",
"staff", "staff",
"store", "store",
// FIXME: SUPPORT VIEW "staff_list",
//"staff_list", "customer_list",
//"customer_list", "actor_info",
//"actor_info", "sales_by_film_category",
//"sales_by_film_category", "sales_by_store",
//"sales_by_store", "nicer_but_slower_film_list",
//"nicer_but_slower_film_list", "film_list",
//"film_list",
} }
for _, table := range tables { for _, table := range tables {
err := vEnv.createTable(rEnv, table) err := vEnv.createTable(rEnv, table)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册