
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
When should I use a composite index in MySQL?
The composite index can be used when we are using sub queries. The advantages of using composite index are in case of.
- Joining
- Filtering
- Selecting
The following is the syntax of index.
index(column_name1,column_name2,column_name3,column_name4,............................N)
Let us create a table first and within that we have set index.
mysql> create table MultipleIndexDemo - > ( - > id int, - > FirstName varchar(100), - > LastName varchar(100), - > Address varchar(200), - > index(id,LastName,Address) - > ); Query OK, 0 rows affected (0.57 sec)
To check if the indexes are created successfully.
mysql> show index from MultipleIndexDemo;
The following is the output.
+-------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | 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)
- Related Articles
- When should I use MySQL compressed protocol?
- MySQL Composite Index
- When Should I use Selenium Grid?
- When should I use the keyword ‘this’ in a Java class?
- When should I use a semicolon after curly braces in JavaScript?
- Which datatype should I use for flag in MySQL?
- When should I use an Inline script and when to use external JavaScript file?
- What is a smart pointer and when should I use it in C++?
- How should I display MySQL database that is currently in use?
- Should I use COUNT(*) to get all the records in MySQL?
- When should you use sets in Javascript?
- Which one should I use? The datetime or timestamp data type in MySQL?
- How MySQL evaluates when I use a conditional expression within SUM() function?
- Why should I use Hubspot?
- When should you use a class vs a struct in C++?

Advertisements