From 5cffdc47c72f640a778b2aaebbbaf9b24bcc327a Mon Sep 17 00:00:00 2001 From: Hau Nguyen Date: Fri, 16 Jun 2023 02:31:21 +0700 Subject: [PATCH] feat: morr about index --- docs/2022-07-31-sql.html | 28 ++++++++++++++++++++++++++-- posts/2022-07-31-sql.md | 20 ++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/docs/2022-07-31-sql.html b/docs/2022-07-31-sql.html index 7059365..b9485d3 100644 --- a/docs/2022-07-31-sql.html +++ b/docs/2022-07-31-sql.html @@ -126,8 +126,23 @@

For example, create index in MySQL:

-
CREATE INDEX `idx_timestamp`
-    ON `user_upload` (`timestamp`);
+
CREATE INDEX idx_user_id
+    ON user_upload (user_id);
+
+

+ If create index inside CREATE TABLE, + prefer INDEX to KEY: +

+
+
CREATE TABLE user_upload
+(
+    id      int(11) NOT NULL,
+    user_id int(11) NULL DEFAULT NULL,
+    PRIMARY KEY (id),
+    INDEX idx_user_id (user_id)
+);

Use EXPLAIN to check if index is used or not: