2

我有一个超过十万行的表。当我在下面使用时:

Yii::app()->db->createCommand('SELECT * FROM thistable')->query();

查询失败,但是测试了很多小表,没问题。我想备份我当前的数据库,我点击了这个链接:

http://www.yiiframework.com/forum/index.php/topic/29291-full-database-backup/

任何想法?提前致谢!

4

1 回答 1

1

You need to avoid such queries in big tables. It can cause mysql crash or server dump. And thats not yii problem. Advices:

1.Use indexes (but carefully sometimes they slowing down queries - COUNT for example).

2.Always make limits in your queries : SELECT * FROM thistable LIMIT 50.

3.If you using InnoDB for total count use EXPLAIN SELECT COUNT(*) FROM thistable. In myISAM COUNT() works fast.

4.Avoid all joins. Even join on small table(<100 records) can cause 30-100% slow on queries.

I assume that 2nd point is your problem. For example:

SELECT * FROM thistable LIMIT 30 => result (32,415,735 all, Query took 0.0184 sec.)`

SELECT COUNT(*) FROM thistable'=> result (31,912,535 all, Query took 215.14 sec.)

于 2013-06-04T07:30:18.550 回答