
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Function-Based Index in MySQL
Function-based index wasn't possible in MySQL versions below 5.6. Firstly, to create function-based index in MySQL, we will create a table.
mysql> create table FunctionIndexDemo - > ( - > FirstName varchar(100) - > ); Query OK, 0 rows affected (0.70 sec)
Let us see the syntax to create a function based index.
create index index_name on yourTableName (column_name(IntegerSize));
Here is the query.
mysql> create index indFirstName on FunctionIndexDemo (FirstName(6)); Query OK, 0 rows affected (0.56 sec) Records: 0 Duplicates: 0 Warnings: 0
To check if the index is present.
mysql> SHOW INDEX FROM FunctionIndexDemo;
Here 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 | +-------------------+------------+--------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | functionindexdemo | 1 | indFirstName | 1 | FirstName | A | 0 | 6 | NULL | YES | BTREE | | | YES | +-------------------+------------+--------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ 1 row in set (0.24 sec)
Advertisements