테이블이 articles
이고 행 수가 500k입니다. 기사에는 저자 목록이 있습니다. 저자 목록에 대한 최신 게시 된 기사를 얻기 위해 쿼리를 작성하려고합니다.HQL을 사용하는 from 절의 하위 쿼리
select * from (
select articles.id, author.id
from articles, article_authors, authors
where articles.id = article_authors.article_id and
article_authors.author_id=authors.id
and author.id in (author_list)
order by articles.publishedAt desc
) b
group by authors.id;
만에서 :
나는 일반 SQL에서 가능한 더 나은 쿼리가 될 것 내가 원하는 걸 얻을 수 있지만 매우 느린 실행하는 다음 HQL 쿼리 (~ 4S) select author, article
from Article article inner join article.authors author
where (author.id, article.publishedAt) in
(select author.id, max(article.publishedAt)
from Article article join article.authors author
where author.id in (authors_list))
group by author.id
을 사용 Hibernate 문서는 HQL 부질의가 select 나 where 절에서만 발생할 수 있다고 명시되어있다. http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html#queryhql-subqueries
HQL 또는 다른 방법을 사용하여 이러한 종류의 쿼리를 에뮬레이션하는 방법이 있습니까?
저는 몇 달 전에 비슷한 질문에 답했습니다. 너를 도와 줘야 해. http://stackoverflow.com/questions/32486923/how-to-increase-performance-in-sql-query/32487550#32487550 – jswan