I have following query which is taking time. Mytable type is innodb and have primary key on field tsh_id I have also added index on transaction_Id field
following is implementation inside my database stored procedure.
DECLARE lv_timestamp DATETIME(3);
SET @lv_timestamp = NOW(3);
IF(mycondition) then
SET @lv_Duration :=( SELECT UNIX_TIMESTAMP (@lv_timestamp) - UNIX_TIMESTAMP ( `changedon` )
FROM `MyTable`
WHERE transaction_Id = _transaction_Id
ORDER BY tsh_id DESC
LIMIT 1)
End if;
Please suggest any sort of improvement
Edit:
Explain to query says
"select_type":"SIMPLE",
"table":"MyTable",
"type":"ref",
"possible_keys":"IX_MyTable_Transaction",
"key":"IX_MyTable_Transaction",
"key_len":"98",
"ref":"const",
"rows":1,
"Extra":"Using where"