我正在尝试创建一个过程,该过程将获取一个由数千条记录组成的视图表,并根据各种条件删除多条记录来对其进行过滤。
当我尝试使用调用来运行它时,它会继续加载,根据whm panel,这个进程(phpmyadmin/import.php)占用了大约90%的cpu资源。最终,可能在10分钟后由于超时而失败:
静态分析:
分析中发现1处错误。
缺少表达式(位置25处“开”附近)sql查询:编辑
设置外键\u checks=on;
mysql说:文档
2006年的今天,mysql服务器消失了
我使用以下代码,新的视图表使用3个db表: vw_r2_items_tr
,正在使用 tr
db核心表和 vw_items
-使用 items
以及 visits
核心表
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 ;
1条答案
按热度按时间9bfwbjaz1#
我想你不能只用一个“开”和两个连接,试着这样做两个连接查询