From 5cffdc47c72f640a778b2aaebbbaf9b24bcc327a Mon Sep 17 00:00:00 2001
From: Hau Nguyen
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:
TEXT
if you don't care, just want to store something.
+ LIMIT
+
+ Prefer LIMIT 10 OFFSET 5
to LIMIT 5, 10
to avoid
+ misunderstanding.
+