即时搜索需要大量计算能力吗?

发布于 2024-09-19 12:29:05 字数 89 浏览 6 评论 0 原文

我想知道使用 jQuery 的即时搜索是否会对数据库(MySQL)造成巨大的负载。我知道有很多因素需要考虑,但为了论证起见,假设您有 30,000 条记录需要浏览?

I was wondering whether the instant search using jQuery would cause a massive load on a database (MySQL). I know there are a lot of factors to consider, but for argument's sake let's say you have 30,000 records to flick through?

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

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

发布评论

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

评论(4

不乱于心 2024-09-26 12:29:05

索引

索引有帮助,但索引也会减慢 INSERT/UPDATE/DELETE 语句的速度...

MySQL 还限制了可用于索引表中列的空间量,这取决于引擎类型:

  • MyISAM:1000 字节
  • InnoDB: 767 字节

数据类型

为作业选择正确的数据类型。
不久前,我注意到 SO 上的一个问题将 TEXT 列为数据类型,但仅使用 ~100 个字符。 他们报告说他们看到了查询时间当他们将数据类型更改为 VARCHAR 时,减少到原始数据的三分之一 十分

最佳查询

请注意,对左侧进行通配符LIKE 表达式的一侧使列上的索引变得无用。如果您需要此类搜索,请考虑使用 MySQL 的本机 MATCH .. AGAINST 语法 或第三方支持,如 Sphinx。如果没有看到查询,就很难提供更多见解。

Indexing

Indexing helps, but indexing also slows down INSERT/UPDATE/DELETE statements...

MySQL also limits the amount of space you can use to index columns in a table, and it depends on the engine type:

  • MyISAM: 1000 bytes
  • InnoDB: 767 bytes

Data types

Choose the right data type for the job.
Not long ago, I noticed that a question on SO was listing TEXT as the data type but only using ~100 characters. They reported back to say they saw the query time decrease to a third tenth of the original when they changed the data type to VARCHAR.

Optimal Query

Be aware that wildcarding the left side of a LIKE expression renders an index on the column useless. If you need that sort of search, look at leveraging Full Text Search (FTS) using either MySQL's native MATCH .. AGAINST syntax or 3rd party support like Sphinx. It's hard to offer more insight without seeing a query.

护你周全 2024-09-26 12:29:05

Searching through 30,000 records, in any SQL database, should be very fast if the tables are properly indexed. You need to make sure that you have usable index(es) for your queries. You may also want to consider using Full-Text Indexing.

女皇必胜 2024-09-26 12:29:05

这要看情况。您的即时搜索实现比普通搜索模型多生成多少查询?

我见过的大多数执行此操作的 Javascript 库实际上不会尝试运行查询,除非光标已处于非活动状态一段时间。这些导致的查询数量仅为普通搜索的 3 - 4 倍。如果您确实对输入的每个字符都运行搜索,那么您将必须处理与输入的字符一样多的搜索。

总而言之,这完全取决于查询涉及多少工作。

That depends. How many more queries does your instant search implementation generate than a plain search model?

Most Javascript libraries I've seen that do this don't actually try to run the query unless the cursor has been inactive for some time. These result in only 3 - 4 times as many queries as plain search. If you truly run the search on every character entered, then you're going to have to deal with as many searches as characters are input.

That all said, it depends entirely on how much work is involved in a query.

写给空气的情书 2024-09-26 12:29:05

这取决于您如何创建数据库。索引很重要,您选择的列也很重要。您应该考虑的最后一件事是搜索算法。如果您只是在 let's 关键字上使用 where 或 like 子句,我认为这会很好,但如果您需要大量内容,那么您可能应该考虑 MySQL 的全文搜索功能。

It depends on how you created your database. Indexes would matter and the columns you selected will do also. The last thing you should consider is the searching algorithm. If you're just using where or like clause on let's keywords I think it's gonna be fine, but if you're after a big content then probably you should consider Full-Text Search feature of MySQL.

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