开发者

Why does this query make my whole database freeze?

SELECT * FROM `groupon-spain-6sep-2011`, `Hoja1`,`GroupaliaJuly2011` 
WHERE `groupon-spain-6sep-2011`.`code`= 5654 
    OR  `Hoja1`.`code` = "5654 
    OR `GroupaliaJuly2011开发者_开发百科`.`code` = 5654


You are missing any join condition relating the tables to each other so are doing a cartesian join of 3 tables.

I recommend always using explicit join syntax

SELECT *
FROM   `groupon-spain-6sep-2011`
       JOIN `hoja1` ON `groupon-spain-6sep-2011`.foo=`hoja1`.foo
       JOIN `groupaliajuly2011` ON `groupaliajuly2011`.`foo` = `hoja1`.foo
WHERE  `groupon-spain-6sep-2011`.`code` = 5654
        OR `hoja1`.`code` = 5654
        OR `groupaliajuly2011`.`code` = 5654  

Although it is possible that you might be wanting a Union here I think anyway?


You might want to do a union instead:

SELECT * 
    FROM groupon-spain-6sep-2011
    WHERE code = 5654
UNION SELECT * 
    FROM Hoja1
    WHERE code = 5654
UNION SELECT * 
    FROM GroupaliaJuly2011
    WHERE code = 5654


The query you posed involves the Cartesian product(also known as CROSS JOIN in standard SQL, thanks for the advice @onedaywhen) of three tables, the amount of record involves will be size(A) * size(B) * size(C). So if the total product is large enough, it will fill a significant amount of memory, which will make your database unable to response to any other request, and that will lead to the 'freeze' of your database.

I noticed that you want either of the three specified columns to be the same value '5654', so you can selet tuples from three table respectively, and then UNION them, instead of doing Cartesian product of them like you're doing it now, since I don't think the Cartesian product you're making makes any sense. That will save a GREAT number of memory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜