(I'm not smart enough to know for a fact that this hasn't already been reported; there are a number of similar tickets, but those that are not closed appear to be somewhat different.)
Basically, attempting a bunch of `action=undelete` queries can result in multiple `internal_api_error_DBQueryError` errors, reported as `Wikimedia\Rdbms\DBQueryError` and a varying string like `XMrEMQpAMDwAAGzj1h4AAAAW` or `XMtbogpAAEwAAA7kBZ0AAACO`.
Sometimes it works fine, and sometimes 20%-80% of the queries fail, even after attempting them all twice. Has been going on for at least a few months, possibly much longer. This is using the `batchundelete` module from [[https://en.wikipedia.org/wiki/Wikipedia:Twinkle|Twinkle]] on enwiki (or testwiki). The same code is used for `batchdelete` and doesn't result in the same errors.
```
2019-05-02 10:19:29 [XMrEMQpAMDwAAGzj1h4AAAAW] mw1225 enwiki 1.34.0-wmf.1 exception ERROR: [XMrEMQpAMDwAAGzj1h4AAAAW] /w/api.php Wikimedia\Rdbms\DBQueryError from line 1587 of /srv/mediawiki/php-1.34.0-wmf.1/includes/libs/rdbms/database/Database.php: A database query error has occurred. Did you forget to run your application's database schema updater after upgrading?
Query: INSERT IGNORE INTO `page` (page_namespace,page_title,page_restrictions,page_is_redirect,page_is_new,page_random,page_touched,page_latest,page_len,page_id) VALUES ('2','Amorymeltzer/sandbox/5','','0','1','0.206380669357','20190502101929','0','0','60635647')
Function: WikiPage::insertOn
Error: 1213 Deadlock found when trying to get lock; try restarting transaction (10.64.32.64)
{"exception_id":"XMrEMQpAMDwAAGzj1h4AAAAW","exception_url":"/w/api.php","caught_by":"mwe_handler"}
[Exception Wikimedia\Rdbms\DBQueryError] (/srv/mediawiki/php-1.34.0-wmf.1/includes/libs/rdbms/database/Database.php:1587) A database query error has occurred. Did you forget to run your application's database schema updater after upgrading?
Query: INSERT IGNORE INTO `page` (page_namespace,page_title,page_restrictions,page_is_redirect,page_is_new,page_random,page_touched,page_latest,page_len,page_id) VALUES ('2','Amorymeltzer/sandbox/5','','0','1','0.206380669357','20190502101929','0','0','60635647')
Function: WikiPage::insertOn
Error: 1213 Deadlock found when trying to get lock; try restarting transaction (10.64.32.64)
#0 /srv/mediawiki/php-1.34.0-wmf.1/includes/libs/rdbms/database/Database.php(1556): Wikimedia\Rdbms\Database->getQueryExceptionAndLog(string, integer, string, string)
#1 /srv/mediawiki/php-1.34.0-wmf.1/includes/libs/rdbms/database/Database.php(1274): Wikimedia\Rdbms\Database->reportQueryError(string, integer, string, string, boolean)
#2 /srv/mediawiki/php-1.34.0-wmf.1/includes/libs/rdbms/database/Database.php(2149): Wikimedia\Rdbms\Database->query(string, string)
#3 /srv/mediawiki/php-1.34.0-wmf.1/includes/page/WikiPage.php(1345): Wikimedia\Rdbms\Database->insert(string, array, string, string)
#4 /srv/mediawiki/php-1.34.0-wmf.1/includes/page/PageArchive.php(735): WikiPage->insertOn(Wikimedia\Rdbms\DatabaseMysqli, string)
#5 /srv/mediawiki/php-1.34.0-wmf.1/includes/page/PageArchive.php(506): PageArchive->undeleteRevisions(array, boolean, string)
#6 /srv/mediawiki/php-1.34.0-wmf.1/includes/api/ApiUndelete.php(74): PageArchive->undelete(array, string, NULL, boolean, User, NULL)
#7 /srv/mediawiki/php-1.34.0-wmf.1/includes/api/ApiMain.php(1593): ApiUndelete->execute()
#8 /srv/mediawiki/php-1.34.0-wmf.1/includes/api/ApiMain.php(531): ApiMain->executeAction()
#9 /srv/mediawiki/php-1.34.0-wmf.1/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling()
#10 /srv/mediawiki/php-1.34.0-wmf.1/api.php(87): ApiMain->execute()
#11 /srv/mediawiki/w/api.php(3): require(string)
#12 {main}
```