鍍金池/ 問答/Java/ Java /mybatis/hibernate 將多條 mysql 語句放在一個(gè)

Java /mybatis/hibernate 將多條 mysql 語句放在一個(gè) Dao 函數(shù)里會(huì)提升性能嗎?

譬如 java 里的一個(gè) service,里面有事務(wù)

@Service
class ShopService{

@Transactional
public void doTransaction(int type){      
     List<Customer> customerList = customerDao.getByType(type);
     couponDao.assign(customerList);    
}

}

我的理解是:

1 java 程序?qū)?customerDao.getByType(type);對應(yīng)的 mysql 語句通過數(shù)據(jù)庫連接發(fā)給數(shù)據(jù)庫

2 數(shù)據(jù)庫產(chǎn)生結(jié)果,將 customerList 發(fā)給 java 程序

3 java 程序?qū)?couponDao.assign(customerList);對應(yīng)的 mysql 語句通過數(shù)據(jù)庫連接發(fā)給數(shù)據(jù)庫

4 數(shù)據(jù)庫產(chǎn)生結(jié)果,將結(jié)果發(fā)給 java 程序

這樣,如果中間結(jié)果 customerList 很大的話,網(wǎng)絡(luò)傳輸性能損耗比較大

假如如下做法:

@Service
class ShopService{

@Transactional
public void doTransaction(int type){      
     couponDao.assignCustomersByType(type);    
}

}

couponDao.assignCustomersByType(type); 對應(yīng)兩條 mysql 語句,一次性發(fā)給數(shù)據(jù)庫去執(zhí)行,讓中間結(jié)果在數(shù)據(jù)庫里,這樣性能會(huì)有顯著提升嗎?

回答
編輯回答
青檸

你都不發(fā)sql 說屁

2018年8月22日 00:58
編輯回答
臭榴蓮

很多優(yōu)化都是沒有必要的, 啟用數(shù)據(jù)庫端的慢sql日志,僅需優(yōu)化真正慢的,其他的不要猜,拿數(shù)據(jù)說話

2017年2月21日 08:40