select count(*) vs list.size()解决办法

select count(*) vs list.size()解决办法

select count(*) vs list.size()

大家好,使用hibernate链接MySQL查询,如果从一个库中查询数量,那么下面这两种方式那个效率好一些?

1,select count(*) from itemresult where itemid=2;

取得count(*)

2,from ItemResult where itemId=?

取得List<ItemResult>.size()



个人认为直接写sql语句效率会好一些,直接与数据库打交道了啊!

但是 hql 移植比较好一些吧。





1,select count(*) from itemresult where itemid=2;

这个会比较好。至少数据库的输出部分只有一行,另外可以直接使用索引不必访问数据文件。




select count(*) from itemresult where itemid=2;

这个直接从数据库中获得结果,而第二个方法是查询数据库后再计算结果




探讨

1,select count(*) from itemresult where itemid=2;

这个会比较好。至少数据库的输出部分只有一行,另外可以直接使用索引不必访问数据文件。



当然count(*)。

select count(*) vs list.size()解决办法

相关文章:

你感兴趣的文章:

标签云: