@@ -30,45 +30,69 @@ func (e *ShowExec) fetchShowStatsMeta() error {
30
30
dbs := do .InfoSchema ().AllSchemas ()
31
31
for _ , db := range dbs {
32
32
for _ , tbl := range db .Tables {
33
- statsTbl := h .GetTableStats (tbl )
34
- if ! statsTbl .Pseudo {
35
- e .appendRow ([]interface {}{
36
- db .Name .O ,
37
- tbl .Name .O ,
38
- e .versionToTime (statsTbl .Version ),
39
- statsTbl .ModifyCount ,
40
- statsTbl .Count ,
41
- })
33
+ pi := tbl .GetPartitionInfo ()
34
+ if pi == nil {
35
+ e .appendTableForStatsMeta (db .Name .O , tbl .Name .O , "" , h .GetTableStats (tbl ))
36
+ } else {
37
+ for _ , def := range pi .Definitions {
38
+ e .appendTableForStatsMeta (db .Name .O , tbl .Name .O , def .Name .O , h .GetPartitionStats (tbl , def .ID ))
39
+ }
42
40
}
43
41
}
44
42
}
45
43
return nil
46
44
}
47
45
46
+ func (e * ShowExec ) appendTableForStatsMeta (dbName , tblName , partitionName string , statsTbl * statistics.Table ) {
47
+ if statsTbl .Pseudo {
48
+ return
49
+ }
50
+ e .appendRow ([]interface {}{
51
+ dbName ,
52
+ tblName ,
53
+ partitionName ,
54
+ e .versionToTime (statsTbl .Version ),
55
+ statsTbl .ModifyCount ,
56
+ statsTbl .Count ,
57
+ })
58
+ }
59
+
48
60
func (e * ShowExec ) fetchShowStatsHistogram () error {
49
61
do := domain .GetDomain (e .ctx )
50
62
h := do .StatsHandle ()
51
63
dbs := do .InfoSchema ().AllSchemas ()
52
64
for _ , db := range dbs {
53
65
for _ , tbl := range db .Tables {
54
- statsTbl := h .GetTableStats (tbl )
55
- if ! statsTbl .Pseudo {
56
- for _ , col := range statsTbl .Columns {
57
- e .histogramToRow (db .Name .O , tbl .Name .O , col .Info .Name .O , 0 , col .Histogram , col .AvgColSize (statsTbl .Count ))
58
- }
59
- for _ , idx := range statsTbl .Indices {
60
- e .histogramToRow (db .Name .O , tbl .Name .O , idx .Info .Name .O , 1 , idx .Histogram , 0 )
66
+ pi := tbl .GetPartitionInfo ()
67
+ if pi == nil {
68
+ e .appendTableForStatsHistograms (db .Name .O , tbl .Name .O , "" , h .GetTableStats (tbl ))
69
+ } else {
70
+ for _ , def := range pi .Definitions {
71
+ e .appendTableForStatsHistograms (db .Name .O , tbl .Name .O , def .Name .O , h .GetPartitionStats (tbl , def .ID ))
61
72
}
62
73
}
63
74
}
64
75
}
65
76
return nil
66
77
}
67
78
68
- func (e * ShowExec ) histogramToRow (dbName string , tblName string , colName string , isIndex int , hist statistics.Histogram , avgColSize float64 ) {
79
+ func (e * ShowExec ) appendTableForStatsHistograms (dbName , tblName , partitionName string , statsTbl * statistics.Table ) {
80
+ if statsTbl .Pseudo {
81
+ return
82
+ }
83
+ for _ , col := range statsTbl .Columns {
84
+ e .histogramToRow (dbName , tblName , partitionName , col .Info .Name .O , 0 , col .Histogram , col .AvgColSize (statsTbl .Count ))
85
+ }
86
+ for _ , idx := range statsTbl .Indices {
87
+ e .histogramToRow (dbName , tblName , partitionName , idx .Info .Name .O , 1 , idx .Histogram , 0 )
88
+ }
89
+ }
90
+
91
+ func (e * ShowExec ) histogramToRow (dbName , tblName , partitionName , colName string , isIndex int , hist statistics.Histogram , avgColSize float64 ) {
69
92
e .appendRow ([]interface {}{
70
93
dbName ,
71
94
tblName ,
95
+ partitionName ,
72
96
colName ,
73
97
isIndex ,
74
98
e .versionToTime (hist .LastUpdateVersion ),
@@ -89,29 +113,41 @@ func (e *ShowExec) fetchShowStatsBuckets() error {
89
113
dbs := do .InfoSchema ().AllSchemas ()
90
114
for _ , db := range dbs {
91
115
for _ , tbl := range db .Tables {
92
- statsTbl := h .GetTableStats (tbl )
93
- if ! statsTbl .Pseudo {
94
- for _ , col := range statsTbl .Columns {
95
- err := e .bucketsToRows (db .Name .O , tbl .Name .O , col .Info .Name .O , 0 , col .Histogram )
96
- if err != nil {
97
- return errors .Trace (err )
98
- }
99
- }
100
- for _ , idx := range statsTbl .Indices {
101
- err := e .bucketsToRows (db .Name .O , tbl .Name .O , idx .Info .Name .O , len (idx .Info .Columns ), idx .Histogram )
102
- if err != nil {
103
- return errors .Trace (err )
104
- }
116
+ pi := tbl .GetPartitionInfo ()
117
+ if pi == nil {
118
+ e .appendTableForStatsBuckets (db .Name .O , tbl .Name .O , "" , h .GetTableStats (tbl ))
119
+ } else {
120
+ for _ , def := range pi .Definitions {
121
+ e .appendTableForStatsBuckets (db .Name .O , tbl .Name .O , def .Name .O , h .GetPartitionStats (tbl , def .ID ))
105
122
}
106
123
}
107
124
}
108
125
}
109
126
return nil
110
127
}
111
128
129
+ func (e * ShowExec ) appendTableForStatsBuckets (dbName , tblName , partitionName string , statsTbl * statistics.Table ) error {
130
+ if statsTbl .Pseudo {
131
+ return nil
132
+ }
133
+ for _ , col := range statsTbl .Columns {
134
+ err := e .bucketsToRows (dbName , tblName , partitionName , col .Info .Name .O , 0 , col .Histogram )
135
+ if err != nil {
136
+ return errors .Trace (err )
137
+ }
138
+ }
139
+ for _ , idx := range statsTbl .Indices {
140
+ err := e .bucketsToRows (dbName , tblName , partitionName , idx .Info .Name .O , len (idx .Info .Columns ), idx .Histogram )
141
+ if err != nil {
142
+ return errors .Trace (err )
143
+ }
144
+ }
145
+ return nil
146
+ }
147
+
112
148
// bucketsToRows converts histogram buckets to rows. If the histogram is built from index, then numOfCols equals to number
113
149
// of index columns, else numOfCols is 0.
114
- func (e * ShowExec ) bucketsToRows (dbName , tblName , colName string , numOfCols int , hist statistics.Histogram ) error {
150
+ func (e * ShowExec ) bucketsToRows (dbName , tblName , partitionName , colName string , numOfCols int , hist statistics.Histogram ) error {
115
151
isIndex := 0
116
152
if numOfCols > 0 {
117
153
isIndex = 1
@@ -128,6 +164,7 @@ func (e *ShowExec) bucketsToRows(dbName, tblName, colName string, numOfCols int,
128
164
e .appendRow ([]interface {}{
129
165
dbName ,
130
166
tblName ,
167
+ partitionName ,
131
168
colName ,
132
169
isIndex ,
133
170
i ,
@@ -146,20 +183,32 @@ func (e *ShowExec) fetchShowStatsHealthy() {
146
183
dbs := do .InfoSchema ().AllSchemas ()
147
184
for _ , db := range dbs {
148
185
for _ , tbl := range db .Tables {
149
- statsTbl := h .GetTableStats (tbl )
150
- if ! statsTbl .Pseudo {
151
- var healthy int64
152
- if statsTbl .ModifyCount < statsTbl .Count {
153
- healthy = int64 ((1.0 - float64 (statsTbl .ModifyCount )/ float64 (statsTbl .Count )) * 100.0 )
154
- } else if statsTbl .ModifyCount == 0 {
155
- healthy = 100
186
+ pi := tbl .GetPartitionInfo ()
187
+ if pi == nil {
188
+ e .appendTableForStatsHealthy (db .Name .O , tbl .Name .O , "" , h .GetTableStats (tbl ))
189
+ } else {
190
+ for _ , def := range pi .Definitions {
191
+ e .appendTableForStatsHealthy (db .Name .O , tbl .Name .O , def .Name .O , h .GetPartitionStats (tbl , def .ID ))
156
192
}
157
- e .appendRow ([]interface {}{
158
- db .Name .O ,
159
- tbl .Name .O ,
160
- healthy ,
161
- })
162
193
}
163
194
}
164
195
}
165
196
}
197
+
198
+ func (e * ShowExec ) appendTableForStatsHealthy (dbName , tblName , partitionName string , statsTbl * statistics.Table ) {
199
+ if statsTbl .Pseudo {
200
+ return
201
+ }
202
+ var healthy int64
203
+ if statsTbl .ModifyCount < statsTbl .Count {
204
+ healthy = int64 ((1.0 - float64 (statsTbl .ModifyCount )/ float64 (statsTbl .Count )) * 100.0 )
205
+ } else if statsTbl .ModifyCount == 0 {
206
+ healthy = 100
207
+ }
208
+ e .appendRow ([]interface {}{
209
+ dbName ,
210
+ tblName ,
211
+ partitionName ,
212
+ healthy ,
213
+ })
214
+ }
0 commit comments