
- 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
Is it possible to have a 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)
- Related Articles
- Is it possible to have JavaScript split() start at index 1?
- Is it possible to have View and table with the same name in MySQL?
- Is it possible to handle Windows based pop-ups in Selenium?
- Is it possible to calculate a correlation in a MySQL query?
- How to get index in a sorted array based on iterator function in JavaScript?
- Is it possible to sort varchar data in ascending order that have both string and number values with MySQL?
- Is it possible to have a HTML SELECT/OPTION value as NULL using PHP?
- Is it possible to use UPDATE query with LIMIT in MySQL?
- How is it possible for a MySQL trigger to execute multiple statements?
- Insert the results of a MySQL select? Is it possible?
- Is it required to have a return a value from a JavaScript function?
- Is it possible to give arguments in the main() function in C language?
- Is it possible to add a set of elements in one cell with MySQL?
- Is it possible to delete everything after a 'space' in a MySQL field?
- How can it be possible to invert a string in MySQL?

Advertisements