簡體   English   中英

將C#類型Int64的參數傳遞到T-SQL bigint存儲過程參數時,性能下降

[英]performance hit when passing argument of C# type Int64 into T-SQL bigint stored procedure parameter

當我開始將數據類型[bigint]用於存儲過程參數時,我注意到應用程序存在嚴重的性能問題。 以下快速代碼的參數數據類型為[nvarchar](50) 下面是我更改的一些代碼,此簡單調用從<1秒(快速代碼)更改為超過20秒(慢速代碼)。 是什么導致此問題? 如何使用[bigint]保持性能? 我在.NET 4.0中使用Enterprise Library 5(數據庫應用程序塊)。

之前(快速):

            Database db = DatabaseFactory.CreateDatabase("APP");
            DbCommand cmd = db.GetStoredProcCommand("sp_test");
            db.AddInParameter(cmd, "@crud_command", DbType.String, "read");
            db.AddInParameter(cmd, "@network_login", DbType.String, "abc231");
            db.AddInParameter(cmd, "@id_filter", DbType.String, id_filter);
            DataSet ds = db.ExecuteDataSet(cmd);

之后(慢):

            Database db = DatabaseFactory.CreateDatabase("APP");
            DbCommand cmd = db.GetStoredProcCommand("sp_test");
            db.AddInParameter(cmd, "@crud_command", DbType.String, "read");
            db.AddInParameter(cmd, "@network_login", DbType.String, "abc231");
            db.AddInParameter(cmd, "@id_filter", DbType.Int64, Convert.ToInt64(id_filter));
            DataSet ds = db.ExecuteDataSet(cmd);

您必須檢查db中的類型,確保參數的類型與您要查詢的列相同(我想這是varchar,而不是bigint)。 如果它們不同,則比較將進行轉換,並且sql server將不使用索引(無法優化)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM