UPDATE `tb_document_import_batch_item`
SET `retryable` = 1
WHERE `status` = 'FAILED'
  AND `stage` IN ('PARSE', 'SPLIT', 'INDEX')
  AND `document_id` IS NOT NULL
  AND `retryable` = 0;

UPDATE `tb_document_import_batch` batch
SET batch.`retryable_failed_count` = (
    SELECT COUNT(*)
    FROM `tb_document_import_batch_item` item
    WHERE item.`batch_id` = batch.`id`
      AND item.`status` = 'FAILED'
      AND item.`retryable` = 1
);
