SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Indexing the MySQL Index: Guide to
    Performance Enhancement

             Presented by – Sonali Minocha
                            OSSCube
Who Am I?

 Chief Technology Officer (MySQL)
           with OSSCube


MySQL Consulting, Implementation
          & Training


MySQL Certified DBA & Cluster DBA
What is Index?


                                A mechanism to locate and
 A database index is a data
                                   access data within a
structure that improves the
                                 database. An index may
   speed of data retrieval
                               quote one or more columns
 operations on a database
                               and be a means of enforcing
           table.
                               uniqueness on their values.
More about Index

• Speedy data retrieval.
  • SPEED of SELECTs
• Rapid random look ups.
• Efficient for
  Reporting, OLAP, read-intensive applications
  •However it is expensive for
  – Slows down writes
  – heavy write applications (OLTP) be careful
  – More disk space used
Properties
Index can be created on
:                         Index only contains key-
• One or more columns.       fields according to
                          which table is arranged.



                          Index may quote one or
                          more columns and be a
Index may be unique or
                            means of enforcing
     non-unique.
                            uniqueness of their
                                 values.
EMPLOYEE TABLE
EMPLOYEE ID   FIRSTNAME   LASTNAME   AGE   SALARY   GENDER


001           Ashish      Kataria    25    10000    M

002           Rony        Felix      28    20000    M

003           Namita      Misra      24    10000    F

004           Ankur       Aeran      30    25000    M

005           Priyanka    Jain       30    20000    F

006           Pradeep     Pandey     31    30000    M

007           Pankaj      Gupta      25    12000    M

008           Ankit       Garg       30    15000    M
Cont.
In this table if we have to search for employee whose name is
Rony then code will look like :
For each row in table
         if row[2] = 'Rony' then
           results.append[row]
      Else
      movenext
So we checking each now for condition.
HOW DATABASE INDEXES WORK ?


• Lets assume we have a table of data like this:
Type Of Indexes


                 Concatenated
Column Index                     Covering Index
                    Index


                        Clustered/Non-
        Partial Index
                        clustered Index
Column Index


                       Only those query will
  Index on a single
                       be optimized which
      column
                       satisfy your criteria.




        Eg:
                       By adding an index to
           SELECT
                         employeeid, the
employeeid, firstnam
                       query is optimized to
        e
                        only look at records
  FROM Employee
                         that satisfy your
       WHERE
                              criteria.
 employeeid = 001
Concatenated Index


Index on multiple      Use appropriate index.
    columns.                     :



     SELECT employeeid, lastname
       FROM Employee
       WHERE employeeid = 002
       AND lastname = ‘Felix’;
Covering Index
                                     The benefit of a covering
                                 index is that the lookup of the
                                    various B-Tree index pages
Covers all columns in a query.
                                      necessarily satisfies the
                                  query, and no additional data
                                   page lookups are necessary.



          SELECT employeeid
            FROM Employee
            WHERE employeeid = 001
Partial Index
 Subset of a column for the index.
 Use on CHAR, VARCHAR,TEXT etc.
 Creating a partial index may greatly reduce the size of the
  index, and minimize the additional data lookups required.
     Create table t ( name char(255) , INDEX ( name(15) ) );
 Eg:-SELECT employeeid, firstname, lastname
       FROM Employee WHERE lastname like ‘A%’

  We should add an index to lastname to improve
  performance.
Clustered vs. Non-clustered
 Describes whether the data records are stored
  on disk in a sorted order
MyISAM - non clustered.
      InnoDB - Clustered.
 Secondary indexes built upon the clustering
 key
Primary Index is added to all secondary index.

Because the data resides within the leaf nodes of index, more space in memory needed to search through same amount of records
How Hash Function Works
How it can be faster?
If we create HASH TABLE. The key                    of
hash table would be based on
empnameand the values would be
pointer to the database row.
This is Hash Index:
   • Hash index are good for equality searches.
   • Hash index are not good for index searches.
So what should be the solution for Range Searches?
B-Tree
30 0X775800


                                                                   Age Location of the
                                                                       data
  B-Tree/ Binary tree: Stores data in
            ordered way.
                                      Nodes in B-Tree
                                      contains a index
                                      field and a
                                      pointer to a
      Allows                          data row.
  logarithmic                         • So like in above      Each node takes
                   It allows faster                                             Single disk
selections, inser                       example if we           up one disk
                  range searches.                                               operation.
    tions and                           create an index on         block.
    deletion.                           age the node of B-
                                        tree will look like
B-Tree                        003    006
Diagram


       001   002              004    005              008     007




 EMPLOYEE ID       FIRSTNAME        LASTNAME   AGE   SALARY         GENDER

 001               Ashish           Kataria    25    10000          M

 002               Rony             Felix      28    20000          M

 003               Namita           Misra      24    10000          F

 004               Ankur            Aeran      30    25000          M

 005               Priyanka         Jain       30    20000          F

 006               Pradeep          Pandey     31    30000          M

 007               Pankaj           Gupta      25    12000          M

 008               Ankit            Garg       30    15000          M
R-Tree
MySQL supports any other type of index called Spatial Index. Spatial Index are
created the way other index are created. Only extended keyword is used
'SPATIAL'.
Fulltext Indexes
Ability to search for text.


Only available in MyISAM.


Can be created for a TEXT, CHAR or VARCHAR.


Important points of fulltext Search:

  • Searches are not case sensitive.
  • Short words are ignored, the default minimum length is 4 character.
  • ft_min_word_len
  • ft_max_word_len

Words called stopwords are ignored:

  • ft_stopword_file= ' '

If a word is present in more than 50% of the rows it will have a weight of zero. This has advantage
on large data sets.
 Hash, B-Tree, R-Tree uses different strategy to speed data
  retrieval time.
 The best algorithm is pickedup depending on data expected
  and supportedalgorithm.
Query is using Index or Not?

                                             With EXPLAIN the query is
Query Execution Plan                          sent all the way to the
     (EXPLAIN)                               optimizer, but not to the
                                                  storage engine




             Secrets of Best MySQL Optimization Practice
mysql> explain select * from citylistG
       id: 1
select_type: SIMPLE
    table: citylist
     type: ALL
possible_keys: NULL
      key: NULL
key_len: NULL
      ref: NULL
     rows: 4079
    Extra:
1 row in set (0.01 sec)
Selectivity
• Selectivity of a column is the ratio between number of distinct
values and number of total values.
•Primary Key has selectivity 1.
     eg: Employee table has 10,000 users with fields employeeid
    ,email ,firstname ,lastname ,salary ,gender
Our application searches for following fields:
                       employeeid
      first ,lastname ,gender           email        So
    employeeid, email, firstname and lastname can be candiates
    for indexes.
Since employee id is unique its selectivity will
    be equal to the primary key selectivity.



In case of gender it will have two values M ,F
 selectivity = 2/10,000 = .00002



  If we drop this index , it will be more beneficial.
  Index on firstname and lastname selectivity is a
        function of name you are searching.



Selectivity above than 15% is a good index.
   # /*
                                                                        SQL script to grab the
   # SQL script to grab the worst performing indexes                     worst performing
   # in the whole server                                                 indexes in the whole
                                                                          server
   # */

   # SELECT

   # t.TABLE_SCHEMA AS `db`

   # , t.TABLE_NAME AS `table`

   # , s.INDEX_NAME AS `inde name`

   # , s.COLUMN_NAME AS `field name`

   # , s.SEQ_IN_INDEX `seq in index`

   # , s2.max_columns AS `# cols`

   # , s.CARDINALITY AS `card`

   # , t.TABLE_ROWS AS `est rows`

   # , ROUND(((s.CARDINALITY / IFNULL(t.TABLE_ROWS, 0.01)) * 100), 2) AS `sel %`

   # FROM INFORMATION_SCHEMA.STATISTICS s

   # INNER JOIN INFORMATION_SCHEMA.TABLES t

   # ON s.TABLE_SCHEMA = t.TABLE_SCHEMA

   # AND s.TABLE_NAME = t.TABLE_NAME
   # INNER JOIN (

   # SELECT

   # TABLE_SCHEMA

   # , TABLE_NAME

   # , INDEX_NAME

   # , MAX(SEQ_IN_INDEX) AS max_columns

   # FROM INFORMATION_SCHEMA.STATISTICS

   # WHERE TABLE_SCHEMA != 'mysql'

   # GROUP BY TABLE_SCHEMA, TABLE_NAME, INDEX_NAME

   # ) AS s2

   # ON s.TABLE_SCHEMA = s2.TABLE_SCHEMA

   # AND s.TABLE_NAME = s2.TABLE_NAME

   # AND s.INDEX_NAME = s2.INDEX_NAME

   # WHERE t.TABLE_SCHEMA != 'mysql'                 /* Filter out the mysql system DB */

   # AND t.TABLE_ROWS> 10                      /* Only tables with some rows */

   # AND s.CARDINALITY IS NOT NULL                  /* Need at least one non-NULL value in the field */

   # AND (s.CARDINALITY / IFNULL(t.TABLE_ROWS, 0.01)) < 1.00 /* Selectivity < 1.0 b/c unique indexes are perfect anyway */

   # ORDER BY `sel %`, s.TABLE_SCHEMA, s.TABLE_NAME          /* Switch to `sel %` DESC for best non-unique indexes */
Where to add index
WHERE clauses ( on which column data is filtered)

• Good distribution and selectivity in field values
• BAD IDEA to index gender or columns like status

Index join columns

Try to create as many Covering Index as possible

GROUP BY clauses
• Field order is important.
Avoid Redundant Indexes

Example:
Key(a)
key(a,b)
 Key(a(10));

Key(a)andKey(a(10) is redundant because they are prefix of Key(A,B)
Redundantx may be useful
A – integer column
B – varchar(255)
Key(A) will be faster than using Key(A,B).

Index on short columns are more faster however if index on longer column
 is created that can be beneficial as covered index.
Key Caches (MyISAM)
• For tables are used more often Key Cache can
  be used to optimize read of those tables
hot_cache.key_buffer_size = 128K
• Assign tables to caches
  CACHE INDEX table1, TO hot_cache;
  CACHE INDEX table2 TO cold_cache;
• Preload your indexes for maximum efficiency
• LOAD INDEX INTO CACHE table1;
• Use IGNORE LEAVES
Case where Index will not be used
Functions on indexed fields.

WHERE TO_DAYS(dateofjoining) –
TO_DAYS(Now()) <= 7 (doesn’t use index)

WHERE dateofjoing >= DATE_SUB(NOW(), INTER
 VAL 7 DAY) (uses index)
Select * from employee where name like ‘%s’;
If we use left() function used on index column.
Choosing Indexes
Index columns that you
   use for searching,
                               Consider column
sorting or grouping, not                                   Index Short Values.
                                 selectivity.
   columns you only
   display as output.



Index prefixes of string       Take advantage of
                                                            Don't over Index.
        values.                leftmost prefixes.




                Match Index types to      Use the slow-query log
                    the type of           to identify queries that
                 comparisions you           may be performing
                     perform.                      badly.
Keep data types as small as possible for what you
     need Don't use BIGINT unless required




       The smaller your data types, the more records
      will fit into the index blocks. The more records
      fit in each block, the fewer reads are needed to
                       find your records.
Common indexing mistakes



                        Using CREATE         Misusing a
Not using an Index.
                           INDEX.          composite Index.


                                 Appending the
                Using an
                                primary key to an
             expression on a
                                   index on an
                column.
                                  InnoDB table.
QnA
Thank you for your time and attention

   www.osscube.com



For more information, please feel free to drop in a line to
 sonali@osscube.com or visit http://www.osscube.com

Weitere ähnliche Inhalte

Was ist angesagt?

How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performanceoysteing
 
Introduction of sql server indexing
Introduction of sql server indexingIntroduction of sql server indexing
Introduction of sql server indexingMahabubur Rahaman
 
Introduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundIntroduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundMasahiko Sawada
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Mydbops
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0Norvald Ryeng
 
How to use histograms to get better performance
How to use histograms to get better performanceHow to use histograms to get better performance
How to use histograms to get better performanceMariaDB plc
 
MySQL Index Cookbook
MySQL Index CookbookMySQL Index Cookbook
MySQL Index CookbookMYXPLAIN
 
More mastering the art of indexing
More mastering the art of indexingMore mastering the art of indexing
More mastering the art of indexingYoshinori Matsunobu
 
Dd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinDd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinStåle Deraas
 
Recovery of lost or corrupted inno db tables(mysql uc 2010)
Recovery of lost or corrupted inno db tables(mysql uc 2010)Recovery of lost or corrupted inno db tables(mysql uc 2010)
Recovery of lost or corrupted inno db tables(mysql uc 2010)Aleksandr Kuzminsky
 
Query Optimization with MySQL 8.0 and MariaDB 10.3: The Basics
Query Optimization with MySQL 8.0 and MariaDB 10.3: The BasicsQuery Optimization with MySQL 8.0 and MariaDB 10.3: The Basics
Query Optimization with MySQL 8.0 and MariaDB 10.3: The BasicsJaime Crespo
 
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZEMySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZENorvald Ryeng
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningPuneet Behl
 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0Mydbops
 
MySQL Optimizer Cost Model
MySQL Optimizer Cost ModelMySQL Optimizer Cost Model
MySQL Optimizer Cost ModelOlav Sandstå
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain ExplainedJeremy Coates
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL TuningPgDay.Seoul
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQLJoel Brewer
 

Was ist angesagt? (20)

How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performance
 
Introduction of sql server indexing
Introduction of sql server indexingIntroduction of sql server indexing
Introduction of sql server indexing
 
Index in sql server
Index in sql serverIndex in sql server
Index in sql server
 
Introduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundIntroduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparound
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0
 
How to use histograms to get better performance
How to use histograms to get better performanceHow to use histograms to get better performance
How to use histograms to get better performance
 
MySQL Index Cookbook
MySQL Index CookbookMySQL Index Cookbook
MySQL Index Cookbook
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, Really
 
More mastering the art of indexing
More mastering the art of indexingMore mastering the art of indexing
More mastering the art of indexing
 
Dd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublinDd and atomic ddl pl17 dublin
Dd and atomic ddl pl17 dublin
 
Recovery of lost or corrupted inno db tables(mysql uc 2010)
Recovery of lost or corrupted inno db tables(mysql uc 2010)Recovery of lost or corrupted inno db tables(mysql uc 2010)
Recovery of lost or corrupted inno db tables(mysql uc 2010)
 
Query Optimization with MySQL 8.0 and MariaDB 10.3: The Basics
Query Optimization with MySQL 8.0 and MariaDB 10.3: The BasicsQuery Optimization with MySQL 8.0 and MariaDB 10.3: The Basics
Query Optimization with MySQL 8.0 and MariaDB 10.3: The Basics
 
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZEMySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0
 
MySQL Optimizer Cost Model
MySQL Optimizer Cost ModelMySQL Optimizer Cost Model
MySQL Optimizer Cost Model
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning
 
Introduction to PostgreSQL
Introduction to PostgreSQLIntroduction to PostgreSQL
Introduction to PostgreSQL
 

Andere mochten auch

MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MYXPLAIN
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBOvais Tariq
 
1 data types
1 data types1 data types
1 data typesRam Kedem
 
Database indexing framework
Database indexing frameworkDatabase indexing framework
Database indexing frameworkNitin Pande
 
The OSSCube MySQL High Availability Tutorial
The OSSCube MySQL High Availability TutorialThe OSSCube MySQL High Availability Tutorial
The OSSCube MySQL High Availability TutorialOSSCube
 
Database indexing techniques
Database indexing techniquesDatabase indexing techniques
Database indexing techniquesahmadmughal0312
 
Alta Disponibilidade em Linux com Heartbeat e Drbd
Alta Disponibilidade em Linux com Heartbeat e DrbdAlta Disponibilidade em Linux com Heartbeat e Drbd
Alta Disponibilidade em Linux com Heartbeat e DrbdFrederico Madeira
 
ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016Derek Downey
 
Database management system chapter12
Database management system chapter12Database management system chapter12
Database management system chapter12Md. Mahedi Mahfuj
 
MySQL High Availability Sprint: Launch the Pacemaker
MySQL High Availability Sprint: Launch the PacemakerMySQL High Availability Sprint: Launch the Pacemaker
MySQL High Availability Sprint: Launch the Pacemakerhastexo
 
Supriya Shailaja Latest Gallery
 Supriya Shailaja Latest Gallery Supriya Shailaja Latest Gallery
Supriya Shailaja Latest Gallerytelugustop.com
 
MySQL High Availability Deep Dive
MySQL High Availability Deep DiveMySQL High Availability Deep Dive
MySQL High Availability Deep Divehastexo
 
OSSCube MySQL Cluster Tutorial By Sonali At Osspac 09
OSSCube MySQL Cluster Tutorial By Sonali At Osspac 09OSSCube MySQL Cluster Tutorial By Sonali At Osspac 09
OSSCube MySQL Cluster Tutorial By Sonali At Osspac 09OSSCube
 
Maria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High AvailabilityMaria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High AvailabilityOSSCube
 

Andere mochten auch (20)

MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6
 
B+Tree Indexes and InnoDB
B+Tree Indexes and InnoDBB+Tree Indexes and InnoDB
B+Tree Indexes and InnoDB
 
1 data types
1 data types1 data types
1 data types
 
3 indexes
3 indexes3 indexes
3 indexes
 
Database indexing framework
Database indexing frameworkDatabase indexing framework
Database indexing framework
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Explain that explain
Explain that explainExplain that explain
Explain that explain
 
The OSSCube MySQL High Availability Tutorial
The OSSCube MySQL High Availability TutorialThe OSSCube MySQL High Availability Tutorial
The OSSCube MySQL High Availability Tutorial
 
Database indexing techniques
Database indexing techniquesDatabase indexing techniques
Database indexing techniques
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Introduction to TFS 2013
Introduction to TFS 2013Introduction to TFS 2013
Introduction to TFS 2013
 
Alta Disponibilidade em Linux com Heartbeat e Drbd
Alta Disponibilidade em Linux com Heartbeat e DrbdAlta Disponibilidade em Linux com Heartbeat e Drbd
Alta Disponibilidade em Linux com Heartbeat e Drbd
 
ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016ProxySQL Tutorial - PLAM 2016
ProxySQL Tutorial - PLAM 2016
 
Database management system chapter12
Database management system chapter12Database management system chapter12
Database management system chapter12
 
MySQL High Availability Sprint: Launch the Pacemaker
MySQL High Availability Sprint: Launch the PacemakerMySQL High Availability Sprint: Launch the Pacemaker
MySQL High Availability Sprint: Launch the Pacemaker
 
Supriya Shailaja Latest Gallery
 Supriya Shailaja Latest Gallery Supriya Shailaja Latest Gallery
Supriya Shailaja Latest Gallery
 
MySQL High Availability Deep Dive
MySQL High Availability Deep DiveMySQL High Availability Deep Dive
MySQL High Availability Deep Dive
 
OSSCube MySQL Cluster Tutorial By Sonali At Osspac 09
OSSCube MySQL Cluster Tutorial By Sonali At Osspac 09OSSCube MySQL Cluster Tutorial By Sonali At Osspac 09
OSSCube MySQL Cluster Tutorial By Sonali At Osspac 09
 
Maria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High AvailabilityMaria DB Galera Cluster for High Availability
Maria DB Galera Cluster for High Availability
 
MyRocks Deep Dive
MyRocks Deep DiveMyRocks Deep Dive
MyRocks Deep Dive
 

Ähnlich wie Indexing the MySQL Index: Key to performance tuning

Database Performance
Database PerformanceDatabase Performance
Database PerformanceBoris Hristov
 
Database index
Database indexDatabase index
Database indexRiteshkiit
 
Mongo Performance Optimization Using Indexing
Mongo Performance Optimization Using IndexingMongo Performance Optimization Using Indexing
Mongo Performance Optimization Using IndexingChinmay Naik
 
Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008wharrislv
 
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011Mark Ginnebaugh
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesJavier García Magna
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…Aaron Shilo
 
Sql Interview Questions
Sql Interview QuestionsSql Interview Questions
Sql Interview Questionsarjundwh
 
153680 sqlinterview
153680  sqlinterview153680  sqlinterview
153680 sqlinterviewzdsgsgdf
 
SQL Server 2000 Research Series - Performance Tuning
SQL Server 2000 Research Series - Performance TuningSQL Server 2000 Research Series - Performance Tuning
SQL Server 2000 Research Series - Performance TuningJerry Yang
 

Ähnlich wie Indexing the MySQL Index: Key to performance tuning (20)

Indexing
IndexingIndexing
Indexing
 
Module08
Module08Module08
Module08
 
Module08
Module08Module08
Module08
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
 
Database index
Database indexDatabase index
Database index
 
Mongo Performance Optimization Using Indexing
Mongo Performance Optimization Using IndexingMongo Performance Optimization Using Indexing
Mongo Performance Optimization Using Indexing
 
Oracle Index
Oracle IndexOracle Index
Oracle Index
 
Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008
 
Tunning overview
Tunning overviewTunning overview
Tunning overview
 
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
Microsoft SQL Server Filtered Indexes & Sparse Columns Feb 2011
 
Viva voce
Viva voceViva voce
Viva voce
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelines
 
Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…Getting to know oracle database objects iot, mviews, clusters and more…
Getting to know oracle database objects iot, mviews, clusters and more…
 
Sql
SqlSql
Sql
 
Sql Interview Questions
Sql Interview QuestionsSql Interview Questions
Sql Interview Questions
 
Sql
SqlSql
Sql
 
Sql
SqlSql
Sql
 
153680 sqlinterview
153680  sqlinterview153680  sqlinterview
153680 sqlinterview
 
SQL Server 2000 Research Series - Performance Tuning
SQL Server 2000 Research Series - Performance TuningSQL Server 2000 Research Series - Performance Tuning
SQL Server 2000 Research Series - Performance Tuning
 
Sql rally 2013 columnstore indexes
Sql rally 2013   columnstore indexesSql rally 2013   columnstore indexes
Sql rally 2013 columnstore indexes
 

Mehr von OSSCube

High Availability Using MySQL Group Replication
High Availability Using MySQL Group ReplicationHigh Availability Using MySQL Group Replication
High Availability Using MySQL Group ReplicationOSSCube
 
Accelerate Your Digital Transformation Journey with Pimcore
Accelerate Your Digital Transformation Journey with PimcoreAccelerate Your Digital Transformation Journey with Pimcore
Accelerate Your Digital Transformation Journey with PimcoreOSSCube
 
Migrating Legacy Applications to AWS Cloud: Strategies and Challenges
Migrating Legacy Applications to AWS Cloud: Strategies and ChallengesMigrating Legacy Applications to AWS Cloud: Strategies and Challenges
Migrating Legacy Applications to AWS Cloud: Strategies and ChallengesOSSCube
 
Why Does Omnichannel Experience Matter to Your Customers
Why Does Omnichannel Experience Matter to Your CustomersWhy Does Omnichannel Experience Matter to Your Customers
Why Does Omnichannel Experience Matter to Your CustomersOSSCube
 
Using MySQL Fabric for High Availability and Scaling Out
Using MySQL Fabric for High Availability and Scaling OutUsing MySQL Fabric for High Availability and Scaling Out
Using MySQL Fabric for High Availability and Scaling OutOSSCube
 
Webinar: Five Ways a Technology Refresh Strategy Can Help Make Your Digital T...
Webinar: Five Ways a Technology Refresh Strategy Can Help Make Your Digital T...Webinar: Five Ways a Technology Refresh Strategy Can Help Make Your Digital T...
Webinar: Five Ways a Technology Refresh Strategy Can Help Make Your Digital T...OSSCube
 
Cutting Through the Disruption
Cutting Through the DisruptionCutting Through the Disruption
Cutting Through the DisruptionOSSCube
 
Legacy to industry leader: a modernization case study
Legacy to industry leader: a modernization case studyLegacy to industry leader: a modernization case study
Legacy to industry leader: a modernization case studyOSSCube
 
Marketing and Sales together at last
Marketing and Sales together at lastMarketing and Sales together at last
Marketing and Sales together at lastOSSCube
 
Using pim to maximize revenue and improve customer satisfaction
Using pim to maximize revenue and improve customer satisfactionUsing pim to maximize revenue and improve customer satisfaction
Using pim to maximize revenue and improve customer satisfactionOSSCube
 
Talend for the Enterprise
Talend for the EnterpriseTalend for the Enterprise
Talend for the EnterpriseOSSCube
 
Ahead of the Curve
Ahead of the CurveAhead of the Curve
Ahead of the CurveOSSCube
 
Non functional requirements. do we really care…?
Non functional requirements. do we really care…?Non functional requirements. do we really care…?
Non functional requirements. do we really care…?OSSCube
 
Learning from experience: Collaborative Journey towards CMMI
Learning from experience: Collaborative Journey towards CMMILearning from experience: Collaborative Journey towards CMMI
Learning from experience: Collaborative Journey towards CMMIOSSCube
 
Exploiting JXL using Selenium
Exploiting JXL using SeleniumExploiting JXL using Selenium
Exploiting JXL using SeleniumOSSCube
 
Introduction to AWS
Introduction to AWSIntroduction to AWS
Introduction to AWSOSSCube
 
Talend Open Studio Introduction - OSSCamp 2014
Talend Open Studio Introduction - OSSCamp 2014Talend Open Studio Introduction - OSSCamp 2014
Talend Open Studio Introduction - OSSCamp 2014OSSCube
 
Performance Testing Session - OSSCamp 2014
Performance Testing Session -  OSSCamp 2014Performance Testing Session -  OSSCamp 2014
Performance Testing Session - OSSCamp 2014OSSCube
 
Job Queue Presentation - OSSCamp 2014
Job Queue Presentation - OSSCamp 2014Job Queue Presentation - OSSCamp 2014
Job Queue Presentation - OSSCamp 2014OSSCube
 
Introduction to Business Process Model and Notation (BPMN) - OSSCamp 2014
 Introduction to Business Process Model and Notation (BPMN) - OSSCamp 2014 Introduction to Business Process Model and Notation (BPMN) - OSSCamp 2014
Introduction to Business Process Model and Notation (BPMN) - OSSCamp 2014OSSCube
 

Mehr von OSSCube (20)

High Availability Using MySQL Group Replication
High Availability Using MySQL Group ReplicationHigh Availability Using MySQL Group Replication
High Availability Using MySQL Group Replication
 
Accelerate Your Digital Transformation Journey with Pimcore
Accelerate Your Digital Transformation Journey with PimcoreAccelerate Your Digital Transformation Journey with Pimcore
Accelerate Your Digital Transformation Journey with Pimcore
 
Migrating Legacy Applications to AWS Cloud: Strategies and Challenges
Migrating Legacy Applications to AWS Cloud: Strategies and ChallengesMigrating Legacy Applications to AWS Cloud: Strategies and Challenges
Migrating Legacy Applications to AWS Cloud: Strategies and Challenges
 
Why Does Omnichannel Experience Matter to Your Customers
Why Does Omnichannel Experience Matter to Your CustomersWhy Does Omnichannel Experience Matter to Your Customers
Why Does Omnichannel Experience Matter to Your Customers
 
Using MySQL Fabric for High Availability and Scaling Out
Using MySQL Fabric for High Availability and Scaling OutUsing MySQL Fabric for High Availability and Scaling Out
Using MySQL Fabric for High Availability and Scaling Out
 
Webinar: Five Ways a Technology Refresh Strategy Can Help Make Your Digital T...
Webinar: Five Ways a Technology Refresh Strategy Can Help Make Your Digital T...Webinar: Five Ways a Technology Refresh Strategy Can Help Make Your Digital T...
Webinar: Five Ways a Technology Refresh Strategy Can Help Make Your Digital T...
 
Cutting Through the Disruption
Cutting Through the DisruptionCutting Through the Disruption
Cutting Through the Disruption
 
Legacy to industry leader: a modernization case study
Legacy to industry leader: a modernization case studyLegacy to industry leader: a modernization case study
Legacy to industry leader: a modernization case study
 
Marketing and Sales together at last
Marketing and Sales together at lastMarketing and Sales together at last
Marketing and Sales together at last
 
Using pim to maximize revenue and improve customer satisfaction
Using pim to maximize revenue and improve customer satisfactionUsing pim to maximize revenue and improve customer satisfaction
Using pim to maximize revenue and improve customer satisfaction
 
Talend for the Enterprise
Talend for the EnterpriseTalend for the Enterprise
Talend for the Enterprise
 
Ahead of the Curve
Ahead of the CurveAhead of the Curve
Ahead of the Curve
 
Non functional requirements. do we really care…?
Non functional requirements. do we really care…?Non functional requirements. do we really care…?
Non functional requirements. do we really care…?
 
Learning from experience: Collaborative Journey towards CMMI
Learning from experience: Collaborative Journey towards CMMILearning from experience: Collaborative Journey towards CMMI
Learning from experience: Collaborative Journey towards CMMI
 
Exploiting JXL using Selenium
Exploiting JXL using SeleniumExploiting JXL using Selenium
Exploiting JXL using Selenium
 
Introduction to AWS
Introduction to AWSIntroduction to AWS
Introduction to AWS
 
Talend Open Studio Introduction - OSSCamp 2014
Talend Open Studio Introduction - OSSCamp 2014Talend Open Studio Introduction - OSSCamp 2014
Talend Open Studio Introduction - OSSCamp 2014
 
Performance Testing Session - OSSCamp 2014
Performance Testing Session -  OSSCamp 2014Performance Testing Session -  OSSCamp 2014
Performance Testing Session - OSSCamp 2014
 
Job Queue Presentation - OSSCamp 2014
Job Queue Presentation - OSSCamp 2014Job Queue Presentation - OSSCamp 2014
Job Queue Presentation - OSSCamp 2014
 
Introduction to Business Process Model and Notation (BPMN) - OSSCamp 2014
 Introduction to Business Process Model and Notation (BPMN) - OSSCamp 2014 Introduction to Business Process Model and Notation (BPMN) - OSSCamp 2014
Introduction to Business Process Model and Notation (BPMN) - OSSCamp 2014
 

Kürzlich hochgeladen

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Kürzlich hochgeladen (20)

Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

Indexing the MySQL Index: Key to performance tuning

  • 1. Indexing the MySQL Index: Guide to Performance Enhancement Presented by – Sonali Minocha OSSCube
  • 2. Who Am I? Chief Technology Officer (MySQL) with OSSCube MySQL Consulting, Implementation & Training MySQL Certified DBA & Cluster DBA
  • 3.
  • 4. What is Index? A mechanism to locate and A database index is a data access data within a structure that improves the database. An index may speed of data retrieval quote one or more columns operations on a database and be a means of enforcing table. uniqueness on their values.
  • 5. More about Index • Speedy data retrieval. • SPEED of SELECTs • Rapid random look ups. • Efficient for Reporting, OLAP, read-intensive applications •However it is expensive for – Slows down writes – heavy write applications (OLTP) be careful – More disk space used
  • 6. Properties Index can be created on : Index only contains key- • One or more columns. fields according to which table is arranged. Index may quote one or more columns and be a Index may be unique or means of enforcing non-unique. uniqueness of their values.
  • 7. EMPLOYEE TABLE EMPLOYEE ID FIRSTNAME LASTNAME AGE SALARY GENDER 001 Ashish Kataria 25 10000 M 002 Rony Felix 28 20000 M 003 Namita Misra 24 10000 F 004 Ankur Aeran 30 25000 M 005 Priyanka Jain 30 20000 F 006 Pradeep Pandey 31 30000 M 007 Pankaj Gupta 25 12000 M 008 Ankit Garg 30 15000 M
  • 8. Cont. In this table if we have to search for employee whose name is Rony then code will look like : For each row in table if row[2] = 'Rony' then results.append[row] Else movenext So we checking each now for condition.
  • 9. HOW DATABASE INDEXES WORK ? • Lets assume we have a table of data like this:
  • 10. Type Of Indexes Concatenated Column Index Covering Index Index Clustered/Non- Partial Index clustered Index
  • 11. Column Index Only those query will Index on a single be optimized which column satisfy your criteria. Eg: By adding an index to SELECT employeeid, the employeeid, firstnam query is optimized to e only look at records FROM Employee that satisfy your WHERE criteria. employeeid = 001
  • 12. Concatenated Index Index on multiple Use appropriate index. columns. : SELECT employeeid, lastname FROM Employee WHERE employeeid = 002 AND lastname = ‘Felix’;
  • 13. Covering Index The benefit of a covering index is that the lookup of the various B-Tree index pages Covers all columns in a query. necessarily satisfies the query, and no additional data page lookups are necessary. SELECT employeeid FROM Employee WHERE employeeid = 001
  • 14. Partial Index  Subset of a column for the index.  Use on CHAR, VARCHAR,TEXT etc.  Creating a partial index may greatly reduce the size of the index, and minimize the additional data lookups required.  Create table t ( name char(255) , INDEX ( name(15) ) );  Eg:-SELECT employeeid, firstname, lastname FROM Employee WHERE lastname like ‘A%’ We should add an index to lastname to improve performance.
  • 15. Clustered vs. Non-clustered Describes whether the data records are stored on disk in a sorted order MyISAM - non clustered. InnoDB - Clustered. Secondary indexes built upon the clustering key
  • 16. Primary Index is added to all secondary index. Because the data resides within the leaf nodes of index, more space in memory needed to search through same amount of records
  • 18. How it can be faster? If we create HASH TABLE. The key of hash table would be based on empnameand the values would be pointer to the database row. This is Hash Index: • Hash index are good for equality searches. • Hash index are not good for index searches. So what should be the solution for Range Searches? B-Tree
  • 19. 30 0X775800 Age Location of the data B-Tree/ Binary tree: Stores data in ordered way. Nodes in B-Tree contains a index field and a pointer to a Allows data row. logarithmic • So like in above Each node takes It allows faster Single disk selections, inser example if we up one disk range searches. operation. tions and create an index on block. deletion. age the node of B- tree will look like
  • 20. B-Tree 003 006 Diagram 001 002 004 005 008 007 EMPLOYEE ID FIRSTNAME LASTNAME AGE SALARY GENDER 001 Ashish Kataria 25 10000 M 002 Rony Felix 28 20000 M 003 Namita Misra 24 10000 F 004 Ankur Aeran 30 25000 M 005 Priyanka Jain 30 20000 F 006 Pradeep Pandey 31 30000 M 007 Pankaj Gupta 25 12000 M 008 Ankit Garg 30 15000 M
  • 21. R-Tree MySQL supports any other type of index called Spatial Index. Spatial Index are created the way other index are created. Only extended keyword is used 'SPATIAL'.
  • 22. Fulltext Indexes Ability to search for text. Only available in MyISAM. Can be created for a TEXT, CHAR or VARCHAR. Important points of fulltext Search: • Searches are not case sensitive. • Short words are ignored, the default minimum length is 4 character. • ft_min_word_len • ft_max_word_len Words called stopwords are ignored: • ft_stopword_file= ' ' If a word is present in more than 50% of the rows it will have a weight of zero. This has advantage on large data sets.
  • 23.  Hash, B-Tree, R-Tree uses different strategy to speed data retrieval time.  The best algorithm is pickedup depending on data expected and supportedalgorithm.
  • 24. Query is using Index or Not? With EXPLAIN the query is Query Execution Plan sent all the way to the (EXPLAIN) optimizer, but not to the storage engine Secrets of Best MySQL Optimization Practice
  • 25. mysql> explain select * from citylistG id: 1 select_type: SIMPLE table: citylist type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 4079 Extra: 1 row in set (0.01 sec)
  • 26. Selectivity • Selectivity of a column is the ratio between number of distinct values and number of total values. •Primary Key has selectivity 1. eg: Employee table has 10,000 users with fields employeeid ,email ,firstname ,lastname ,salary ,gender Our application searches for following fields: employeeid first ,lastname ,gender email So employeeid, email, firstname and lastname can be candiates for indexes.
  • 27. Since employee id is unique its selectivity will be equal to the primary key selectivity. In case of gender it will have two values M ,F selectivity = 2/10,000 = .00002 If we drop this index , it will be more beneficial. Index on firstname and lastname selectivity is a function of name you are searching. Selectivity above than 15% is a good index.
  • 28. # /* SQL script to grab the  # SQL script to grab the worst performing indexes worst performing  # in the whole server indexes in the whole server  # */  # SELECT  # t.TABLE_SCHEMA AS `db`  # , t.TABLE_NAME AS `table`  # , s.INDEX_NAME AS `inde name`  # , s.COLUMN_NAME AS `field name`  # , s.SEQ_IN_INDEX `seq in index`  # , s2.max_columns AS `# cols`  # , s.CARDINALITY AS `card`  # , t.TABLE_ROWS AS `est rows`  # , ROUND(((s.CARDINALITY / IFNULL(t.TABLE_ROWS, 0.01)) * 100), 2) AS `sel %`  # FROM INFORMATION_SCHEMA.STATISTICS s  # INNER JOIN INFORMATION_SCHEMA.TABLES t  # ON s.TABLE_SCHEMA = t.TABLE_SCHEMA  # AND s.TABLE_NAME = t.TABLE_NAME
  • 29. # INNER JOIN (  # SELECT  # TABLE_SCHEMA  # , TABLE_NAME  # , INDEX_NAME  # , MAX(SEQ_IN_INDEX) AS max_columns  # FROM INFORMATION_SCHEMA.STATISTICS  # WHERE TABLE_SCHEMA != 'mysql'  # GROUP BY TABLE_SCHEMA, TABLE_NAME, INDEX_NAME  # ) AS s2  # ON s.TABLE_SCHEMA = s2.TABLE_SCHEMA  # AND s.TABLE_NAME = s2.TABLE_NAME  # AND s.INDEX_NAME = s2.INDEX_NAME  # WHERE t.TABLE_SCHEMA != 'mysql' /* Filter out the mysql system DB */  # AND t.TABLE_ROWS> 10 /* Only tables with some rows */  # AND s.CARDINALITY IS NOT NULL /* Need at least one non-NULL value in the field */  # AND (s.CARDINALITY / IFNULL(t.TABLE_ROWS, 0.01)) < 1.00 /* Selectivity < 1.0 b/c unique indexes are perfect anyway */  # ORDER BY `sel %`, s.TABLE_SCHEMA, s.TABLE_NAME /* Switch to `sel %` DESC for best non-unique indexes */
  • 30. Where to add index WHERE clauses ( on which column data is filtered) • Good distribution and selectivity in field values • BAD IDEA to index gender or columns like status Index join columns Try to create as many Covering Index as possible GROUP BY clauses • Field order is important.
  • 31. Avoid Redundant Indexes Example: Key(a) key(a,b) Key(a(10)); Key(a)andKey(a(10) is redundant because they are prefix of Key(A,B) Redundantx may be useful A – integer column B – varchar(255) Key(A) will be faster than using Key(A,B). Index on short columns are more faster however if index on longer column is created that can be beneficial as covered index.
  • 32. Key Caches (MyISAM) • For tables are used more often Key Cache can be used to optimize read of those tables hot_cache.key_buffer_size = 128K • Assign tables to caches CACHE INDEX table1, TO hot_cache; CACHE INDEX table2 TO cold_cache;
  • 33. • Preload your indexes for maximum efficiency • LOAD INDEX INTO CACHE table1; • Use IGNORE LEAVES
  • 34. Case where Index will not be used Functions on indexed fields. WHERE TO_DAYS(dateofjoining) – TO_DAYS(Now()) <= 7 (doesn’t use index) WHERE dateofjoing >= DATE_SUB(NOW(), INTER VAL 7 DAY) (uses index)
  • 35. Select * from employee where name like ‘%s’; If we use left() function used on index column.
  • 36. Choosing Indexes Index columns that you use for searching, Consider column sorting or grouping, not Index Short Values. selectivity. columns you only display as output. Index prefixes of string Take advantage of Don't over Index. values. leftmost prefixes. Match Index types to Use the slow-query log the type of to identify queries that comparisions you may be performing perform. badly.
  • 37. Keep data types as small as possible for what you need Don't use BIGINT unless required The smaller your data types, the more records will fit into the index blocks. The more records fit in each block, the fewer reads are needed to find your records.
  • 38. Common indexing mistakes Using CREATE Misusing a Not using an Index. INDEX. composite Index. Appending the Using an primary key to an expression on a index on an column. InnoDB table.
  • 39. QnA
  • 40. Thank you for your time and attention www.osscube.com For more information, please feel free to drop in a line to sonali@osscube.com or visit http://www.osscube.com