Mysql Indexing

2,472 views
2,324 views

Published on

The Basic concept of MySql Indexing

Published in: Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,472
On SlideShare
0
From Embeds
0
Number of Embeds
18
Actions
Shares
0
Downloads
59
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Mysql Indexing

  1. 1. MySQL Database Indexing <ul><li>By Abdul Barek </li></ul><ul><li>tekSymmetry, LLC </li></ul><ul><li>12th January, 2010 </li></ul>
  2. 2. What is Indexing? <ul><li>Like our text/reference books indexing </li></ul><ul><li>1000 pages of contents (Data) </li></ul><ul><li>4-5 pages indexes (meta data) to retrieve data quickly </li></ul><ul><li>Indexes with page number (pointer) </li></ul>
  3. 3. Advantages <ul><li>Quick (less time) in data retrieval </li></ul><ul><li>Less work for DB Engine in data searching </li></ul>
  4. 4. Disadvantages <ul><li>Requires extra space (4-5 pages for books) </li></ul><ul><li>Create/update/delete index when DB insert/update/delete on data </li></ul><ul><li>Using too many indexes will slow down database server (I.e.; index for ‘the’, ‘on’ of books) </li></ul>
  5. 5. Fetch >> Operation <ul><li>95% fetch/data retrieval </li></ul><ul><li>5% insert/update/delete </li></ul><ul><li>So why not indexing? </li></ul>
  6. 6. How to create/drop index <ul><li>CREATE INDEX indexName ON tableName(columnName) </li></ul><ul><li>DROP INDEX indexName ON tableName </li></ul>
  7. 7. A students table (without index on name field)
  8. 8. Select statement without index <ul><li>EXPLAIN SELECT * FROM ‘students’ WHERE name =‘shishir’ </li></ul>
  9. 9. Select statement with index <ul><li>EXPLAIN SELECT * FROM ‘students’ WHERE name =‘shishir’ </li></ul>
  10. 10. Where will we apply index? <ul><li>All fields in where clause </li></ul><ul><li>All foreign keys </li></ul>Where will we not apply index? <ul><li>Fields which is almost constant - select * from news where active=1 </li></ul>
  11. 11. Where index will work <ul><li>Column = value </li></ul><ul><li>LIKE ‘abc%‘, Full text search </li></ul><ul><li>Comparison(<, <=, >, >=, BETWEEN) </li></ul><ul><li>All joins with foreign keys </li></ul><ul><li> </li></ul>Where index will not work <ul><li>LIKE ‘%abc%‘ </li></ul><ul><li>LIKE ‘%abc’ </li></ul><ul><li> </li></ul>
  12. 12. Types of mysql indexing <ul><li>Single Column </li></ul><ul><li>Select * from table where name=‘abc’ </li></ul><ul><li>Multi-column </li></ul><ul><li>Select * from table where name=‘abc’ AND age=18 create index indexName on table(col1,col2..) </li></ul><ul><li>Multi column will be single column when ‘OR’ Select * from table where name=‘abc’ OR age=18 </li></ul>
  13. 13. MySQL Indexing methods
  14. 14. Indexing graphical example (B+)
  15. 15. Indexing graphical example (B+) - cont
  16. 16. Indexing graphical example (B+) - Range
  17. 17. Indexing graphical example (Hash)
  18. 18. Question?

×