Grails版本:3.0.7
Groovy版本:2.4.5
JVM版本:1.8.0_60
最近,我们在Heroku上托管的Grails 3.0.7应用程序中,MySQL中存储过程的执行时间大大降低。不幸的是,这种情况很少发生。
有时执行时间小于200毫秒,但是我们看到相同的存储过程有时会超过70,000毫秒。这是具有相同参数的相同查询。
谁能解释为什么这可能在Grails应用程序中发生,或者下面显示的代码或MySQL存储过程中是否存在任何问题?
任何见识将不胜感激。
Sql sql = new Sql(dataSource)
def ids = []
StopWatch queryStopWatch = new StopWatch('advancedSearchWithPagedResults-DD-01')
queryStopWatch.start()
sql.eachRow("{call findEvents(?, ?, ?)}",
[wildcardSearch, startDate, endDate], offset, max) { row ->
// pull out the id's into a list and later use that to get grails managed objects
ids << row.id
}
queryStopWatch.stop()
log.info(queryStopWatch.toString())
// close of the connection
sql.close()
和存储过程:
BEGIN
SELECT DISTINCT e.*
FROM event e
INNER JOIN event_organiser eo on e.event_organiser_id = eo.id
WHERE (e.event_name LIKE in_search OR e.address_town LIKE in_search OR e.address_county LIKE in_search OR eo.event_organiser_name LIKE in_search)
AND e.start_date_time >= in_start_date
AND e.start_date_time <= in_end_date
AND e.enabled = true
ORDER BY e.start_date_time;
END
最佳答案
感谢伯纳德(Bernhard)的上述评论,但我几个小时前才解决此问题。
这归因于提供程序问题,并且数据库实例在共享环境中受到限制。
我在一个租户计划中搬到了一个新的提供程序,不仅查询执行速度大大提高,而且偶发的超时问题也增加了。
注意:我使用存储过程的原因在于其他一些查询的复杂性。我决定使用存储过程以相同的方式实现所有查询。
关于hibernate - 从Grails应用程序执行的MySQL存储过程调用执行起来非常缓慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39244574/