MCPcopy
hub / github.com/pingcap/tidb / updateSpecifiedTablesMeta

Function updateSpecifiedTablesMeta

dumpling/export/sql.go:251–361  ·  view source on GitHub ↗

updateSpecifiedTablesMeta updates DatabaseTables with correct table type and avg row size.

(tctx *tcontext.Context, db *sql.Conn, dbTables DatabaseTables, listType listTableType)

Source from the content-addressed store, hash-verified

249
250// updateSpecifiedTablesMeta updates DatabaseTables with correct table type and avg row size.
251func updateSpecifiedTablesMeta(tctx *tcontext.Context, db *sql.Conn, dbTables DatabaseTables, listType listTableType) error {
252 var (
253 schema, table, tableTypeStr string
254 tableType TableType
255 avgRowLength uint64
256 err error
257 )
258 switch listType {
259 case listTableByInfoSchema:
260 dbNames := make([]string, 0, len(dbTables))
261 for db := range dbTables {
262 dbNames = append(dbNames, fmt.Sprintf("'%s'", db))
263 }
264 query := fmt.Sprintf("SELECT TABLE_SCHEMA,TABLE_NAME,TABLE_TYPE,AVG_ROW_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA IN (%s)", strings.Join(dbNames, ","))
265 if err := simpleQueryWithArgs(tctx, db, func(rows *sql.Rows) error {
266 var (
267 sqlAvgRowLength sql.NullInt64
268 err2 error
269 )
270 if err2 = rows.Scan(&schema, &table, &tableTypeStr, &sqlAvgRowLength); err != nil {
271 return errors.Trace(err2)
272 }
273
274 tbls, ok := dbTables[schema]
275 if !ok {
276 return nil
277 }
278 for _, tbl := range tbls {
279 if tbl.Name == table {
280 tableType, err2 = ParseTableType(tableTypeStr)
281 if err2 != nil {
282 return errors.Trace(err2)
283 }
284 if sqlAvgRowLength.Valid {
285 avgRowLength = uint64(sqlAvgRowLength.Int64)
286 } else {
287 avgRowLength = 0
288 }
289 tbl.Type = tableType
290 tbl.AvgRowLength = avgRowLength
291 }
292 }
293 return nil
294 }, query); err != nil {
295 return errors.Annotatef(err, "sql: %s", query)
296 }
297 return nil
298 case listTableByShowFullTables:
299 for schema, tbls := range dbTables {
300 query := fmt.Sprintf("SHOW FULL TABLES FROM `%s`",
301 escapeString(schema))
302 if err := simpleQueryWithArgs(tctx, db, func(rows *sql.Rows) error {
303 var err2 error
304 if err2 = rows.Scan(&table, &tableTypeStr); err != nil {
305 return errors.Trace(err2)
306 }
307 for _, tbl := range tbls {
308 if tbl.Name == table {

Callers 1

prepareTableListToDumpFunction · 0.85

Calls 10

simpleQueryWithArgsFunction · 0.85
ParseTableTypeFunction · 0.85
WarnMethod · 0.80
escapeStringFunction · 0.70
JoinMethod · 0.65
ScanMethod · 0.65
QueryContextMethod · 0.65
StringMethod · 0.65
LMethod · 0.45

Tested by

no test coverage detected