我正在使用一個非常複雜的查詢從我們的一個賬單數據庫中檢索一些數據。爲什麼OracleDataAdapter.Fill()非常慢?
我遇到了一個問題,即在使用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
我有類似的SQL Server的問題,但沒有滿意的解決方案。如果您可以運行數據包跟蹤或應用程序跟蹤來比較這兩個查詢,那麼可能會對此有所瞭解。 – dsolimano 2010-03-12 18:37:58