Quantcast

Ruby on Rails, Io, Lisp, JavaScript, Dynamic Languages, Prototype-based programming and more...

Technoblog reader special: $10 off web hosting by FatCow!

Monday, July 10, 2006

Use or Force an Index with Rails

I just found an ActiveRecord hint that is very useful and very undocumented. If you are working with a table who's indexes are sufficiently complex, MySQL will inevitably guess the wrong index at times. To counteract that in SQL, you write:
SELECT * FROM alphas USE INDEX (some_index) WHERE betas = gamas;

Rails does not have a corresponding :use_index for find methods. However, it does have an un-documented :from option.
Alpha.find(:all, :from => "alphas USE INDEX (some_index)", :conditions => "betas = gamas")

Keep this in the back of your mind if you are going to be working with complex database tables any time soon.

You should follow me on twitter here.

Technoblog reader special: click here to get $10 off web hosting by FatCow!

9 Comments:

Anonymous Dan said...

I had the same problems with mysql not performing as it should, I used:

[code]
@posts = ForumPosts.Find(:all, :order => 'touched DESC', :joins => 'FORCE INDEX (post_touched)')
[/code]

I had written about it on my blog, but have been in the same situation as you - my host f*cked me sideways...

2:55 AM, July 11, 2006

 
Anonymous Small Business Web Hosting said...

Dan,

Switch Web Hosting Companies!

6:30 AM, October 01, 2006

 
Blogger Bobbie the GrandParents Home Finder said...

We have many offerings. Please review
Of course Bloggers get 10% discount
Refer a company and get 10% commission

* We have super fast servers with many upstream providers.
* 250 strands of fiber
* power for months on battery
* first month free if you mention blogger for 10% off

** many hosted solutions **
hosted solution provider Great Plains
Cisco Support
Novell GroupWise to exchange
hosted solution QuickBooks Pro
asterisk voip hosted pbx
Hosted Exchange Server
hosted solution for Microsoft Dynamics
hosted cisco platform for voip
** Need a Job? ***
IT Staffing
* Outsourcing *
IT Outsourcing
** Have a Case to win ***
Forensic Services

9:10 PM, August 05, 2007

 
Anonymous Anonymous said...

This company provide amazing tier one level connectivity. You have to check it out.
CoLocation Los Angeles

6:56 PM, August 16, 2007

 
Blogger Lai Weizhou said...

chung cư tháp doanh nhân
tháp doanh nhân / tháp doanh nhân hà đông / dự án tháp doanh nhân hà đông / chung cư the legend / chung cư the legend 109 nguyễn tuân
chung cư 360 giải phóng / dự án 360 giải phóng / chung cư vietracimex / chung cư 201 minh khai / chung cư thanh xuân tower / chung cư 35 lê văn thiêm
chung cư eco green city / chung cu eco green city / chung cư eco green city nguyễn xiển / chung cu eco green city nguyen xien / eco green city / eco green city nguyễn xiển / dự án eco green city / toà ct4 eco green city / toà ct3 eco green city / toà ct1 eco green city

11:07 AM, May 21, 2016

 
Blogger Zhenhong Bao said...

longchamp handbags
coach outlet
true religion canada
oakley sunglasses
mulberry handbags
reebok shoes
burberry outlet
ralph lauren outlet
ralph lauren polo
ralph lauren
hermes belt for sale
versace sunglasses on sale
fitflops clearance
nike air max 90
thomas sabo outlet
pandora outlet
tory burch outlet
coach outlet
kobe shoes
oakley sunglasses
ghd hair straighteners
ray ban sunglasses
coach outlet online
tory burch shoes
coach outlet
ralph lauren outlet
mulberry handbags
michael kors outlet online
discount oakley sunglasses
burberry sunglasses on sale
ralph lauren pas cher
replica watches
oakley sunglasses
chrome hearts outlet online
longchamp pliage
20160531zhenhong

6:20 PM, May 30, 2016

 
Blogger Hua Cai said...

fitflops sale
ugg outlet
mulberry handbags sale
true religion outlet
michael kors outlet clearance
true religion jeans
new balance outlet
michael kors outlet clearance
ferragamo outlet
christian louboutin shoes
links of london
michael kors wholesale
tory burch outlet online
prada sneakers
true religion outlet
swarovski outlet
jordan pas cher
nike air force 1
calvin klein underwear
louis vuitton pas cher
true religion jeans
ferragamo outlet
ferragamo shoes sale
louis vuitton outlet store
tiffany and co
coach outlet store
gucci outlet
louis vuitton outlet
oakley sunglasses uk
true religion jeans
michael kors outlet online
mulberry outlet
nike free 5
celine outlet online
louis vuitton bags
20160804caihuali

10:43 PM, August 03, 2016

 
Blogger Fangyaya said...

air jordan 13
gucci outlet
adidas outlet
michael kors outlet
true religion outlet
cheap jordans
cheap jordans
louis vuitton outlet
coach outlet
uggs for men
michael kors outlet
air jordan 8
ralph lauren uk
true religion jeans
fitflops
louis vuitton handbags uk
ralph lauren polo shirts
ugg sale
ugg boots
rolex watches
mlb jerseys
oakley sunglasses
ray ban sunglasses uk
nike outlet store
michael kors outlet online
louis vuitton handbags
uggs on sale
supra shoes
hermes handbags
chenyingying20160908

6:52 PM, September 07, 2016

 
Blogger John said...

ugg outlet
burberry bags
cheap ugg boots
cheap oakley sunglasses
ugg pas cher
polo ralph lauren outlet online
ysl handbags
oakley sunglasses outlet
ed hardy outlet
michael kors outlet canada
2016927yuanyuan

6:23 PM, September 26, 2016

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home

 

If you like this blog, you might also like top photography schools.