Skip to content

Commit 8f721f2

Browse files
committed
Add missing database indexes for performance
- Add index on quotes.chat_id: all queries filter by this column - Add index on reminders.time: used in ORDER BY clauses - Add composite indexes on reminders(chat_id, time) and reminders(user_id, time) for optimal query performance
1 parent 77442de commit 8f721f2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- +migrate Up
2+
3+
-- Add index on quotes.chat_id for better filtering performance
4+
-- All quote queries filter by chat_id
5+
ALTER TABLE `quotes`
6+
ADD INDEX `chat_id` (`chat_id`);
7+
8+
-- Add index on reminders.time for ORDER BY operations
9+
ALTER TABLE `reminders`
10+
ADD INDEX `time` (`time`);
11+
12+
-- Add composite index on reminders(chat_id, time)
13+
-- Optimizes: SELECT ... WHERE chat_id = ? ORDER BY time
14+
ALTER TABLE `reminders`
15+
ADD INDEX `chat_id_time` (`chat_id`, `time`);
16+
17+
-- Add composite index on reminders(user_id, time)
18+
-- Optimizes: SELECT ... WHERE chat_id IS NULL AND user_id = ? ORDER BY time
19+
ALTER TABLE `reminders`
20+
ADD INDEX `user_id_time` (`user_id`, `time`);

0 commit comments

Comments
 (0)