Lazy Indexing
Upcoming SlideShare
Loading in...5
×
 

Lazy Indexing

on

  • 4,390 views

Easily optimize your Rails app by adding database indexes where you need them.

Easily optimize your Rails app by adding database indexes where you need them.

Statistics

Views

Total Views
4,390
Views on SlideShare
4,327
Embed Views
63

Actions

Likes
3
Downloads
61
Comments
1

3 Embeds 63

http://coderwall.com 50
http://www.slideshare.net 7
http://www.linkedin.com 6

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Lazy Indexing Lazy Indexing Presentation Transcript

  • LAZY INDEXING matt aimonetti sdruby
  • before we start I’m not a Database Administrator This talk only covers MySQL You will still need to understand indexing Dubbed version of this presentation will be available from Patrick ;)
  • indexing SELECT * FROM users WHERE last_name = 'Aimonetti'; NO INDEX look at each row in the table, one at a time, to find all matching records (full table scan = SLOW)
  • indexing SELECT * FROM users WHERE last_name = 'Aimonetti'; INDEX simply follows the b-tree data structure until the Aimonetti entries have been found = WAY FASTER
  • indexing class User < ActiveRecord::Base has_many :team_members, :dependent => :destroy has_many :projects, :through => :team_members end current_user.projects SELECT `projects`.* FROM `projects` INNER JOIN team_members ON projects.id = team_members.project_id WHERE ((`team_members`.user_id = 1))
  • indexing how to know what indexes to create?
  • indexing N? HE W Every time you are using one of these associations in a model: belongs_to, has_many, has_one, or has_and_belongs_to_many association
  • indexing N? HE W ✓ use a join in your query ✓query non-foreign-key column ✓ sort on a column or combination of columns
  • T? indexing HA W EXPLAIN obtain information about how MySQL executes a SELECT statement
  • indexing query-reviewer plugin http://code.google.com/p/query-reviewer/ by Kongregate and David Stevenson
  • indexing add an index from your migrations: add_index :invoices, [:client_id, :invoiced_on] remove an index from your migrations: remove_index :invoices, [:client_id, :invoiced_on]
  • indexing resources: http://code.google.com/p/query-reviewer/ http://weblog.jamisbuck.org/2006/10/23/indexing-for-db-performance http://www.mysqlperformanceblog.com/