关于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 | +----------+------------+--------------------------------------------------------------------------------------------------+
如果从这看,貌似统一插入时占用的总时间稍少。各有个的好处....
相关推荐
要啥自行车一把梭 2020-11-12
vitasfly 2020-11-12
minerk 2020-11-12
xkorey 2020-09-14
sofia 2020-08-15
liang枫 2020-08-07
herohope 2020-07-18
mrandy 2020-07-04
Jaystrong 2020-06-27
wangwtotao 2020-06-27
msmysql 2020-06-26
李高峰 2020-06-22
InJavaWeTrust 2020-06-21
debugjoker 2020-06-17
sunnyxuebuhui 2020-06-16
勇往直前 2020-06-14
wensonlee 2020-06-12
vivenwan 2020-06-06