diff --git a/docs/2022-07-31-sql.html b/docs/2022-07-31-sql.html
index 37d799a..7e00638 100644
--- a/docs/2022-07-31-sql.html
+++ b/docs/2022-07-31-sql.html
@@ -196,6 +196,29 @@
PRIMARY KEY (id),
INDEX idx_user_id (user_id)
);
+
+
+ If use composite index, order is important, either both
+ DESC
or both ASC
, do not mix:
+
+
+
CREATE INDEX idx_user_id_created_at
+ ON user_upload (user_id, created_at);
+
+-- Do not
+SELECT *
+FROM user_upload
+ORDER BY user_id, created_at DESC;
+
+-- Do
+SELECT *
+FROM user_upload
+ORDER BY user_id DESC, created_at DESC;
+
+-- Or do
+SELECT *
+FROM user_upload
+ORDER BY user_id, created_at;
Use EXPLAIN
to check if index is used or not:
diff --git a/posts/2022-07-31-sql.md b/posts/2022-07-31-sql.md
index af08cc5..d157dca 100644
--- a/posts/2022-07-31-sql.md
+++ b/posts/2022-07-31-sql.md
@@ -72,6 +72,29 @@ CREATE TABLE user_upload
);
```
+If use composite index, order is important, either both `DESC` or both `ASC`, do
+not mix:
+
+```sql
+CREATE INDEX idx_user_id_created_at
+ ON user_upload (user_id, created_at);
+
+-- Do not
+SELECT *
+FROM user_upload
+ORDER BY user_id, created_at DESC;
+
+-- Do
+SELECT *
+FROM user_upload
+ORDER BY user_id DESC, created_at DESC;
+
+-- Or do
+SELECT *
+FROM user_upload
+ORDER BY user_id, created_at;
+```
+
Use `EXPLAIN` to check if index is used or not:
- [For MySQL 5.7](https://dev.mysql.com/doc/refman/5.7/en/explain-output.html)