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

ddl: basic support for invisible index #15366

Merged
merged 8 commits into from
Mar 17, 2020
Merged

Conversation

Deardrops
Copy link
Contributor

@Deardrops Deardrops commented Mar 13, 2020

What problem does this PR solve?

Part of #9246

What is changed and how it works?

  1. Store Invisible Flag in these statements:

    • CREATE TABLE t (a INT, INDEX (a) INVISIBLE)
    • CREATE INDEX a on t(a) INVISIBLE
    • ALTER TABLE t ADD INDEX a INVISIBLE
  2. Add a new column Visible in SHOW INDEX:

mysql> show index from t;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| t     |          1 | a        |            1 | a           | A         |           0 |     NULL | NULL   | YES  | BTREE      |         |               | NO      | NULL       |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
1 row in set (0.00 sec)
  1. Add a new column IS_VISIBLE in table information_schema.statistics:
mysql> select table_name, index_name, is_visible from information_schema.statistics where table_name = "t";
+------------+------------+------------+
| table_name | index_name | is_visible |
+------------+------------+------------+
| t          | a          | NO         |
+------------+------------+------------+
1 row in set (0.00 sec)

  1. Show Invisible Index in SHOW CREATE TABLE
mysql> show create table t;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                     |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `a` int(11) DEFAULT NULL,
  KEY `a` (`a`) /*!80000 INVISIBLE */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Check List

Tests

  • Unit test

Code changes

  • Has exported variable/fields change

Side effects

  • Increased code complexity

Related changes

  • None

Release note

  • None

@Deardrops Deardrops added the sig/sql-infra SIG: SQL Infra label Mar 13, 2020
@Deardrops Deardrops requested review from a team as code owners March 13, 2020 11:32
@ghost ghost requested review from qw4990, SunRunAway, francis0407, winoros and a team and removed request for a team March 13, 2020 11:32
@github-actions github-actions bot added the sig/execution SIG execution label Mar 13, 2020
@Deardrops
Copy link
Contributor Author

/rebuild

@codecov
Copy link

codecov bot commented Mar 13, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@8aad651). Click here to learn what that means.
The diff coverage is 100%.

@@             Coverage Diff             @@
##             master     #15366   +/-   ##
===========================================
  Coverage          ?   80.4052%           
===========================================
  Files             ?        502           
  Lines             ?     133495           
  Branches          ?          0           
===========================================
  Hits              ?     107337           
  Misses            ?      17729           
  Partials          ?       8429

@AilinKid AilinKid self-requested a review March 13, 2020 12:46
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

Rest seems ok

@@ -852,6 +863,9 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T
cols = append(cols, colInfo)
}
fmt.Fprintf(buf, "(%s)", strings.Join(cols, ","))
if idxInfo.Invisible {
fmt.Fprintf(buf, ` /*!80000 INVISIBLE */`)
Copy link
Contributor

Choose a reason for hiding this comment

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

How does comment 80000 come?any reference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I do not find any reference for the /*!80000 INVISIBLE */,
but when test in MySQL 8.0, it does have this behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

make sense

@Deardrops
Copy link
Contributor Author

/run-all-tests tidb-test=pr/1004

@SunRunAway SunRunAway removed their request for review March 16, 2020 06:13
Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

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

LGTM

@Deardrops Deardrops added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 16, 2020
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

fix the conflicts

Copy link
Contributor

@djshow832 djshow832 left a comment

Choose a reason for hiding this comment

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

LGTM

@djshow832 djshow832 added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 17, 2020
@Deardrops Deardrops added status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Mar 17, 2020
Copy link
Member

@francis0407 francis0407 left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added the status/can-merge Indicates a PR has been approved by a committer. label Mar 17, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Mar 17, 2020

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Mar 17, 2020

@Deardrops merge failed.

@Deardrops
Copy link
Contributor Author

/run-all-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution sig/sql-infra SIG: SQL Infra status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants