If you name the index, the query will fail if the index already exists (tested in MySQL 8.0):
ALTER TABLE `my_table` ADD INDEX `col_idx` (`col` DESC);
Error Code: 1061. Duplicate key name 'col_idx';
So you can just catch the exception and ignore it, for example in PHP:
try {
$db->query('ALTER TABLE `my_table` ADD INDEX `col_idx` (`col` DESC) VISIBLE;');
} catch (PDOException $ex) {
if ($exception$ex->errorInfo[2] == 1061) {
// Index already exists
} else {
// Another error occurred
}
}