-- 性能优化索引（MySQL 兼容）
-- 注意：此文件需要手动在数据库中执行，如果索引已存在会报错（可忽略）

-- users 表索引
ALTER TABLE users ADD INDEX idx_users_phone (phone);
ALTER TABLE users ADD INDEX idx_users_is_active (is_active);
ALTER TABLE users ADD INDEX idx_users_last_active_time (last_active_time);
ALTER TABLE users ADD INDEX idx_users_created_at (created_at);

-- payments 表索引
ALTER TABLE payments ADD INDEX idx_payments_user_id (user_id);
ALTER TABLE payments ADD INDEX idx_payments_status (status);
ALTER TABLE payments ADD INDEX idx_payments_created_at (created_at);
ALTER TABLE payments ADD INDEX idx_payments_user_status (user_id, status);

-- orders 表索引
ALTER TABLE orders ADD INDEX idx_orders_user_id (user_id);
ALTER TABLE orders ADD INDEX idx_orders_status (status);
ALTER TABLE orders ADD INDEX idx_orders_created_at (created_at);
ALTER TABLE orders ADD INDEX idx_orders_user_status (user_id, status);

-- user_works 表索引（高频查询优化）
ALTER TABLE user_works ADD INDEX idx_user_works_username (username);
ALTER TABLE user_works ADD INDEX idx_user_works_status (status);
ALTER TABLE user_works ADD INDEX idx_user_works_task_id (task_id);
ALTER TABLE user_works ADD INDEX idx_user_works_created_at (created_at);
ALTER TABLE user_works ADD INDEX idx_user_works_username_status (username, status);
ALTER TABLE user_works ADD INDEX idx_user_works_is_public_status (is_public, status);

-- text_to_video_tasks 表索引
ALTER TABLE text_to_video_tasks ADD INDEX idx_text_to_video_tasks_task_id (task_id);
ALTER TABLE text_to_video_tasks ADD INDEX idx_text_to_video_tasks_username (username);
ALTER TABLE text_to_video_tasks ADD INDEX idx_text_to_video_tasks_status (status);

-- image_to_video_tasks 表索引
ALTER TABLE image_to_video_tasks ADD INDEX idx_image_to_video_tasks_task_id (task_id);
ALTER TABLE image_to_video_tasks ADD INDEX idx_image_to_video_tasks_username (username);
ALTER TABLE image_to_video_tasks ADD INDEX idx_image_to_video_tasks_status (status);

-- storyboard_video_tasks 表索引
ALTER TABLE storyboard_video_tasks ADD INDEX idx_storyboard_video_tasks_task_id (task_id);
ALTER TABLE storyboard_video_tasks ADD INDEX idx_storyboard_video_tasks_username (username);
ALTER TABLE storyboard_video_tasks ADD INDEX idx_storyboard_video_tasks_status (status);

-- points_freeze_records 表索引
ALTER TABLE points_freeze_records ADD INDEX idx_points_freeze_records_task_id (task_id);
ALTER TABLE points_freeze_records ADD INDEX idx_points_freeze_records_username (username);
ALTER TABLE points_freeze_records ADD INDEX idx_points_freeze_records_status (status);
