My Oracle Support Banner

A Query Does Not Use Expected Indexes When Comparing a Field to a Variable (Doc ID 2242395.1)

Last updated on MARCH 28, 2024

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:



To view full details, sign in with your My Oracle Support account.

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

In this Document

My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.