在我的应用程序中,我使用本机查询来获取数据:
SELECT
time_month,
CCC.closing_strike_value AS closing_strike_value,
CC.opening_strike_value AS opening_strike_value,
C.closing_time AS closing_time,
C.max_ask AS max_ask,
C.max_bid AS max_bid,
C.max_point_value AS max_point_value,
C.max_strike_value AS max_strike_value,
C.min_ask AS min_ask,
C.min_bid AS min_bid,
C.min_point_value AS min_point_value,
C.min_strike_value AS min_strike_value,
C.opening_time AS opening_time,
C.option_name AS option_name,
C.opening_time AS id
FROM
(SELECT
DATE(DATE_FORMAT(FROM_UNIXTIME(opening_time / 1000), '%Y-%m-01')) AS time_month,
MAX(closing_time) AS closing_time,
MAX(max_ask) AS max_ask,
MAX(max_bid) AS max_bid,
MAX(max_point_value) AS max_point_value,
MAX(max_strike_value) AS max_strike_value,
MIN(min_ask) AS min_ask,
MIN(min_bid) AS min_bid,
MIN(min_point_value) AS min_point_value,
MIN(min_strike_value) AS min_strike_value,
MIN(opening_time) AS opening_time,
option_name
FROM
candle_option
WHERE
option_name LIKE CONCAT('%', :optionName, '%')
AND opening_time BETWEEN :from AND :to
GROUP BY DATE(DATE_FORMAT(FROM_UNIXTIME(opening_time / 1000), '%Y-%m-01'))) C
JOIN
candle_option CC ON CC.opening_time = C.opening_time
AND CC.option_name = C.option_name
JOIN
candle_option CCC ON CCC.closing_time = C.closing_time
AND CCC.option_name = C.option_name
ORDER BY C.opening_time
第一个select语句中列出的每一列都对应于我检索的实体中的一个字段。
此本机查询工作正常并返回有效结果。但是,有一个关键问题 - 即使在hibernate使用少量数据时,它也会使得结果显着减慢。但是,当我直接运行此查询(我使用MySQL Workbench)时,返回的结果非常快。例如,如果此查询由hibernate执行,则需要大约1分钟才能获得结果;如果我直接从MySQL Workbench运行此查询,那么它只需要100毫秒。 我想知道为什么会发生这种情况并且会感激任何提示或帮助。 谢谢!