在休眠状态下从表中批量获取
我有一个表,我正在从该表中获取大约 250,000 条记录,这需要大约 25 分钟,有没有办法减少获取时间。我正在使用如下代码:-
query.setParameterList("studentId", StudentIdList);
有没有办法优化它?
I have a table and from that I am fetching records somewhere around 250,000 records and this is taking some 25 mins, is there a way to decrease the fetch time. I am using some code like below :-
query.setParameterList("studentId", StudentIdList);
Is there a way to optimize it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果从 SQL 命令行花费的时间不到 10 分钟,而从 Hibernate 花费的时间超过 25 分钟,那么您可能需要查看 批处理。特别是,您可能会从无状态会话中受益(特别是如果您没有做太多工作)。如果您确实没有做太多工作,您也许可以使用 DML 语句(也在该 URL 中)。
If it takes less than 10 minutes from the SQL command line and more than 25 minutes from Hibernate then you may want to look into the information on batching. In particular you might benefit from a stateless session (especially if you're not doing much work). If you're really not doing much work you may be able to use a DML statement (also in that URL).
如果您想让速度更快,您可以批量导出并从文件加载。或者只是不使用数据库;)
您可以使用其他方法来存储数据,速度会更快。您可能会通过数据库获得这样的性能,但有时最简单的方法是最好的。
我使用 http://introcs.cs.princeton.edu/java 中的 Student /32class/Student.java.html
打印
If you want to make it faster you can do a bulk export and load from a file. Or just not use the data base ;)
You can go much faster with other approaches to storing data. You might get performance like this with a database, but sometimes the simplest approaches are best.
I used Student from http://introcs.cs.princeton.edu/java/32class/Student.java.html
prints