Why does query parameter type affects mysql index choice? I have a query like this:

select a, b, c from sometable where cateId = ? /**1**/


We can also do this:

select a, b, c from sometable where cateId = "1"


as MySQL will cast it. Interestingly I observed different performance characteristics on these two queries. Why this is the case?

I omitted quite some details regarding table structure and index details, but in general is it possible for such scenario to really occur, and why?

adding the details I mentioned. if it helps. 

    select
        memberId,
        prodId,
        prodName,
        sum(count) as total
    from
        SOMETABLE
    where
        statDate &gt;= ?
        and statDate&lt;= ?
        and catId = ?
        and name &lt;&gt; 'OTHERS'
    group by
        memberId, prodName
    order by
        total desc
    limit 5

    --IDX catId, prodName
    --IDX catId, statDate
    --IDX memberId, statDate
    --IDX catId, statDate, prodName, prodId, count
Query processing takes the given SQL, applies a set of rules and heuristics and comes up with an execution plan. This states which indexes are used and how. The outcome is dependent on the input and how the rules have been written.

Given a slightly different start point a different end point may result. It's somewhat like dropping a ball in a landscape of river vallies. Drop it once and it will roll into a river. Drop it in a slightly different place and chances are it will roll down into the same river. Occasionally, if you're near a ridge, you drop the ball in a slightly different place and it rolls into the next river instead.