Understanding MySQL Index Scan Types

 Understanding MySQL Index Scan Types

MySQL uses various scan types to efficiently retrieve data from indexed tables. Understanding these scan types helps optimize query performance.


1. Full Table Scan

  • Definition: Reads all rows from a table.
  • Use Case: When no index is available or the query requires all rows.
     select * from emp;

2. Index Scan (Range Scan)
  • Definition: Reads rows within a specified range.
  • Use Case: Queries using indexed columns with range conditions (e.g., BETWEEN, <, >);
select * from emp where age between 30 and 40;

3. Full Index Scan
  • Definition: Reads all entries in an index.
  • Use Case: When a query can be resolved by reading only the index.
select empid from emp;

4. Index Range Scan
  • Definition: Scans a range of index values.
  • Use Case: Common for range queries and partial key lookups.

select * from emp where last_name like 'singh%';

5. Index Only Scan
  • Definition: Retrieves data directly from the index without accessing the table.
  • Use Case: When all required data is contained within the index.
select last_name from emp where last_name='praksh';

6. Index Merge

Definition: Combines results from multiple indexes.
Use Case: Complex queries using multiple conditions that each have separate indexes.

select * from emp where age='30' and last_name='Vaibhav';

7. Index Condition Pushdown (ICP)

  • Definition: Pushes down a condition to the storage engine level to filter rows earlier.
  • Use Case: Improves performance by reducing the number of rows returned to the MySQL server.
select * from emp where emp_id=5 and salary >=50000;





Comments

Popular posts from this blog

MySQL Point in Time Recovery: How To Configure And How Does it Work?

MySQL Replication Switchover: Step-by-Step Guide

Mysql Commercial Mysqlbackup:How to take Differential or Incremental Backup and resotre using mysqlbackup utility in mysql 8.0.37 enterprise edition