V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
esolve
V2EX  ›  问与答

Java /mybatis/hibernate 将多条 mysql 语句放在一个 Dao 函数里会提升性能吗?

  •  
  •   esolve · 2017-12-21 14:42:08 +08:00 · 869 次点击
    这是一个创建于 2342 天前的主题,其中的信息可能已经有所发展或是发生改变。

    譬如 java 里的一个 service,里面有事务

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

    我的理解是:

    1 java 程序将 customerDao.getByType(type);对应的 mysql 语句通过数据库连接发给数据库

    2 数据库产生结果,将 customerList 发给 java 程序

    3 java 程序将 couponDao.assign(customerList);对应的 mysql 语句通过数据库连接发给数据库

    4 数据库产生结果,将结果发给 java 程序

    这样,如果中间结果 customerList 很大的话,网络传输性能损耗比较大

    假如如下做法:

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

    couponDao.assignCustomersByType(type); 对应两条 mysql 语句,一次性发给数据库去执行,让中间结果在数据库里,这样性能会有显著提升吗?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5494 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 02:15 · PVG 10:15 · LAX 19:15 · JFK 22:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.