該功能需要約1.2秒的時間才能執行。我無法理解爲什麼?是因爲內部聯接嗎?如果是,那我該如何提高執行速度?我正在使用Microsoft企業庫。如何提高此功能的性能?
Public Shared Function GetDataByInterests(ByVal accountId As Integer) As Object
Dim details As New List(Of GetIdBasedOnInterest)()
Dim getIDs As New GetIdBasedOnInterest
Dim interests As String = ""
Dim db As SqlDatabase = Connection.Connection
Using cmdGeneric As DbCommand = db.GetSqlStringCommand("SELECT Interests.InterestName FROM UserInterests INNER JOIN Interests ON UserInterests.InterestID = Interests.InterestID WHERE [email protected]")
db.AddInParameter(cmdGeneric, "AccountID", SqlDbType.Int, accountId)
Dim dsInterests As DataSet = db.ExecuteDataSet(cmdGeneric)
For i = 0 To dsInterests.Tables(0).Rows.Count - 1
If i = dsInterests.Tables(0).Rows.Count - 1 Then
interests = interests & dsInterests.Tables(0).Rows(i).Item(0).ToString
Else
interests = interests & dsInterests.Tables(0).Rows(i).Item(0).ToString & ","
End If
Next
End Using
getIDs.InterestName = interests
details.Add(getIDs)
Return details
End Function
您必須先跟蹤並查看您的sql服務器上的選擇命令的速度。 – Aristos
我該怎麼做? – Monodeep
在SSMS中爲典型的accountID運行SQL。需要多長時間(您可以選擇前後查看的當前日期/時間戳)?這將表明時間是用在SQL還是VB代碼中。 InterestID是否被索引在兩個表上(即被定義爲索引還是主鍵)?如果不是,那麼如果表格很大,這會減慢查詢速度。 – NigelK