DbFit中的大型数据集比较超时

时间:2013-10-09 09:55:57

标签: sql-server timeout dbfit

查询总结按货币分组的前500个帐户余额,用于来自新SQL 2012服务器和现有服务器的比较查询,以验证新2012服务器中没有更改。

将超时属性设置为| set option | command | 900 |但无济于事。

以下是错误摘录:

System.Data.SqlClient.SqlException(0x80131904):超时已过期。操作完成之前经过的超时时间或服务器没有响应。    在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection)    在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()    在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)    在System.Data.SqlClient.SqlDataReader.SetMetaData(_SqlMetaDataSet metaData,Boolean moreInfo)    在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)    在System.Data.SqlClient.SqlDataReader.ConsumeMetaData()    在System.Data.SqlClient.SqlDataReader.get_MetaData()    在System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString)    在System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async)    在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method,DbAsyncResult result)    在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method)    在System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior,String method)    在System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior行为)    在System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior行为)    在System.Data.Common.DbDataAdapter.FillInternal(DataSet数据集,DataTable [] datatables,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand命令,CommandBehavior行为)    在System.Data.Common.DbDataAdapter.Fill(DataSet dataSet,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand命令,CommandBehavior行为)    在System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)    在dbfit.DatabaseTest.GetDataTable(符号符号,字符串查询,IDbEnvironment环境,Int32 rsNo)    在dbfit.fixture.StoreQuery.DoTable(解析表)    at fitSharp.Fit.Operators.InterpretFlow.DoTable(Tree`1 table,Interpreter activeFixture,Boolean inFlow)

我尝试将要检查的行数从500减少到300,这似乎有效,但是大数据集非常适合突出显示任何差异。

我还在考虑将查询更改为其他内容,以将其分解为更小的结果集或创建替代

如果有人有更好的解决方案来优化查询,则查询如下:

       select 
       TOP 1000 fab.DateKey,be.BK_ActOId,be.PtId,be.PDesc,
       be.OId,be.ODesc,be.SubOId,be.SubODesc,
       rc.Currency,SUM(CASE WHEN rc.Currency = '_NA' THEN FAB.Balance ELSE 0 END) as       bal_OrigCcy
       ,SUM(CASE WHEN rc.Currency = 'AUD' THEN FAB.Balance ELSE 0 END) as bal_AUD
       ,SUM(CASE WHEN rc.Currency = 'GBP' THEN FAB.Balance ELSE 0 END) as bal_GBP
       ,SUM(CASE WHEN rc.Currency = 'SGD' THEN FAB.Balance ELSE 0 END) as bal_SGD
       ,SUM(CASE WHEN rc.Currency = 'USD' THEN FAB.Balance ELSE 0 END) as bal_USD 
       from olap.v_FactAccB fab 
       inner join OLAP.v_DimCur dc on dc.CurrencyKey = fab.BalanceCurrencyKey 
       inner join olap.v_DimReportingCur rc on rc.CurrencyKey =          fab.ReportingCurrencyKey 
       inner join OLAP.v_DimBusinessEntity be on be.BusinessEntityKey = fab.BusinessEntityKey 
     and rc.Currency in ('_NA', 'AUD', 'GBP', 'SGD','USD') 
     and fab.DateKey = 20130912 
     and fab.PlatformKey = 1 
     group by fab.DateKey, be.BK_ActOId, be.PId, be.PDesc
    ,be.OId, be.ODesc, be.SubOId, be.SubODesc, rc.Currency 
     order by fab.DateKey, be.BK_ActOId, be.PId, be.PDesc, be.OId, be.ODesc, be.SubOId,    be.SubODesc, rc.Curr

是否有人有上述选择之外的其他选择

1 个答案:

答案 0 :(得分:0)

我会重写您的查询以使用PIVOT而不是重复的SUM(CASE... )

例如:

 select * from yourtable
pivot (SUM(balance) for currency in (_NA,AUD,GBP,SGD,USD)) p