SET @idx_count := (
  SELECT COUNT(1)
  FROM INFORMATION_SCHEMA.STATISTICS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'stu_rank'
    AND INDEX_NAME = 'idx_stu_rank_update_school'
);
SET @ddl := IF(
  @idx_count = 0,
  'ALTER TABLE stu_rank ADD INDEX idx_stu_rank_update_school (update_time, school_id)',
  'SELECT ''idx_stu_rank_update_school exists'''
);
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SET @idx_count := (
  SELECT COUNT(1)
  FROM INFORMATION_SCHEMA.STATISTICS
  WHERE TABLE_SCHEMA = DATABASE()
    AND TABLE_NAME = 'stu_rank'
    AND INDEX_NAME = 'idx_stu_rank_update_class'
);
SET @ddl := IF(
  @idx_count = 0,
  'ALTER TABLE stu_rank ADD INDEX idx_stu_rank_update_class (update_time, school_class_id)',
  'SELECT ''idx_stu_rank_update_class exists'''
);
PREPARE stmt FROM @ddl;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
