gpt4 book ai didi

mysql - 过程的 CALL 不断加载,占用高 CPU,并失败

转载 作者:行者123 更新时间:2023-11-30 21:42:52 24 4
gpt4 key购买 nike

我正在尝试创建一个过程,该过程将采用由数千条记录组成的 View 表,并根据各种条件通过删除几条记录来过滤它。

当我尝试使用 CALL 来运行它时,它一直在加载,根据 WHM 面板,进程 (phpMyAdmin/import.php) 占用了大约 90% 的 CPU 功率。最终由于超时,它可能在 10 分钟后失败:

Static analysis:

1 errors were found during analysis.

Missing expression. (near "ON" at position 25) SQL query: Edit Edit

SET FOREIGN_KEY_CHECKS = ON;

MySQL said: Documentation

2006 - MySQL server has gone away

我正在使用以下代码,新 View 表使用了 3 个数据库表:

vw_r2_items_tr,正在使用 tr 数据库核心表和 vw_items - 使用 items 的 View 表> 和访问核心表

DELIMITER $$

CREATE VIEW `vw_r2_items_tr` AS
SELECT
IF((`i`.`id` = `t`.`item_ord`),1,0) AS `has_tr`,
`i`.`calculated_score` AS `calculated_score`,
`i`.`visited_at` AS `visited_at`,
`i`.`ip_address` AS `ip_address`,
`i`.`user_id` AS `user_id`,
`i`.`visit_id` AS `visit_id`,
`i`.`product_id` AS `product_id`,
`i`.`name` AS `name`,
`i`.`id` AS `id`,
`i`.`item_no` AS `item_no`,
FROM (`vw_items` `i`
LEFT JOIN `trs` `t`
ON (((`t`.`visit_id` = `i`.`visit_id`)
AND (`t`.`item_ord` = `i`.`id`))))$$

DELIMITER ;


DELIMITER $$

CREATE PROCEDURE `vw_unique_trs2`()
BEGIN
SET @vat=0;
SET @ht=0;
SET @tdiff=0;
-- EXPLAIN
SELECT
COUNT(*) AS ct,
tb1.* FROM (SELECT it.*, @tdiff:=UNIX_TIMESTAMP(CONVERT_TZ(it.visited_at,'+00:00',@@global.time_zone)) AS tdiffs,
IF(@vat > 0 AND ((@vat-@tdiff) < 28800 AND (@vat-@tdiff) > -28800),@vat DIV 28800, @tdiff DIV 28800) AS diff,
@ht:=(IF(@vat > 0 AND ((@vat-@tdiff) < 28800 AND (@vat-@tdiff) > -28800),@ht+has_tr,has_tr)) hts,
@vat:=(IF(@vat > 0 AND ((@vat-@tdiff) < 28800 AND (@vat-@tdiff) > -28800),@vat,@tdiff)) curr_vat
FROM (SELECT * FROM (SELECT * FROM `vw_r2_items_tr` ORDER BY has_tr DESC, item_no, visited_at) AS tb
GROUP BY `tb`.`visit_id`,`tb`.`product_id`) AS it
ORDER BY has_tr DESC, it.visited_at DESC
) AS tb1
GROUP BY user_id, calculated_score, diff, hts;
END$$

DELIMITER ;

最佳答案

我认为你不能只使用一个“ON”和两个连接,尝试像那样做 2 个连接查询

    `SELECT *
FROM Table1
LEFT JOIN Table2 ON Table1.key = Table2.key` and
LEFT JOIN Table3 ON Table1.key = Table2.key`

关于mysql - 过程的 CALL 不断加载,占用高 CPU,并失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50797586/

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