Why the performance difference between TableAdapter.Fill data sources

十年热恋 提交于 2019-12-11 02:15:59

问题


I have a windows form app with a DataGridView populated by a TableAdapter. I'm using the Fill method to update the data for the UI in a looping Async sub like so.

Private Async Sub updateUI()
    Dim sw As New Stopwatch
    While True
        Await Task.Delay(3000)
        sw.Restart()
        'myTableAdapter.Fill(getDataWithMySQL())
        'myTableAdapter.Fill(myDataSet.myTable)
        myTableAdapter.Fill(myDataSet.myStoredProc)
        logger.Debug(sw.ElapsedMilliseconds)
    End While
End Sub

The getDataWithMySQL function is as follows:

Private Function getDataWithMySQL() As myDataSet.myDataTable
    Dim connStr As String = My.Settings.myConnectionString
    Dim sql As String = "SELECT ... LEFT JOIN ..."
    Dim dt As New myDataSet.myDataTable
    Using conn As New MySqlConnection(connStr)
        Using cmd As New MySqlCommand()
            With cmd
                .CommandText = sql
                .Connection = conn
            End With
            Try
                conn.Open()
                Dim sqladapter As New MySqlDataAdapter(cmd)
                sqladapter.Fill(dt)

            Catch ex As MySqlException
                MsgBox(ex.Message)
            End Try
        End Using
    End Using
    Return dt
End Function

myDataSet.myTable is the same as myDataSet.myStoredProc except it is created by joining tables in the DataSet designer. Obviously myDataSet.myStoredProc is the same query in a stored procedure in the source database.

So benchmarking the Fill with each method using a Stopwatch I get the following results:

  • myDataSet.myStoredProc
    ~750ms

  • myDataSet.myTable
    ~550ms

  • getDataWithMySQL()
    <10ms

So my question is, what is causing the performance difference here? I'd prefer to use myDataSet.myTable or myDataSet.myStoredProc but I don't know if it is possible to optimise them in some way so as to match the performance of getDataWithMySQL().

来源:https://stackoverflow.com/questions/28358425/why-the-performance-difference-between-tableadapter-fill-data-sources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!