I'm attempting to use a stored procedure.
DELIMITER //
CREATE PROCEDURE cuiTitle(IN cui_in CHAR(8))
BEGIN
EXPLAIN SELECT str FROM MRCONSO
WHERE cui = cui_in
AND ts = 'P'
AND stt = 'PF'
AND ispref = 'Y'
LIMIT 1;
END //
CALL cuiTitle('C0269037');
The query is very slow. it does a fully scan instead of using the primary index.
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE MRCONSO NULL ALL NULL NULL NULL NULL 5814290 0.10 Using where
If querying directly or using hardcoded value instead of parameter, the query is very fast and uses the primary key.
DELIMITER //
CREATE PROCEDURE cuiTitle(IN cui_in CHAR(8))
BEGIN
EXPLAIN SELECT str FROM MRCONSO
WHERE cui = 'C0269037'
AND ts = 'P'
AND stt = 'PF'
AND ispref = 'Y'
LIMIT 1;
END //
CALL cuiTitle('C0269037');
its "explain":
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE MRCONSO NULL ref PRIMARY PRIMARY 24 const 10 0.50 Using where
Why is it? how can I make the stored procedure use the primary key? I've tried https://stackoverflow.com/a/21687188/218677 recommendation but with no success..
UPDATE:
I don't know if the makes a difference, but it primary key is:
PRIMARY KEY (CUI
,AUI
),