Reputation: 57
I am new to SQL. If i create an index on a column, I know it is going to make the search faster. But how do I use the index later? For example, CREATE INDEX ID_INDEX ON Students(ID); Is there a SQL command that shows how I use this index? If I also do SELECT * FROM Students WHERE ID = 3, is there a big difference?
Upvotes: 1
Views: 317
Reputation: 108641
Deciding what indexes to use, and whether they should be on single columns or multiple columns, is a task that takes some learning. See this: https://use-the-index-luke.com .
But here's the really REALLY cool thing about indexes:
The MySQL server software automatically figures out how to apply them to satisfy SQL queries. So, we can add or remove indexes during the lifetime of a database, with absolutely no change required to the queries. New indexes can sometimes dramatically speed up queries, sometimes by taking O(n**2) or O(n) operations and converting them to O(log n) in complexity.
This is important, seeing as how the lifetime of a database for a successful application is measured in decades, not years. As a database grows with use, new indexes keep it humming along.
Upvotes: 1