关于MYSQL 语句常用的优化

批量超做时,是分开操作,还是一次性插入呢??

mysql> set profiling=1;
Query OK, 0 rows affected (0.06 sec)

mysql> update b2b_sell set edittime= from_unixtime(now()),editdate= 'curdate()' where itemid in(8,9,10);update b2b_sell set edittime= from_unixtime(now()),editdate='curdate()' where itemid=148;update b2b_sell set edittime= from_unixtime(now()),editdate='curdate()' where itemid=149;update b2b_sell set edittime= from_unixtime(now()),editdate='curdate()' where itemid=147;show profiles;show processlist;
Query OK, 3 rows affected, 6 warnings (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 6

Query OK, 1 row affected, 2 warnings (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 2

Query OK, 1 row affected, 2 warnings (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 2

Query OK, 1 row affected, 2 warnings (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 2

+----------+------------+--------------------------------------------------------------------------------------------------+
| Query_ID | Duration   | Query                                                                                            |
+----------+------------+--------------------------------------------------------------------------------------------------+
|        1 | 0.00080800 | update b2b_sell set edittime= from_unixtime(now()),editdate= 'curdate()' where itemid in(8,9,10) |
|        2 | 0.00032200 | update b2b_sell set edittime= from_unixtime(now()),editdate='curdate()' where itemid=148         |
|        3 | 0.00031900 | update b2b_sell set edittime= from_unixtime(now()),editdate='curdate()' where itemid=149         |
|        4 | 0.00027900 | update b2b_sell set edittime= from_unixtime(now()),editdate='curdate()' where itemid=147         |
+----------+------------+--------------------------------------------------------------------------------------------------+

 如果从这看,貌似统一插入时占用的总时间稍少。各有个的好处....

          

相关推荐