Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document what ADMIN CHECK does #13375

Merged
merged 9 commits into from
Aug 30, 2023
19 changes: 18 additions & 1 deletion sql-statements/sql-statement-admin-check-table-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,24 @@ category: reference

# ADMIN CHECK [TABLE|INDEX]

The `ADMIN CHECK [TABLE|INDEX]` statement checks for data consistency of tables and indexes. It does not support checking [FOREIGN KEY constraints](/foreign-key.md).
The `ADMIN CHECK [TABLE|INDEX]` statement checks for data consistency of tables and indexes.

It does not support the following:

- Checking [FOREIGN KEY constraints](/foreign-key.md).
- Checking the PRIMARY KEY index if a [clustered primary key](/clustered-indexes.md) is used.

If `ADMIN CHECK [TABLE|INDEX]` finds any issues, you can resolve them by dropping and recreating the index. If the issue is not resolved, you can report an [issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if GitHub issue is still a recommended channel for support. Maybe we should link to support resources instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is a common sentence in SQL Statement docs:

$ git grep -l 'github.com/pingcap/tidb/issues/new/choose'
dr-secondary-cluster.md
sql-statements/sql-statement-admin-check-table-index.md
sql-statements/sql-statement-alter-database.md
sql-statements/sql-statement-create-database.md
sql-statements/sql-statement-create-role.md
sql-statements/sql-statement-create-table-like.md
sql-statements/sql-statement-deallocate.md
sql-statements/sql-statement-delete.md
sql-statements/sql-statement-do.md
sql-statements/sql-statement-drop-database.md
sql-statements/sql-statement-drop-role.md
sql-statements/sql-statement-drop-view.md
sql-statements/sql-statement-execute.md
sql-statements/sql-statement-flush-privileges.md
sql-statements/sql-statement-grant-role.md
sql-statements/sql-statement-insert.md
sql-statements/sql-statement-load-data.md
sql-statements/sql-statement-prepare.md
sql-statements/sql-statement-rename-index.md
sql-statements/sql-statement-rename-table.md
sql-statements/sql-statement-rename-user.md
sql-statements/sql-statement-replace.md
sql-statements/sql-statement-revoke-role.md
sql-statements/sql-statement-set-default-role.md
sql-statements/sql-statement-set-names.md
sql-statements/sql-statement-set-password.md
sql-statements/sql-statement-set-role.md
sql-statements/sql-statement-show-character-set.md
sql-statements/sql-statement-show-collation.md
sql-statements/sql-statement-show-columns-from.md
sql-statements/sql-statement-show-create-database.md
sql-statements/sql-statement-show-create-table.md
sql-statements/sql-statement-show-databases.md
sql-statements/sql-statement-show-errors.md
sql-statements/sql-statement-show-grants.md
sql-statements/sql-statement-show-indexes.md
sql-statements/sql-statement-show-plugins.md
sql-statements/sql-statement-show-privileges.md
sql-statements/sql-statement-show-table-status.md
sql-statements/sql-statement-show-tables.md
sql-statements/sql-statement-show-variables.md
sql-statements/sql-statement-show-warnings.md
sql-statements/sql-statement-shutdown.md
sql-statements/sql-statement-truncate.md
sql-statements/sql-statement-use.md
troubleshoot-tidb-cluster.md

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #14648 for this.


## Principles

The `ADMIN CHECK TABLE` statement takes the following steps to check the table:

1. For each index, it checks if the number of records in the index is the same as that in the table.

2. For each index, it loops over the values in each row and compares the values with that in the table.

If you use the `ADMIN CHECK INDEX` statement, it only checks the specified index.

## Synopsis

Expand Down