-2

SQL クエリを最適化したいと考えています。パフォーマンス テストを行わずに、最も時間のかかるクエリはどれですか? 私は彼らが同じ結果を返すとほぼ確信しています。

  • !MyClass.find(:first, :conditions => c).nil?
  • MyClass.count(:conditions => c) > 0
  • MyClass.count(:conditions => c, :limit => 1) > 0

よろしく

4

2 に答える 2

0

答えが証拠だと思ったので質問します。そうではないようです。

そのため、いくつかのクエリに平均時間を費やしています。時間順に並べた結果は次のとおりです。

.count(:conditions => c, :limit => 1) > 0;
=> 0.042037

.count(:conditions => c) > 0
=> 0.037781

.count(:select => '1', :conditions => c) > 0
=> 0.035976

.count(:select => '1', :conditions => c, :limit => 1) > 0
=> 0.034157

.find(:first, :conditions => c).nil?
=> 0.000377

.find(:first, :select => '1', :conditions => c).nil?
( equivalent to .exists?(c) )
=> 0.000184

最後のものは最も効率的です。のヒントをありがとう:select => '1'

于 2013-05-03T09:42:21.407 に答える