MySQL-Why does this query use full index scan?

861 views Asked by At

I'm currently studying DB index. In the MySQL classicmodels db, I don't know why does this query use full index scan.

    select salesRepEmployeeNumber, count(*) 
    from customers 
    where creditLimit > 100000
    group by salesRepEmployeeNumber;

The customers table has clustered index on customerNumber and Non-clustered index on salesRepEmployeeNumber. From what I learned, there is a <key, key of clustered index> in the data entry of the non-clustered tree. Isn't the creditLimit column that exists in the WHERE clause information that can only be known by accessing the data record? If so, shouldn't MySQL query optimizer use full table scan not full index scan?B tree clustered index B tree Non-clustered index Query Execution Plan

1

There are 1 answers

4
Gordan Bobić On

If you have an index defined on (credit limit, salesRepEmployeeNumber), this query can be fulfilled from the index alone without touching the data pages.