DROP FUNCTION IF EXISTS mocha_get_instance_by_key;

CREATE FUNCTION mocha_get_instance_by_key
(
    p_class_id INT,
    p_inst_id INT
)
RETURNS INT
RETURN (SELECT id FROM mocha_instances WHERE tenant_id = mocha_get_current_tenant() AND class_id = p_class_id AND inst_id = p_inst_id LIMIT 1);