Skip to content

Commit 47285a5

Browse files
authored
[no-release-notes] stats iter types edit (#2848)
* [no-release-notes] stats iter types edit * cleanup names * better empty row check * mcv checks before strconv
1 parent df44c73 commit 47285a5

File tree

7 files changed

+16
-11
lines changed

7 files changed

+16
-11
lines changed

memory/stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type StatsProv struct {
4343

4444
var _ sql.StatsProvider = (*StatsProv)(nil)
4545

46-
func (s *StatsProv) RefreshTableStats(ctx *sql.Context, table sql.Table, db string) error {
46+
func (s *StatsProv) AnalyzeTable(ctx *sql.Context, table sql.Table, db string) error {
4747
// non-Dolt would sample the table to get estimate of unique and histogram
4848
iat, ok := table.(sql.IndexAddressableTable)
4949
if !ok {

sql/analyzer/catalog.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ func (c *Catalog) TableFunction(ctx *sql.Context, name string) (sql.TableFunctio
405405
return nil, false
406406
}
407407

408-
func (c *Catalog) RefreshTableStats(ctx *sql.Context, table sql.Table, db string) error {
409-
return c.StatsProvider.RefreshTableStats(ctx, table, db)
408+
func (c *Catalog) AnalyzeTable(ctx *sql.Context, table sql.Table, db string) error {
409+
return c.StatsProvider.AnalyzeTable(ctx, table, db)
410410
}
411411

412412
func (c *Catalog) GetTableStats(ctx *sql.Context, db string, table sql.Table) ([]sql.Statistic, error) {

sql/catalog_map.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (t MapCatalog) GetTableStats(ctx *Context, db string, table Table) ([]Stati
116116
panic("implement me")
117117
}
118118

119-
func (t MapCatalog) RefreshTableStats(ctx *Context, table Table, db string) error {
119+
func (t MapCatalog) AnalyzeTable(ctx *Context, table Table, db string) error {
120120
//TODO implement me
121121
panic("implement me")
122122
}

sql/rowexec/other_iters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (itr *analyzeTableIter) Next(ctx *sql.Context) (sql.Row, error) {
4040

4141
msgType := "status"
4242
msgText := "OK"
43-
err := itr.stats.RefreshTableStats(ctx, t, itr.db)
43+
err := itr.stats.AnalyzeTable(ctx, t, itr.db)
4444
if err != nil {
4545
msgType = "Error"
4646
msgText = err.Error()

sql/statistics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ type StatisticsTable interface {
3838
type StatsProvider interface {
3939
// GetTableStats returns all statistics for the table
4040
GetTableStats(ctx *Context, db string, table Table) ([]Statistic, error)
41-
// RefreshTableStats updates all statistics associated with a given table
42-
RefreshTableStats(ctx *Context, table Table, db string) error
41+
// AnalyzeTable updates all statistics associated with a given table
42+
AnalyzeTable(ctx *Context, table Table, db string) error
4343
// SetStats updates or overwrites a set of table statistics
4444
SetStats(ctx *Context, stats Statistic) error
4545
// GetStats fetches a set of statistics for a set of table columns

sql/stats/iter.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ func (s *statsIter) updateIndexMeta() {
8282
}
8383
s.types = dStat.Types()
8484
s.typesStr = typesB.String()
85-
s.lowerBoundStr = StringifyKey(dStat.LowerBound(), dStat.Types())
85+
if len(dStat.LowerBound()) > 0 {
86+
s.lowerBoundStr = StringifyKey(dStat.LowerBound(), dStat.Types())
87+
}
8688
s.colsStr = strings.Join(dStat.Columns(), ",")
8789
s.qual = dStat.Qualifier()
8890
s.createdAt = dStat.CreatedAt()
@@ -104,7 +106,9 @@ func (s *statsIter) bucketToRow(i int, bucket sql.HistogramBucket) (sql.Row, err
104106
mcvs := make([]string, mcvCnt)
105107

106108
for i, mcv := range bucket.Mcvs() {
107-
mcvs[i] = StringifyKey(mcv, s.types)
109+
if len(mcv) > 0 {
110+
mcvs[i] = StringifyKey(mcv, s.types)
111+
}
108112
}
109113

110114
return sql.Row{
@@ -139,7 +143,8 @@ func ParseRow(rowStr string, types []sql.Type) (sql.Row, error) {
139143
func StringifyKey(r sql.Row, typs []sql.Type) string {
140144
b := strings.Builder{}
141145
sep := ""
142-
for i, v := range r {
146+
for i := range typs {
147+
v := r[i]
143148
typ := typs[i]
144149
if _, ok := typ.(sql.StringType); ok {
145150
typ = types.LongText

test/test_catalog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (c *Catalog) GetTableStats(ctx *sql.Context, db string, table sql.Table) ([
179179
panic("implement me")
180180
}
181181

182-
func (c *Catalog) RefreshTableStats(ctx *sql.Context, table sql.Table, db string) error {
182+
func (c *Catalog) AnalyzeTable(ctx *sql.Context, table sql.Table, db string) error {
183183
//TODO implement me
184184
panic("implement me")
185185
}

0 commit comments

Comments
 (0)