Skip to content

Commit

Permalink
add: indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
thutasann committed Jan 31, 2025
1 parent e3ed7d1 commit 4116a50
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sql/full_course/indexes/indexes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- INDEX (BTree data structure)
-- Indexes are used to find values within a specific column more quickly
-- MySQL normally searches sequentially through a column
-- The longer the column, the more expensive the operation is
-- UPDATE takes more time, SELECT takes less time
SELECT * FROM customers;

SHOW INDEXES FROM customers;

CREATE INDEX last_name_idx
ON customers(last_name);

SELECT * FROM customers
WHERE last_name = "Puff";

CREATE INDEX last_name_first_name_idx
ON customers(last_name, first_name);

ALTER TABLE customers
DROP INDEX last_name_idx;

SELECT * FROM customers
WHERE last_name = "Puff" AND first_name = "Poppy";

0 comments on commit 4116a50

Please sign in to comment.