CREATE UNIQUE INDEX IF NOT EXISTS `task_active_resource_uidx` 
ON `task_run` (`user_id`, `task_type`, `resource_key`) 
WHERE `resource_key` IS NOT NULL AND `status` IN ('queued', 'running');
