搜索数据库的最快方法 [英] Fastest possible way to search a database

查看:73
本文介绍了搜索数据库的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我正在VB.NET中制作一个应用程序,我需要解决一个问题.
我正在使用accdb数据库,但如有必要,我可以使用任何其他类型,只要它能完成工作就没有关系.

我需要在数据库中搜索特定条目,如果没有,则返回.
现在有一个问题,就是数据库非常大,我在说的是100.000.000(亿)甚至是200.000.000(两亿)个条目,所以如果我使用...
,那么......................................................................................................

SELECT Count(*) FROM Table1 WHERE Column1=Entry1



...可能需要一段时间才能完成我的应用程序的搜索,例如100个条目.

有谁知道最快的方法是什么.谢谢

解决方案

在Column1上添加索引.索引基本上提供了一种快速查找行的方法.而不是扫描整个表,可以查找索引,您可以在O(1)或O(log(N))时间中找到该行.


这样做可能会更快将条目存储在临时表中,并加入Column1,对它们进行分组并计算每个组.应该像下面的sql一样(但是未经测试)

SELECT Count(*) FROM Table
  INNER JOIN Temp
  ON Table.Column1=Temp.Column1
  GroupBy Table.Column1



祝你好运!


索引

为了更快地进行搜索,您需要在表上放置几个索引.首先,请阅读 [ 解决方案

Add an index on Column1. Indexes basically provide a very fast way to look up rows. Rather than scan the entire table, the index can be looked up and you can find the row in O(1) or O(log(N)) time.


It might be faster to store the entries in a temp table and join on Column1, group them and count each group. Should be something like the sql below (untested however)

SELECT Count(*) FROM Table
  INNER JOIN Temp
  ON Table.Column1=Temp.Column1
  GroupBy Table.Column1



Good luck!


Indexing!

In order to have faster search you need to put few indexes on your table. For start read
this[^].
If needed, Google for more.


这篇关于搜索数据库的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆