In my case, turns out the slow query was an update join on the cron_schedule table.
Found a related site on this.
Solution - You can clear it with a daily script to delete completed records.
https://www.optiweb.com/magento-2-cron-issues/
There should be a configuration for each cron groupfor the history cleanup and lifetimes.
<history_cleanup_every>10</history_cleanup_every>
<history_success_lifetime>60</history_success_lifetime>
<history_failure_lifetime>600</history_failure_lifetime>
However, this only cleans up cron entries with the status »success« or »missed« and does not clean old entries with the status »pending«.
Simple Script: to delete cron_schedule records created a day ago copied from optiweb.com link above.
<?php
use Magento\Framework\App\Bootstrap;
$rootDirectory = *Magento root directory*;
require $rootDirectory . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$objectManager = $bootstrap->getObjectManager();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('cron_schedule');
$sql = "DELETE FROM " . $tableName . " WHERE created_at < DATE_SUB(NOW(), INTERVAL 1 DAY)";
try{
$result = $connection->query($sql);
}catch(Exception $ex){
print_r($ex);
}
Seems to do the trick, although I'm not sure about the interval may bump it to 7 days.
SELECT count(*), job_code FROM cron_schedule group by job_code order by count(*) DESC