4

かなり複雑なクエリを使用して、請求データベースの 1 つからデータを取得しています。

SQL Developerで実行するとクエリがかなり速く完了するように見えるが、OracleDataAdapter.Fill()メソッドを使用するとクエリが完了しないという問題が発生しています。

私は約1000行を読み取ろうとしているだけで、クエリはSQL Developerで約20秒で完了します。

このような劇的なパフォーマンスの違いの原因は何ですか? 同じ関数を使用してすばやく実行できるクエリが他にもたくさんあります。


クエリを実行するために使用しているコードは次のとおりです。

using Oracle.DataAccess.Client;

...

public DataTable ExecuteExternalQuery(string connectionString, string providerName, string queryText)
{
    DbConnection connection = null;
    DbCommand selectCommand = null;
    DbDataAdapter adapter = null;

    switch (providerName)
    {
        case "System.Data.OracleClient":
        case "Oracle.DataAccess.Client":
            connection = new OracleConnection(connectionString);
            selectCommand = connection.CreateCommand();
            adapter = new OracleDataAdapter((OracleCommand)selectCommand);
            break;
        ...
    }

    DataTable table = null;
    try
    {
        connection.Open();

        selectCommand.CommandText = queryText;
        selectCommand.CommandTimeout = 300000;
        selectCommand.CommandType = CommandType.Text;

        table = new DataTable("result");
        table.Locale = CultureInfo.CurrentCulture;
        adapter.Fill(table);
    }
    finally
    {
        adapter.Dispose();

        if (connection.State != ConnectionState.Closed)
        {
            connection.Close();
        }
    }

    return table;
}

そして、これが私が使用しているSQLの一般的な概要です。

with
  trouble_calls as
  (
    select
      work_order_number,
      account_number,
      date_entered
    from
      work_orders
    where
      date_entered >= sysdate - (15 + 31)  -- Use the index to limit the number of rows scanned
     and
      wo_status not in ('Cancelled')
     and
      wo_type = 'Trouble Call'
  )
select
  account_number,
  work_order_number,
  date_entered
from
  trouble_calls wo
where
  wo.icoms_date >= sysdate - 15
 and
  (
    select
      count(*)
    from
      trouble_calls repeat
    where
      wo.account_number = repeat.account_number
     and
      wo.work_order_number <> repeat.work_order_number
     and
      wo.date_entered - repeat.date_entered between 0 and 30
  ) >= 1
4

3 に答える 3

4

このコードは私を助けてくれました、試してみてください:

using (OracleConnection conn = new OracleConnection())
{
     OracleCommand comm = new OracleCommand();
     comm.Connection = conn;
     comm.FetchSize = comm.FetchSize * 16;
     comm.CommandText = "select * from some_table";

     try
     {
          conn.Open();
          OracleDataAdapter adap = new OracleDataAdapter(comm);
          System.Data.DataTable dt = new System.Data.DataTable();
          adap.Fill(dt);
     }
     finally
     {
          conn.Close();
     }
}

トリックは次のとおりです (8 から 64 までの値を試して、ケースに最適なものを見つけてください)。

comm.FetchSize = comm.FetchSize * 16;

アップデート:

改善されたコードは次のとおりです。

OracleConnection myConnection = new OracleConnection(myConnectionString);
OracleCommand myCommand = new OracleCommand(mySelectQuery, myConnection);
myConnection.Open();
using (OracleDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection))
{
    // here goes the trick
    // lets get 1000 rows on each round trip
    reader.FetchSize = reader.RowSize * 1000;

    while (reader.Read())
    {
        // reads the records normally
    }
}// close and dispose stuff here

ここから

于 2015-10-13T12:31:41.427 に答える
2

Microsoft Data Provider for Oracle とネイティブの Oracle Data Provider の使用には既知のパフォーマンスの違いがあります。

両方試しましたか?

このクエリで何を達成しようとしていますか? 技術的なことは忘れてください。すべての目的だけです。おそらく、あなたのクエリに可能なチューンがあります。

プロファイラーを使用して、スタックする場所を確認しましたか?

于 2010-03-12T17:47:11.810 に答える
1

Oracle クエリによって返されるカルチャと日付が異なり、アプリケーションの解析に多くの時間がかかっていると思います。

于 2010-03-12T17:50:01.113 に答える