MySQL FAQs
FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
Indexes
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
Errors
N.M.P.L. Company www.NearMePayday.Loan || 3-month (90 days)
Powered by MySQL
 
Home / Indexes / Question No: 139

What is partial-column and prefixed-column index or key in MySQL?

I am newbie to MySQL and learning about indexes terminology.  Can you explain that what is partial-column and prefixed-column index or key in MySQL?

Answer No: 139

An  index is  used if a particular column in your  table will be the focus of a considerable number of your SELECT  queries. For example, suppose an buyer profile table consists of four columns: a unique  id, first_name, last_name, and email address. You know that the majority of the searches will be specific to either the buyers ís last_name or the email address. You should create two indexes for these columns: one normal index for the last_name and a unique index for the email address, like so:

CREATE TABLE buyers (
 id INT UNSIGNED NOT NULL AUTO_INCREMENT,
first_name VARCHAR(35) NOT NULL,last_name VARCHAR(35) NOT NULL,
email VARCHAR(55) NOT NULL UNIQUE,
INDEX (last_name),
PRIMARY KEY(id)
);

To beautify the above idea and make it more useful, MySQL allows to create indexes on columns partially taking their specific length of characters, based on the idea that the first N characters of a given column often are enough to ensure uniqueness, where N is specified within the index creation parameters.  These type of indexes are also known as "partial-column indexes" or "Leftmost Prefixing".  Creating partial-column indexes requires less disk space and is considerably faster than indexing the entire column. Taking again the above example, you can imagine that using the first seven characters of the last_name suffices to ensure accurate retrieval:

CREATE TABLE buyers (
 id INT UNSIGNED NOT NULL AUTO_INCREMENT,
first_name VARCHAR(35) NOT NULL,last_name VARCHAR(35) NOT NULL,
email VARCHAR(55) NOT NULL UNIQUE,
INDEX ( last_name(5) ),
PRIMARY KEY(id)
);

Related MySQL FAQs to the Above FAQ

How-to-get-existing-indexes-of-the-table-in-MySQL How to get existing indexes of the table in MySQL?

What-is-index-terminology-or-concept-and-how-does-index-work-in-MySQL What is index terminology or concept and how does index work in MySQL?

How-many-types-of-indexes-or-keys-are-in-MySQL How many types of indexes or keys are in MySQL?

What-is-single-column-index-or-key-in-MySQL What is single column index or key in MySQL?

What-is-multi-column-index-or-key-in-MySQL What is multi column index or key in MySQL?

When-does-multi-column-index-come-into-use-in-MySQL When does multi column index come into use in MySQL?

What-are-best-practices-to-pick-columns-to-index What are best practices to pick columns to index?

What-are-advantages-and-disadvantages-of-indexes-in-MySQL What are advantages and disadvantages of indexes in MySQL?

How-to-remove-or-drop-indexes-in-MySQL How to remove or drop indexes in MySQL?

Is-it-possible-to-apply-more-than-one-keys-on-a-single-column Is it possible to apply more than one keys on a single column?

What-is-foreign-key-in-MySQL What is foreign key in MySQL?

About FAQs: Recently Added FAQs

About MySQL FAQs: Site Map | Bookmark Us | Recommend this Site to Your Friend | Contact Us

Useful Links: Wikipedia.org | Oracle.com | w3schools.com | www.php.net | Github.com

© 2021  www.mysqlfaqs.net
All rights reserved.