MYSQL查询执行时间

发布于 2024-12-03 10:07:04 字数 1094 浏览 3 评论 0原文

我有一个问题要问你。我的数据库包含 250.000 条录音,其中有 2 个文本字段,每个字段最多包含 300 个单词。我想选择满足某些条件的所有数据并将其放入另一个表中。我想删除那些不满足我的条件的记录:

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 个录音,我能做什么?谢谢你!!!!

I have a question for you. I have this database with 250.000 recordings, with 2 text fields each containing up to 300 words. And I want do select all the data that meets some criteria and put it in another table. I thought to delete those recording that are not satisfying my condition with this 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%"

Each row is OK if it containt at least one time any of those words. The thing is that I already have 3 hours since it is being in execution, and nothing hapened. I've stopped the proccess and nothing happened. The final resuls should have somewhere around 14000 recordings, What can I do? Thank you!!!!

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

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

发布评论

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

评论(4

北音执念 2024-12-10 10:07:04

什么都没发生,因为你阻止了它。因此,commit; 尚未完成。

您应该拆分查询以缩短执行时间。

NOT LIKE %% 非常非常昂贵! (索引,如果有一些没用到……)

Nothing happened because you stopped it. So, the commit; has not been done.

You should split your query to have a shorter execution.

The NOT LIKE %% are very very expensive!!! (the index, if there are some are not used...)

始终不够 2024-12-10 10:07:04

尝试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'

try REGEXP, might perform better here.

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'

also try it with concatenation (Karolis' suggestion)

DELETE FROM `cables` WHERE
   CONCAT( `data`, `tags`, `header`, `subject`, `tmp`, `identifier` )
   NOT REGEXP 'BRV|Venezuela|Caracas|Hugo Chavez'
江湖正好 2024-12-10 10:07:04

问题是 LIKE %text% 将不会使用全文索引。因此,一个包含 250.000 个条目和大量 LIKE %% 标准的大表将花费非常长的时间。

您确定需要前导“%...”吗?否则,您可以尝试使用布尔搜索修饰符

The problem is that LIKE %text% will not make use of a fulltext index. So a big table with 250.000 entries and a lot of LIKE %% criterias will take an awful long time.

Are you sure you need the leading '%...'? Otherwise you can try to use Boolean search modifier.

仙气飘飘 2024-12-10 10:07:04

为什么不反转条件以选择匹配的记录,而不是删除不匹配的记录?然后将它们插入到另一个表中?这可能会更快,因为即使过度使用不相似的条件,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%")

Why not reverse your condition to select the records that match instead of deleting the ones that don't? And then insert those into the other table? This might very well be faster, as 3 hours, even for the overuse of not-like conditions, is way too long for 250'000 rows.

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