在Mysql 5.6上,如果我每分钟运行一次以下查询:
SELECT
Count(DISTINCT oxv_oxarticles_de.`oxid`)
FROM
oxobject2category
INNER JOIN
oxv_oxarticles_de ON oxobject2category.`oxobjectid` = oxv_oxarticles_de.`oxid`
AND oxv_oxarticles_de.`oxparentid` = ''
WHERE
oxobject2category.`oxcatnid` = 'XXXXXXXXXXXXXXXXX'
AND (oxv_oxarticles_de.oxactive = 1
AND (oxv_oxarticles_de.oxstockflag != 2
OR (oxv_oxarticles_de.oxstock
+ oxv_oxarticles_de.oxvarstock) > 0)
AND IF(oxv_oxarticles_de.oxvarcount = 0, 1, (SELECT 1
FROM
oxv_oxarticles_de AS art
WHERE
art.oxparentid = oxv_oxarticles_de.oxid
AND ( art.oxactive = 1 )
AND ( art.oxstockflag != 2
OR art.oxstock > 0 )
LIMIT 1)) )
该网站将每3天停止回复一次。
+----+--------------------+-------------------+--------+-------------------------------------------------+-----------+---------+----------------------------------------------+------+------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+-------------------+--------+-------------------------------------------------+-----------+---------+----------------------------------------------+------+------------------------------------+
| 1 | PRIMARY | oxobject2category | ref | OXMAINIDX,OXOBJECTID | OXMAINIDX | 32 | const | 33 | Using where; Using index |
| 1 | PRIMARY | oxarticles | eq_ref | PRIMARY,OXCOUNT,OXSTOCKFLAG,OXACTIVE,parentsort | PRIMARY | 32 | oxid_erima_prod.oxobject2category.OXOBJECTID | 1 | Using where |
| 2 | DEPENDENT SUBQUERY | oxarticles | ref | OXCOUNT,OXSTOCK,OXSTOCKFLAG,OXACTIVE,parentsort | OXCOUNT | 32 | func | 5 | Using index condition; Using where |
+----+--------------------+-------------------+--------+-------------------------------------------------+-----------+---------+----------------------------------------------+------+------------------------------------+
3 rows in set (0.00 sec)
报告的错误是
mysql error: [5: Out of memory (Needed 1048544 bytes)] in EXECUTE (SELECT COUNT( DISTINCT...
这个问题并不是如何“稍微优化”一下这个问题 - 尽管我对这些提示表示感谢。我需要帮助才能找到可能会导致严重破坏的查询的臭部分。通常(约99.9%)的执行时间不到1毫秒,执行时间为2微秒。
提前致谢!
答案 0 :(得分:0)
SHOW VARIABLES LIKE '%size';
您可能会找到一个1048544或接近1048544的值。提高该值。
然后问为什么您需要计算不同氧化物的数量。
查询运行多长时间?如果要花费一分钟以上的时间,请不要每分钟运行一次。相反,让我们对其进行优化。为此,请为相关表格提供SHOW CREATE TABLE
。