[英]Slow query takes up entire HDD space resulting in a “1030 Got error 28 from storage engine”
Fairly new to MySQL. 相当新的MySQL。
Slow query takes up the entire HDD space ending up with 1030 error code. 慢查询占用整个硬盘空间,最终得到1030错误代码。
INSERT INTO schema.Table C
SELECT a.`Date`, a.Store, a.SKU,
floor((a.QTY / ((b.CASEQTY * b.CASEPERLAYER) * b.LAYERPERPALLET))) AS Pallets,
floor(((a.QTY / ((b.CASEPERLAYER * b.LAYERPERPALLET) * b.CASEQTY)) /.CASEQTY)) AS Cases,
(a.QTY * b.CASEQTY) AS Pieces
FROM
(schema.table1 AS a
INNER JOIN schema.table2 AS b)
WHERE a.Description = 'BLAH';
Problem: 问题:
When I run the above query I get the results I need in 0.01 sec with a limit of 100 rows. 当我运行上面的查询时,我得到了我需要的结果,在0.01秒内限制为100行。 However, When I try to insert the query into a prepared table it fails.
但是,当我尝试将查询插入准备好的表时,它会失败。
The above query will basically run for hours until the HDD is full. 上述查询基本上会运行几个小时,直到硬盘满了。 Table A contains millions of records and table B only a few thousand.
表A包含数百万条记录,表B仅包含数千条记录。 Storage engine is InnoDB.
存储引擎是InnoDB。 I've run a similar query for 3hrs and have had it succeed.
我已经运行了3小时的类似查询并且已经成功了。 Any help will be greatly appreciated.
任何帮助将不胜感激。
That's something special in MySQL. 这在MySQL中很特别。 In spite of calling it INNER JOIN , you can do a CROSS JOIN by leaving out the ON clause which is exactly what you are doing.
尽管将其称为INNER JOIN ,但您可以通过省略ON子句来执行CROSS JOIN ,这正是您正在执行的操作。 (Another dbms would raise a syntax error.)
(另一个dbms会引发语法错误。)
So by not specifying the ON clause to match records from table1 and table2 you match every record in table1 with every record in table2. 因此,通过不指定ON子句,匹配从表1的记录和表2你在表2 中的每个记录在表1 中的每个记录相匹配。 These can be many :-)
这可能很多:-)
Your inner join statement contains no join criteria. 您的内部联接语句不包含联接条件。 This will result in something (bad) called a "cartesian product".
这将导致一些(坏的)称为“笛卡尔积”。 So, if table A has a million records and table b contains a thousand, then a cartesian product will match each row in table A to EVERY row in the other table.
因此,如果表A有一百万条记录而表b包含一千条,那么笛卡尔积将匹配表A中的每一行到另一个表中的每一行。 This should give you (at least) a billion records.
这应该给你(至少)十亿条记录。
To fix this, you need to define/constrain the relationship between the two tables by using an "ON" clause for your join or it could go in the WHERE clause. 要解决此问题,您需要通过对连接使用“ON”子句来定义/约束两个表之间的关系,或者它可以放在WHERE子句中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.