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 2017 January MySQL: How Query Optimizer Read and Update the Index Statistics

MySQL: How Query Optimizer Read and Update the Index Statistics

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

For all the RDBMS, Database Statistics are playing the main role to generate an accurate Query Execution Plan.
A Database Administrator is also very much responsible to make sure that Database Statistics is updated.

MySQL query optimizer is also preparing Query Execution Plan with the help of Statistics Information.
The auto-update Statistics configuration is also very important to keep Statistics updated.

How to enable auto-update Statistics for InnoDB engine?

We can configure innodb_stats_on_metadata variable to enable auto-update Statistics.

When this variable is enabled InnoDB updates statistics when metadata statements such as SHOW TABLE STATUS or SHOW INDEX are run, or when accessing the INFORMATION_SCHEMA.TABLES or INFORMATION_SCHEMA.STATISTICS tables.

Check innodb_stats_on_metadata is ON or OFF:

1
SHOW VARIABLES LIKE 'innodb_stats_on_metadata';

If innodb_stats_on_metadata is OFF, make it ON:

1
SET GLOBAL innodb_stats_on_metadata=ON;

When you perform command like SHOW INDEX, Statisitcs will be update.
Accuracy of statistics is depends on MySQL Server Load.

1
SHOW INDEXES FROM SchemaName.TableName;

You can use below query to check the Index Statistics:

1
2
3
4
5
6
7
8
9
10
11
12
SELECT
Table_Schema
,Table_Name
,Non_Unique
,Index_Schema
,Seq_In_Index
,Column_Name
,Collation
,Cardinality
,Index_Type
FROM information_schema.statistics
WHERE TABLE_SCHEMA='SchemaName';

Jan 8, 2017Anvesh Patel
SQL Server: Get the Latches Usage and Information (sys.dm_db_index_operational_stats)SQL Server Interview: What is the logical order of SQL Query (SELECT Statement)
Comments: 2
  1. Øystein Grøvlen
    January 13, 2017 at 11:23 am

    Note that persistent statistics was added to InnoDB in MySQL 5.6. innodb_stats_on_metadata does not have any effect on persistent statistics. The documentation has now been updated to reflect that.

    • Anvesh Patel
      Anvesh Patel
      January 13, 2017 at 7:03 pm

      Thanks for this information !

Anvesh Patel
Anvesh Patel

Database Engineer

January 8, 2017 MySQLAnvesh Patel, database, database research and development, dbrnd, Index Statistics, INFORMATION_SCHEMA.STATISTICS, innodb_stats_on_metadata, MySQL, MySQL Command, MySQL Database Administrator, MySQL Database Designing, MySQL Database Programming, MySQL Error, MySQL Performance Tunning, MySQL Query, MySQL Tips and Tricks, Query Execution Plan, Query Optimizer, Query Planner
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....