从Grails应用程序调用MySQL存储过程非常慢

时间:2016-08-31 08:33:34

标签: hibernate grails

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

1 个答案:

答案 0 :(得分:0)

感谢Bernhard的上述评论,但我刚刚在几个小时前解决了这个问题。

这是由于提供商问题而且数据库实例在共享环境中受到限制。

我在单个租户计划中迁移到新的提供商,不仅查询执行速度显着提高,而且零星的超时问题也发生了。

注意:我使用存储过程的原因归结为其他一些查询的复杂性。我决定使用存储过程以相同的方式实现所有查询。

相关问题