我有一个问题要问你。我有这个250.000记录的数据库,有2个文本字段,每个字段最多包含300个单词。我想要选择符合某些条件的所有数据并将其放在另一个表中。我想用这个wuery删除那些不满足我条件的录音:
DELETE FROM `cables` WHERE
`data` NOT LIKE "%BRV%" AND
`data` NOT LIKE "%Venezuela%" AND
`data` NOT LIKE "%Caracas%" AND
`data` NOT LIKE "%Hugo Chavez%" AND
`tags` NOT LIKE "%BRV%" AND
`tags` NOT LIKE "%Venezuela%" AND
`tags` NOT LIKE "%Caracas%" AND
`tags` NOT LIKE "%Hugo Chavez%" AND
`header` NOT LIKE "%BRV%" AND
`header` NOT LIKE "%Venezuela%" AND
`header` NOT LIKE "%Caracas%" AND
`header` NOT LIKE "%Hugo Chavez%" AND
`subject` NOT LIKE "%BRV%" AND
`subject` NOT LIKE "%Venezuela%" AND
`subject` NOT LIKE "%Caracas%" AND
`subject` NOT LIKE "%Hugo Chavez%" AND
`tmp` NOT LIKE "%BRV%" AND
`tmp` NOT LIKE "%Venezuela%" AND
`tmp` NOT LIKE "%Caracas%" AND
`tmp` NOT LIKE "%Hugo Chavez%" AND
`identifier` NOT LIKE "%BRV%" AND
`identifier` NOT LIKE "%Venezuela%" AND
`identifier` NOT LIKE "%Caracas%" AND
`identifier` NOT LIKE "%Hugo Chavez%"
如果每行包含至少一次这些单词,则每行都可以。事情是,自从它执行以来我已经有3个小时了,没有任何事情发生。我已经停止了进程,没有任何事情发生。最终的结果应该有大约14000个录音,我该怎么办?谢谢!!!!
答案 0 :(得分:2)
没有发生任何事,因为你停了下来。因此,commit;
尚未完成。
您应该将查询拆分为更短的执行时间。
NOT LIKE %%
非常贵! (索引,如果有一些没有使用...)
答案 1 :(得分:2)
尝试REGEXP
,可能会在这里表现得更好。
DELETE FROM `cables` WHERE
`data` NOT REGEXP 'BRV|Venezuela|Caracas|Hugo Chavez' AND
`tags` NOT REGEXP 'BRV|Venezuela|Caracas|Hugo Chavez' AND
`header` NOT REGEXP 'BRV|Venezuela|Caracas|Hugo Chavez' AND
`subject` NOT REGEXP 'BRV|Venezuela|Caracas|Hugo Chavez' AND
`tmp` NOT REGEXP 'BRV|Venezuela|Caracas|Hugo Chavez' AND
`identifier` NOT REGEXP 'BRV|Venezuela|Caracas|Hugo Chavez'
也可以连接(Karolis'建议)
DELETE FROM `cables` WHERE
CONCAT( `data`, `tags`, `header`, `subject`, `tmp`, `identifier` )
NOT REGEXP 'BRV|Venezuela|Caracas|Hugo Chavez'
答案 2 :(得分:1)
问题是LIKE %text%
不会使用全文索引。因此,包含250,000个条目和大量LIKE %%
条件的大表将花费很长时间。
您确定需要领先的'%...'吗?否则,您可以尝试使用Boolean search modifier。
答案 3 :(得分:0)
为什么不改变条件来选择匹配的记录而不是删除那些不匹配的记录?然后将它们插入另一个表中?这可能会更快,因为即使对于过度使用不喜欢的条件,3小时对于250'000行来说太长了。
INSER INTO `selected_cables`
SELECT * FROM `cables`
WHERE NOT (
`data` NOT LIKE "%BRV%" AND
`data` NOT LIKE "%Venezuela%" AND
`data` NOT LIKE "%Caracas%" AND
`data` NOT LIKE "%Hugo Chavez%" AND
`tags` NOT LIKE "%BRV%" AND
`tags` NOT LIKE "%Venezuela%" AND
`tags` NOT LIKE "%Caracas%" AND
`tags` NOT LIKE "%Hugo Chavez%" AND
`header` NOT LIKE "%BRV%" AND
`header` NOT LIKE "%Venezuela%" AND
`header` NOT LIKE "%Caracas%" AND
`header` NOT LIKE "%Hugo Chavez%" AND
`subject` NOT LIKE "%BRV%" AND
`subject` NOT LIKE "%Venezuela%" AND
`subject` NOT LIKE "%Caracas%" AND
`subject` NOT LIKE "%Hugo Chavez%" AND
`tmp` NOT LIKE "%BRV%" AND
`tmp` NOT LIKE "%Venezuela%" AND
`tmp` NOT LIKE "%Caracas%" AND
`tmp` NOT LIKE "%Hugo Chavez%" AND
`identifier` NOT LIKE "%BRV%" AND
`identifier` NOT LIKE "%Venezuela%" AND
`identifier` NOT LIKE "%Caracas%" AND
`identifier` NOT LIKE "%Hugo Chavez%")