1

我有一个 Microsoft Access 文件 (.mdb),上面有 2.000.000 行,我正在使用一个查询:

select count(*) from tblABC where instr(Column1 , "something") > 0

让所有记录都包含“某物”一词。然而,查询在返回结果之前冻结了 40 秒,这对我来说很糟糕,因为我通常需要这样做。我如何通过给它一个像其他数字列一样的索引来优化搜索?

4

1 回答 1

1

正如上面评论所建议的那样,LIKE "*...*"似乎确实比InStr(...) > 0. 当我在一个有一百万行的表上测试它时,代码

Sub SearchTest()
Dim t0 As Single, strWhere As String
t0 = Timer
strWhere = "InStr(TextField, ""86753"") > 0"
Debug.Print DCount("*", "MillionRows", strWhere) & " row(s) found"
Debug.Print "Search took " & Format(Timer - t0, "0.0") & " seconds"
End Sub

报道

20 row(s) found
Search took 5.4 seconds

当我将搜索字符串更改为

strWhere = "TextField LIKE ""*86753*"""

据报道

20 row(s) found
Search took 3.4 seconds

我还在 [TextField] 上使用和不使用索引对其进行了测试,在我的情况下,索引对结果没有影响。但是,[TextField] 也是唯一的(“Item0000001”、“Item0000002”、...“Item1000000”),因此如果该字段包含不同的数据,则该字段上的索引可能会有所不同(尽管我不会打赌在上面)。

于 2013-10-19T14:12:43.860 回答