如何找出在执行 Hibernate 查询时哪个连接(Join)占用了大部分时间?

huangapple 未分类评论43阅读模式
英文:

How do i find which Join is taking most of the time while executing a Hibernate query?

问题

以下是您要翻译的内容:

我在面试中被问到了这个问题。假设您已经编写了一个包含3-4个连接的Hibernate查询(本机查询或HQL查询)。现在查询运行得很慢。因此,如果我要进行调试,我该如何找出哪个连接花费了最多的时间?

我已经与我的同事、团队成员交谈过,向许多资深开发人员提问过,并在互联网上进行了搜索,但没有得到令人满意的答案。

我想出了以下两种方法:

1:您在查询开头和结尾处编写带有当前时间戳的日志信息,以便您可以在日志中检查查询所花费的时间。

2:或者您可以将log4j记录器与Hibernate集成,以便Hibernate以详细的格式打印日志。

这样能解决问题吗?我一点儿头绪都没有。请帮忙解答。

英文:

I was asked this question in an interview. Suppose you have written a hibernate query (native or HQL) and this query contains 3-4 Joins. Now the query is running slow . So if i debug how do i find out which join is taking the most time?

I have talked with my collegues , my teamMates , asked many senior developers and searched internet too but didn't got any satisfied answers.

I have come up with these two approaches:

1: You write a logging info with current timestamp at the start and end of the query so that you can check in the logs the time taken by the query.

2: Or you can integrate log4j logger with hibernate so that hibernate prints the logs in detailed format.

Is this even close to solve this? i have no clue.
Please assist

答案1

得分: 0

不是。您需要记录查询的详细信息,然后将查询传递给数据库执行分析器。查看查询计划会提供一些提示。

英文:

Neither. You have to log in details the query, and then pass the query to your DB execution analyzer. Having a look at the query plan will give a hint on that.

huangapple
  • 本文由 发表于 2020年4月4日 22:37:12
  • 转载请务必保留本文链接:https://java.coder-hub.com/61029703.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定