Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 October MySQL: Increase the Performance of CREATE INDEX and DROP INDEX for InnoDB

MySQL: Increase the Performance of CREATE INDEX and DROP INDEX for InnoDB

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In MySQL 5.5 and higher version, Index performance has improved a lot.
MySQL InnoDB engine has basically two types of index, Primary clustered index and Secondary indexes.

When we are adding or dropping a clustered index, It is copying the data, and creating a new copy of the table.
Yes, this is the basic nature of any clustered index because It also contains the data value.

But, what about Secondary Index of MySQL InnoDB ?

When we are adding or dropping a secondary index, internally It scans the table, and sorts the rows using memory buffers in order by the values of the secondary index key columns.

Once a CREATE INDEX or ALTER TABLE statement starts to create InnoDB secondary index, we can only read the table, but cannot update the table.

Now Imagine, that we have a table with billions of data and now we require to add few more secondary indexes.
I have noticed that, most of the database developers create individual CREATE INDEX statement and execute each for creating require indexes.

We should not do this way because every CREATE INDEX statement require clustered index scan and other sorting related operation which actually degrade the performance of CREATE or DROP secondary index.

If we are adding or dropping multiple Indexes at a time, We can increase the performance of CREATE INDEX and DROP INDEX by executing using one single ALTER TABLE command.

If we are dealing with bulk-insert operation, we should create require indexes after data insertion which increase the performance of bulk-insertion.

For you guys, small demonstration to add or drop multiple indexes using one ALTER COMMAND.

Create a sample table:

1
2
3
4
5
6
7
CREATE TABLE tbl_Employees
(
EmpID INT PRIMARY KEY
,EmpName VARCHAR(50)
,EmpSalary INT
,EmpGrade CHAR(1)
);

Insert few sample records:

1
2
3
4
INSERT INTO tbl_Employees VALUES
(1,'Anvesh',90000,'A'),(2,'Neevan',120000,'B')
,(3,'Roy',60000,'B'),(4,'Mahi',140000,'A')
,(5,'Martin',50000,'D'),(6,'Eric',80000,'C');

One ALTER command to add multiple Indexes on Table:

1
2
ALTER TABLE tbl_Employees
ADD INDEX (EmpName), ADD INDEX (EmpGrade);

One ALTER command to drop multiple Indexes on Table:

1
2
ALTER TABLE tbl_Employees
DROP INDEX EmpName, DROP INDEX EmpGrade;

Oct 14, 2016Anvesh Patel
MySQL 5.7: How to create an Index on JSON Data Type ColumnMySQL: UDF to SELECT value from a Comma Separated String at any position
Anvesh Patel
Anvesh Patel

Database Engineer

October 14, 2016 MySQLalter, Anvesh Patel, database, database research and development, dbrnd, Increase Index Performance, index, MySQL, MySQL Command, MySQL Database Administrator, MySQL Database Designing, MySQL Database Programming, MySQL Error, MySQL Performance Tunning, MySQL Query, MySQL Tips and Tricks
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....