(tctx *tcontext.Context, conn *BaseConn, meta TableMeta)
| 1048 | } |
| 1049 | |
| 1050 | func selectTiDBTableRegion(tctx *tcontext.Context, conn *BaseConn, meta TableMeta) (pkFields []string, pkVals [][]string, err error) { |
| 1051 | pkFields, _, err = selectTiDBRowKeyFields(tctx, conn, meta, checkTiDBTableRegionPkFields) |
| 1052 | if err != nil { |
| 1053 | return |
| 1054 | } |
| 1055 | |
| 1056 | var ( |
| 1057 | startKey, decodedKey sql.NullString |
| 1058 | rowID = -1 |
| 1059 | ) |
| 1060 | const ( |
| 1061 | tableRegionSQL = "SELECT START_KEY,tidb_decode_key(START_KEY) from INFORMATION_SCHEMA.TIKV_REGION_STATUS s WHERE s.DB_NAME = ? AND s.TABLE_NAME = ? AND IS_INDEX = 0 ORDER BY START_KEY;" |
| 1062 | tidbRowID = "_tidb_rowid=" |
| 1063 | ) |
| 1064 | dbName, tableName := meta.DatabaseName(), meta.TableName() |
| 1065 | logger := tctx.L().With(zap.String("database", dbName), zap.String("table", tableName)) |
| 1066 | err = conn.QuerySQL(tctx, func(rows *sql.Rows) error { |
| 1067 | rowID++ |
| 1068 | err = rows.Scan(&startKey, &decodedKey) |
| 1069 | if err != nil { |
| 1070 | return errors.Trace(err) |
| 1071 | } |
| 1072 | // first region's start key has no use. It may come from another table or might be invalid |
| 1073 | if rowID == 0 { |
| 1074 | return nil |
| 1075 | } |
| 1076 | if !startKey.Valid { |
| 1077 | logger.Debug("meet invalid start key", zap.Int("rowID", rowID)) |
| 1078 | return nil |
| 1079 | } |
| 1080 | if !decodedKey.Valid { |
| 1081 | logger.Debug("meet invalid decoded start key", zap.Int("rowID", rowID), zap.String("startKey", startKey.String)) |
| 1082 | return nil |
| 1083 | } |
| 1084 | pkVal, err2 := extractTiDBRowIDFromDecodedKey(tidbRowID, decodedKey.String) |
| 1085 | if err2 != nil { |
| 1086 | logger.Debug("cannot extract pkVal from decoded start key", |
| 1087 | zap.Int("rowID", rowID), zap.String("startKey", startKey.String), zap.String("decodedKey", decodedKey.String), log.ShortError(err2)) |
| 1088 | } else { |
| 1089 | pkVals = append(pkVals, []string{pkVal}) |
| 1090 | } |
| 1091 | return nil |
| 1092 | }, func() { |
| 1093 | pkFields = pkFields[:0] |
| 1094 | pkVals = pkVals[:0] |
| 1095 | }, tableRegionSQL, dbName, tableName) |
| 1096 | |
| 1097 | return pkFields, pkVals, errors.Trace(err) |
| 1098 | } |
| 1099 | |
| 1100 | func selectTiDBPartitionRegion(tctx *tcontext.Context, conn *BaseConn, dbName, tableName, partition string) (pkVals [][]string, err error) { |
| 1101 | var startKeys [][]string |
nothing calls this directly
no test coverage detected