9万条数据,用select*全部查询mysql数据库,数度超级慢,求解。
public List<Page> findAllPages() {
String hql = "from Page page order by page.id asc";
return (List<Page>) this.getHibernateTemplate().find(hql);
}
起初是调用这个方法,由于数据量太大,总是抛出内存不足的异常,后来改用分页处理的方法,但是越运行到后面,速度就越慢,差不多要10s才运行一条语句
public List<Page> findPagesLimit(int x, int y) {
if (y == 0) {
return null;
}
Session session = this.getSession();
try {
String hql = "from Page page order by page.id asc";
Query q = session.createQuery(hql);
q.setFirstResult(x);
q.setMaxResults(y);
List l = q.list();
if (l.size() == 0) {
return null;
}
return (List<Page>) l;
} catch (RuntimeException re) {
throw re;
} finally {
session.close();
}
请大家指点下,怎么才能使得查询数度变快呢?