Why is it that this stored procedure:
CREATE
DEFINER = mysql_user@`%` PROCEDURE sp_GetSessionData(IN SessionId varchar(45))
BEGIN
SELECT * FROM sessiondata WHERE SessionGuid = SessionId;
END;
Takes 5 minutes to run but this equivalent query:
SELECT * FROM sessiondata WHERE SessionGuid = 'd2c26d6d-4e80-4e80-4e80-2d7ca9cfa3a3';
Only takes 40ms to run?
I have an index on the SessionGuid
column and the column is of type varchar(45)
which is the exact same as the input parameter for my stored procedure.
UPDATE:
Here is what I get when I put an EXPLAIN
in the stored procedure:
╔════╦═════════════╦══════════╦════════════╦══════╦═══════════════╦══════╦═════════╦══════╦══════════╦══════════╦═════════════╗
║ id ║ select_type ║ table ║ partitions ║ type ║ possible_keys ║ key ║ key_len ║ ref ║ rows ║ filtered ║ Extra ║
╠════╬═════════════╬══════════╬════════════╬══════╬═══════════════╬══════╬═════════╬══════╬══════════╬══════════╬═════════════╣
║ 1 ║ SIMPLE ║ perfinfo ║ NULL ║ ALL ║ NULL ║ NULL ║ NULL ║ NULL ║ 77249445 ║ 100 ║ Using where ║
╚════╩═════════════╩══════════╩════════════╩══════╩═══════════════╩══════╩═════════╩══════╩══════════╩══════════╩═════════════╝
And here is an EXPLAIN
of the sessiondata
table:
╔═════════════════╦══════════════════╦══════╦═════╦═════════╦════════════════╗
║ Field ║ Type ║ Null ║ Key ║ Default ║ Extra ║
╠═════════════════╬══════════════════╬══════╬═════╬═════════╬════════════════╣
║ PerfId ║ int(11) unsigned ║ NO ║ PRI ║ NULL ║ auto_increment ║
║ SessionGuid ║ varchar(45) ║ NO ║ MUL ║ NULL ║ ║
║ BuildId ║ int(11) ║ NO ║ MUL ║ NULL ║ ║
║ Metric ║ float ║ NO ║ ║ NULL ║ ║
║ MetricId ║ int(11) unsigned ║ NO ║ MUL ║ NULL ║ ║
║ Location ║ varchar(45) ║ NO ║ ║ NULL ║ ║
║ RunTypeId ║ int(11) ║ NO ║ ║ NULL ║ ║
║ MetaContextId ║ int(11) ║ NO ║ MUL ║ -1 ║ ║
║ SecondsFromBoot ║ int(10) unsigned ║ NO ║ ║ NULL ║ ║
║ Timestamp ║ datetime ║ NO ║ ║ NULL ║ ║
║ DeviceId ║ int(11) ║ NO ║ MUL ║ -1 ║ ║
╚═════════════════╩══════════════════╩══════╩═════╩═════════╩════════════════╝