DROP PROCEDURE IF EXISTS mocha_get_instances;

CREATE PROCEDURE mocha_get_instances
(
    IN p_class_id INT
)
BEGIN

    DECLARE p_tenant_id INT;
    SET p_tenant_id = mocha_get_current_tenant();

    SELECT CONCAT(class_id, '$', inst_id) AS inst_key, global_identifier
    FROM mocha_instances
    WHERE tenant_id = p_tenant_id
    AND (p_class_id IS NULL OR class_id = p_class_id);

END;