我有一个流量非常高的网站,每小时可能会插入 1000 条新记录。
这一错误使网站瘫痪:
PDOException: SQLSTATE[40001]: Serialization failure: 1213
Deadlock found when trying to get lock;
try restarting transaction: INSERT INTO {location_instance}
(nid, vid, uid, genid, lid) VALUES (:db_insert_placeholder_0,
:db_insert_placeholder_1, :db_insert_placeholder_2,
:db_insert_placeholder_3, :db_insert_placeholder_4);
Array ( [:db_insert_placeholder_0] => 1059 [:db_insert_placeholder_1] =>
1059 [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] =>
cck:field_item_location:1059 [:db_insert_placeholder_4] => 1000 )
Run Code Online (Sandbox Code Playgroud)
如果 MySQL 无法处理这种类型的负载,我会感到非常惊讶。那么,我的问题是,这是一个数据库问题,我该如何配置 MySQL 才能处理这么多流量?
我在开发服务器上设置了我的网站副本,其中包含模拟添加到网站的内容负载的脚本。我正在运行带有 16GB RAM 的 Ubuntu、LAMP 堆栈。
诚然,我对数据库不是很了解。事实上,我从“apt-get install”完成后随附的默认 my.cnf 开始。表都是Innodb。你会推荐什么起始配置设置和方法来开始解决这个问题?
让我知道您可能需要更多信息。
谢谢
我有一个 MySQL 数据库表,它引用了不同的单词及其在文档中的位置。我想返回包含所有单词的文档的 ID。
这是一个示例表。
docid wordid
1 4
2 4
1 2
1 5
Run Code Online (Sandbox Code Playgroud)
好的,现在假设有人在数据库中查询了 WORDID 为 4、2 和 5 的单词。
我错误的 SQL SELECT 语句类似于:
Select docid from table where wordid = 4 and wordid = 2 and wordid = 5
Run Code Online (Sandbox Code Playgroud)
这给了我 0 结果。
我在其他地方看到where in有人建议使用该条款:
如果我理解正确,这是编写 OR 子句的另一种方式。我试过这个:
select docid from table where wordid in (4,2,5)
Run Code Online (Sandbox Code Playgroud)
但是,这给了我所有的结果。它应该排除 docid 2,因为它不包含其他词。我期待获得 docid 1。
但是,我可能会where in错误地使用该子句,因为我的数据库经验很少。
如何返回包含所有单词的 docid?
另请注意,我的 where 子句将在 FOR 循环中动态生成。查询可以是一两个词那么简单,也可以是 10 或 12 …