ADO 搜索性能

发布于 2024-11-25 22:21:40 字数 259 浏览 2 评论 0原文

因为我对 ADO 的底层并不熟悉,所以我想知道使用 VB6 查找记录的两种方法中哪一种通常会产生更快的结果。

  1. 使用“select”语句并使用“where”作为限定符。如果记录集计数为零,则未找到该记录。

  2. 选择使用客户端游标迭代记录的所有记录,直到找到记录或根本找不到记录。

记录集在 10,000 条记录范围内,并且会不断增长。另外,除了上面提到的之外,我对任何能缩短搜索时间的事情都持开放态度。

Because I am not familiar with ADO under the hood, I was wonder which of the two methods of finding a record generally yields quicker results using VB6.

  1. Use a 'select' statement using 'where' as a qualifier. If the recordset count yields zero, the record was not found.

  2. Select all records iterating through records with a client-side cursor until record is found, or not at all.

The recordset is in the range of 10,000 records and will grow. Also, I am open to anything that will yield shorter search times other than what was mentioned.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓬勃野心 2024-12-02 22:21:40
SELECT count(*) FROM foo WHERE some_column='some value'

如果结果大于0,则在数据库中找到满足条件的记录。你不太可能比这更快。在 WHERE 子句中使用的列上的正确索引可以显着提高性能。

SELECT count(*) FROM foo WHERE some_column='some value'

If the result is greater than 0 the record satisfying your condition was found in the database. It is unlikely you would get any faster than this. Proper indexes on the columns you are using in the WHERE clause could considerably improve performance.

初熏 2024-12-02 22:21:40

在我能想到的每种情况下,使用 where 子句进行选择会更快。

即使在客户端代码将迭代整个数据库(例如 Access 等基于文件的数据库)的情况下,您也将使用用 C 或 C++ 编写的优化代码来执行选择(在数据库驱动程序中)。这总是比VB6。

对于数据库引擎(SQL、MySQL 等),性能提升甚至更为深远。通过使用 where 子句,您可以限制必须通过网络传输的数据量,从而极大地提高响应。

一些额外的性能提示:

  • 仅选择您想要的字段。
  • 在常用字段上构建索引
  • 观察您返回的记录集类型。如果您只是从数据库返回数据,请使用只进游标。

最后,VB.NET 的数据库性能令我震惊,它比最快的 VB6 代码快了好几倍。

In every case I can think of, selecting using the where clause is faster.

Even in situations where the client code will iterate through the whole database (file-based databases like Access, for example), you will have optimized code written in c or c++ doing the selection (in the database driver.) This is always faster than VB6.

For Database engines (SQL, MySQL, etc), the performance increase can even be more profound. By using the where clause, you limit the amount of data that must be transmitted over the network, vastly improving the response.

Some additional performance tips:

  • Select only the fields you want.
  • Build indexes on frequently used fields
  • Watch what kind of recordset you are returning. Use Forward-only cursors if you are just returning data from a database.

Lastly, I was shocked by VB.NET's database performance, it being several times faster than the fastest VB6 code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文