A Query Does Not Use Expected Indexes When Comparing a Field to a Variable

(Doc ID 2242395.1)

Last updated on MARCH 09, 2017

Applies to:

MySQL Server - Version 5.1 and later
Information in this document applies to any platform.


 A query which compares a string field (CHAR, VARCHAR, or TEXT) to a constant uses an index on that field. A similar query inside a stored procedure or function fails to use the index when comparing the field to a local variable.

For example, this query may use an index:



Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms