From 50d20d8cd0263c035a9146bcc916674961429c35 Mon Sep 17 00:00:00 2001
From: lihaowei <haoweili35@gmail.com>
Date: Thu, 22 Jul 2021 14:58:57 +0800
Subject: [PATCH] add admin check index

---
 executor/admin_test.go     | 2 ++
 planner/core/preprocess.go | 6 ++++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/executor/admin_test.go b/executor/admin_test.go
index da555ef999578..39c4794f8e19c 100644
--- a/executor/admin_test.go
+++ b/executor/admin_test.go
@@ -86,6 +86,8 @@ func (s *testSuite5) TestAdminCheckIndexInTemporaryMode(c *C) {
 	tk.MustExec("insert temporary_admin_test (c1, c2) values (1, 1), (2, 2), (3, 3);")
 	_, err := tk.Exec("admin check table temporary_admin_test;")
 	c.Assert(err.Error(), Equals, core.ErrOptOnTemporaryTable.GenWithStackByArgs("admin check table").Error())
+	_, err = tk.Exec("admin check index temporary_admin_test c1;")
+	c.Assert(err.Error(), Equals, core.ErrOptOnTemporaryTable.GenWithStackByArgs("admin check index").Error())
 	tk.MustExec("drop table if exists temporary_admin_test;")
 
 	tk.MustExec("drop table if exists non_temporary_admin_test;")
diff --git a/planner/core/preprocess.go b/planner/core/preprocess.go
index 2ca80eb5a24a2..53e0e227dc896 100644
--- a/planner/core/preprocess.go
+++ b/planner/core/preprocess.go
@@ -680,11 +680,13 @@ func (p *preprocessor) checkAdminCheckTableGrammar(stmt *ast.AdminStmt) {
 			return
 		}
 		tempTableType := tableInfo.Meta().TempTableType
-		if (stmt.Tp == ast.AdminCheckTable || stmt.Tp == ast.AdminChecksumTable) && tempTableType != model.TempTableNone {
+		if (stmt.Tp == ast.AdminCheckTable || stmt.Tp == ast.AdminChecksumTable || stmt.Tp == ast.AdminCheckIndex) && tempTableType != model.TempTableNone {
 			if stmt.Tp == ast.AdminChecksumTable {
 				p.err = ErrOptOnTemporaryTable.GenWithStackByArgs("admin checksum table")
-			} else {
+			} else if stmt.Tp == ast.AdminCheckTable {
 				p.err = ErrOptOnTemporaryTable.GenWithStackByArgs("admin check table")
+			} else {
+				p.err = ErrOptOnTemporaryTable.GenWithStackByArgs("admin check index")
 			}
 			return
 		}