gpt4 book ai didi

database - 创建太多数据库索引的权衡是什么?

转载 作者:搜寻专家 更新时间:2023-10-30 21:57:55 26 4
gpt4 key购买 nike

我有一个永远运行的 Python 爬虫。

这是手头的问题:

# Time: 151201 19:36:18
# User@Host: root[root] @ localhost []
# Query_time: 25.516377 Lock_time: 0.000059 Rows_sent: 1 Rows_examined: 55589711
SET timestamp=1449016578;
SELECT SQL_CALC_FOUND_ROWS * FROM `links` WHERE `URL` LIKE '%http://www.smallbizpages.ca/%' LIMIT 1;
# Time: 151201 19:37:01
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 32.796236 Lock_time: 0.000074 Rows_sent: 50 Rows_examined: 13245375
SET timestamp=1449016621;
SELECT * FROM links WHERE URL LIKE '%smallbizpages.ca%' ORDER BY dateChecked ASC LIMIT 50;

25-32 秒的查询时间确实会减慢其他脚本和线程的速度。

我的模式:

enter image description here

我的索引:

enter image description here

我已将所有内容设置为索引,但它仍然运行得很慢。索引太多了吗?还不够吗?

该程序基本上执行选择,然后插入并重复。

最佳答案

插入行时,必须将值添加到索引中。

当您删除一行时,该值必须从索引中删除。

当您更新索引列中的值时,该值必须在索引中更新。

也去掉 LIKE 子句中的前导“%”。

最好的办法是获取您的执行计划并查看它为何缓慢(您可以针对您的执行计划发布另一个问题。可能在 dba 堆栈交换上获得更好的结果)。

关于database - 创建太多数据库索引的权衡是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34032982/

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