当我们使用子查询时,可以使用复合索引。使用复合索引的优点是可以的。
加盟
筛选
选择中
以下是index的语法。
index(column_name1,column_name2,column_name3,column_name4,............................N)
让我们首先创建一个表,并在其中设置索引。
mysql> create table MultipleIndexDemo - > ( - > id int, - > FirstName varchar(100), - > LastName varchar(100), - > Address varchar(200), - > index(id,LastName,Address) - > );
检查索引是否成功创建。
mysql> show index from MultipleIndexDemo;
以下是输出。
+-------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | +-------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | multipleindexdemo | 1 | id | 1 | id | A | 0 | NULL | NULL | YES | BTREE | | | YES | | multipleindexdemo | 1 | id | 2 | LastName | A | 0 | NULL | NULL | YES | BTREE | | | YES | | multipleindexdemo | 1 | id | 3 | Address | A | 0 | NULL | NULL | YES | BTREE | | | YES | +-------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ 3 rows in set (0.18 sec)