ALTER TABLE t_test_warning_exception DROP INDEX uk_warning_exception_open, ADD COLUMN open_threshold_id BIGINT GENERATED ALWAYS AS ( IF(exception_status = 'OPEN', threshold_id, NULL) ) STORED AFTER exception_status, ADD UNIQUE KEY uk_warning_exception_open (test_id, metric_code, open_threshold_id);