gpt4 book ai didi

php - jQuery UI 自动完成 : search 2 huge MySQL tables not linked

转载 作者:行者123 更新时间:2023-11-29 09:46:30 25 4
gpt4 key购买 nike

我的网站引用了 20,000 名不同作者的 100,000 多篇文章。我想要在两个表中进行 jQuery UI 自动完成搜索,要么是文章标题,要么是作者姓名。

这两个表基本上是:

Table articles

  • title (ex: This is the title)
  • slug (ex: this-is-the-title)

Table author

  • name (ex: John Doe)
  • slug (ex: john-doe)

应该检索 slug 信息,因为搜索栏将根据搜索结果重定向到 article.phpauthor.php

我担心的是,像这样解析这两个表需要很长时间,超过 30 秒:

SELECT title, ar.slug, name, au.slug
FROM articles ar,author au
WHERE published = 1
AND (title LIKE :term OR name LIKE :term)

该列已编入索引。

有更好的方法吗?感谢您的帮助。

最佳答案

您的查询如此缓慢的原因是您的 JOIN 没有条件因此,您将获得 100,000*20,000 的潜在结果集,即必须通过 WHERE 过滤的 2B 行条款。由于此查询不需要表之间有任何类型的关系,因此最好仅使用 UNION ,添加一个字段来区分 authortitle :

SELECT 'author' AS type, name AS value, slug
FROM author
WHERE published = 1 AND name LIKE :term
UNION
SELECT 'title' AS type, title, slug
FROM articles
WHERE published = 1 AND title LIKE :term

关于php - jQuery UI 自动完成 : search 2 huge MySQL tables not linked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55568078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com