我正在尝试在访问数据库中检索一行的一个字段。我目前的设置大约需要100毫秒。有没有一个更快的方法来处理单个字段?
Public Function GetEntityConfig(ByVal pintID As Integer) As aadXML.XMLDoc
Dim objRtn As New aadXML.XMLDoc, myreader As OleDbDataReader
Dim Query As New OleDbCommand("Select e_config from entity where e_id = " & pintID, CurrentActiveConnectionToDB)
If CurrentActiveConnectionToDB.State = False Then
CurrentActiveConnectionToDB.Open()
End If
myreader = Query.ExecuteReader()
myreader.Read()
objRtn.LoadXML(myreader.Item("e_config"))
myreader.Close()
GetEntityConfig = objRtn
CurrentActiveConnectionToDB.Close()
End Function
首先,您应该学习使用参数,而不是用输入值来修饰查询字符串。
您的查询是:
Select e_config
from entity
where e_id = ?
对于此查询,索引将加快速度:
create index idx_entity_e_d_e_config on entity(e_id, e_config);
您不必在索引中包含e_config
;这是有帮助的,但仅是微不足道的。