您可以使用CHECK GLOBAL INDEX語句檢查主表和索引表的數據是否完全一致,并修訂不一致的數據。
語法
CHECK GLOBAL INDEX gsi_name [ON tbl_name] [extra_cmd]
參數 | 說明 |
---|---|
gsi_name |
需要校驗的全局二級索引名。 |
tbl_name |
全局二級索引所在的主表,非必選。若您輸入具體主表名稱,將會檢查全局二級索引表和主表間的索引關系是否正確。 |
extra_cmd |
保留的額外指令,目前支持如下指令:
|
說明
- 對全局二級索引表中的數據進行校驗或訂正時會占用一定的系統資源,特別是訂正操作會對主表或索引表內數據分批加鎖并訂正,建議您在業務低谷期進行操作。更多關于GSI的使用方式,請參見全局二級索引。
- 對大表的GSI校驗可能會花費較多的時間,可以使用HINT指定PURE_ASYNC_DDL_MODE,以純異步模式執行DDL語句。
示例
- 您可以使用如下語句進行校驗:
CHECK GLOBAL INDEX `g_i_check`;
- 若校驗沒有發現錯誤,則返回如下結果:
+-------------+------------+--------+-------------+-----------------------------+ | GSI_TABLE | ERROR_TYPE | STATUS | PRIMARY_KEY | DETAILS | +-------------+------------+--------+-------------+-----------------------------+ | `g_i_check` | SUMMARY | -- | -- | OK (7025/7025 rows checked) | +-------------+------------+--------+-------------+-----------------------------+ 1 row in set (1.40 sec)
- 若校驗發現錯誤,則返回如下結果:
+-------------+------------+--------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | GSI_TABLE | ERROR_TYPE | STATUS | PRIMARY_KEY | DETAILS | +-------------+------------+--------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | `g_i_check` | ORPHAN | FOUND | (100722) | {"GSI":{"id":100722,"c_timestamp_6":"2000-01-01 00:00:00.000000","c_timestamp_3":"2000-01-01 00:00:00.000","c_timestamp_1":"2000-01-01 00:00:00.0","c_binary":"OTkAAAAAAAAAAA==","c_int_32":271}} | | `g_i_check` | CONFLICT | FOUND | (108710) | {"Primary":{"id":108710,"c_timestamp_6":"2000-01-01 00:00:00.000000","c_timestamp_3":"2000-01-01 00:00:00.000","c_timestamp_1":"2000-01-01 00:00:00.0","c_year":"2000","c_int_32":255},"GSI":{"c_int_32_un":123456,"id":108710,"c_timestamp_6":"2000-01-01 00:00:00.000000","c_timestamp_3":"2000-01-01 00:00:00.000","c_timestamp_1":"2000-01-01 00:00:00.0","c_year":"2000","c_int_32":255}} | | `g_i_check` | MISSING | FOUND | (100090) | {"Primary":{"id":100090,"c_timestamp_6":"2000-01-01 00:00:00.000000","c_timestamp_3":"2000-01-01 00:00:00.000","c_timestamp_1":"2000-01-01 00:00:00.0","c_blob_tiny":"YeS4reWbvWE=","c_int_32":280}} | | `g_i_check` | SUMMARY | -- | -- | 3 error found (7025/7025 rows checked) | +-------------+------------+--------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 4 rows in set (1.92 sec)
說明 如果數據存在多種錯誤,同一行數據會報多個ERROR_TYPE值。
- 若校驗沒有發現錯誤,則返回如下結果:
- 您可以使用如下語句進行訂正:
CHECK GLOBAL INDEX g_i_check CORRECTION_BASED_ON_PRIMARY;
返回結果如下:
+-------------+------------+--------+-------------+------------------------------------------------------------------------+ | GSI_TABLE | ERROR_TYPE | STATUS | PRIMARY_KEY | DETAILS | +-------------+------------+--------+-------------+------------------------------------------------------------------------+ | `g_i_check` | SUMMARY | -- | -- | Done. Use SQL: { CHECK GLOBAL INDEX `g_i_check` SHOW; } to get result. | +-------------+------------+--------+-------------+------------------------------------------------------------------------+ 1 row in set (1.40 sec)
- 您可以使用如下語句查看最近一次校驗或訂正的報告:
CHECK GLOBAL INDEX `g_i_check` SHOW;
返回結果如下:
+-------------+------------+----------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | GSI_TABLE | ERROR_TYPE | STATUS | PRIMARY_KEY | DETAILS | +-------------+------------+----------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | `g_i_check` | MISSING | REPAIRED | (100090) | {"Primary":{"id":100090,"c_timestamp_6":"2000-01-01 00:00:00.000000","c_timestamp_3":"2000-01-01 00:00:00.000","c_timestamp_1":"2000-01-01 00:00:00.0","c_blob_tiny":"YeS4reWbvWE=","c_int_32":280}} | | `g_i_check` | CONFLICT | REPAIRED | (108710) | {"Primary":{"id":108710,"c_timestamp_6":"2000-01-01 00:00:00.000000","c_timestamp_3":"2000-01-01 00:00:00.000","c_timestamp_1":"2000-01-01 00:00:00.0","c_year":"2000","c_int_32":255},"GSI":{"c_int_32_un":123456,"id":108710,"c_timestamp_6":"2000-01-01 00:00:00.000000","c_timestamp_3":"2000-01-01 00:00:00.000","c_timestamp_1":"2000-01-01 00:00:00.0","c_year":"2000","c_int_32":255}} | | `g_i_check` | ORPHAN | REPAIRED | (100722) | {"GSI":{"id":100722,"c_timestamp_6":"2000-01-01 00:00:00.000000","c_timestamp_3":"2000-01-01 00:00:00.000","c_timestamp_1":"2000-01-01 00:00:00.0","c_binary":"OTkAAAAAAAAAAA==","c_int_32":271}} | | `g_i_check` | SUMMARY | -- | -- | 3 error found (7025/7026 rows checked.) Finish time: 2020-01-13 14:41:51.0 | +-------------+------------+----------+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 4 rows in set (0.02 sec)
列名 | 說明 |
---|---|
GSI_TABLE | 全局二級索引名。 |
ERROR_TYPE | 錯誤類型,取值范圍如下:
|
STATUS | 狀態,取值范圍如下:
|
PRIMARY_KEY | 主鍵。 |
DETAILS | 錯誤的詳細信息。 |