2010-11-26 6 views
10

私は7行を返し、データベースでは4ms、インスタンス化するには1075msかかるクエリを持っています。これは時代の単なる一例であり、オブジェクトによって異なりますが、それには時間がかかりすぎるとは思わしくありません。どのように速度を向上させる上の任意のポインター?リスト<int>は、Nhibernate基準でインスタンス化するのに時間がかかります

var criteria = 
       GetSession().CreateSQLQuery(
        @" 
        select circt_id as CircuitId from normal_upstream 
         where dni_equip_type = 'A' 

         start with up_equip_stn_no in (:UpStationNo1) 
         connect by prior equip_stn_no = up_equip_stn_no 
         union 
         select circt_id as CircuitId 
         from normal_upstream 
         where up_equip_stn_no in (:UpStationNo1)") 
        .AddScalar("CircuitId", NHibernateUtil.Int32).SetParameterList("UpStationNo1",upstreamStations) 
        .List<int>() 

SQLクエリは、すべてのヘルプは高く評価され

select 
    circt_id as CircuitId 
from normal_upstream 

where dni_equip_type = 'A' 

          start with up_equip_stn_no in (
    'B' /* :p0 */) 
         connect by prior equip_stn_no = up_equip_stn_no 
         union 
         select 
circt_id as CircuitId 
         from normal_upstream  
where up_equip_stn_no in (
    'B' /* :p1 */) 

を生成しました。ありがとう

+0

それは長い間、それが実行されるたびに、または単に最初にこれを取るん:ここで

は、私が現在使用しているコードのですか?どのバイトコードジェネレータを使用していますか? – jonnii

+0

@jonnii、毎回長い時間がかかります。また、バイトコードはNHibernate.ByteCode.Castleです。 – Gage

+0

@Gage IEnumerable の代わりにIEnumerableを返すように変更してList()を使用するとどうなりますか? – jonnii

答えて

5

どうやらそれを減速させていたのは、SetParameterList呼び出しでした。 SQLを書式設定する前に、8msデータベースと485msインスタンス化のラインに沿って何かを得ることができます。私は何か速く持っていたいが、それは今のところするだろう。

var sql = 
      String.Format(
       @"select circt_id as CircuitId from normal_upstream 
       where dni_equip_type = 'FDR_OCR' 
         start with up_equip_stn_no in ({0}) 
         connect by prior equip_stn_no = up_equip_stn_no 
         union 
         select circt_id as CircuitId 
         from normal_upstream 
         where up_equip_stn_no in ({0})", 
       String.Join(",",upstreamStations.Select(x=>"'"+x+"'").ToArray())); 
     var criteria = 
      GetSession().CreateSQLQuery(sql) 
       .AddScalar("CircuitId", NHibernateUtil.Int32) 
       .List(); 
      return criteria; 
+0

あなたはNHのどのバージョンを使用していますか? – Jaguar

+0

@Jaguar、2.1.2.4000 – Gage

+0

strange。私はさまざまなシナリオや型でSetParameterListを使用しましたが、私はperfヒットを見たことがない。 upstreamStationsはint []なのでしょうか? – Jaguar

関連する問題