【问题标题】:GORM Simple Query but VERY slowGORM 简单查询但非常慢
【发布时间】:2015-05-19 06:40:22
【问题描述】:

我正在使用带有 mysql 数据库的 grails 2.3.8。我有这个包含 200,000 条记录的域类。检索需要 18 秒。

class Alert {
    Long id
    int recorded_at
    int responded_at
    String source_name
    String source_type
    String check_name
    String label
    String priority 
    String status
    String message
    String remarks
    Date dateCreated 
    Date lastUpdated 

    static mapping = {
        table "alerts"
        version false
        dateCreated column: "created_at" 
        lastUpdated column: "updated_at"    
        message type: "text"
        remarks type: "text"
        recorded_at index: 'Recorded_Atx'
        //sort recorded_at: "desc"
    }

    static constraints = {
        responded_at(nullable:true)
        message(nullable:true)
        remarks(nullable:true)
    }
}

 def alerts = Alert.findAll()

为什么?

【问题讨论】:

  • 你的比较是什么,让你估计,这很慢。你真的需要实现所有这些行吗?
  • GORM 很慢,因为它要创建 200,000 个对象。就像任何 ORM 如果需要创建 200,000 个对象都会很慢一样。
  • 有什么方法可以加快速度?
  • 什么是“快”?你的基线是什么,例如通过jdbc读取简单地图需要多长时间?你还没有回答:你真的需要内存中的所有 20 万个对象吗?你真的不想一次又一次地运行findAll() 吗?您如何处理这些数据,而这无法通过缩小数据库中的结果集来完成?
  • 我在和 MySQL 工作台比较

标签: mysql grails grails-orm grails-domain-class grails-2.3


【解决方案1】:

这是因为 MySQL 等到所有结果返回后再将其提供给用户。 Oracle 和 Postgres 等数据库支持允许批量返回结果的持有者。然后我们可以将结果以块的形式返回给用户。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    • 2020-03-26
    • 2016-10-06
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多