【发布时间】: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