我有一个PostgreSQL数据库表,用于存储所有系统日志。当前,该表具有约5.5M行。这是它的结构:
create_table "app_logs", force: :cascade do |t|
t.bigint "admin_id"
t.datetime "received_at"
t.datetime "created_at"
t.datetime "updated_at"
t.string "admin_name"
t.string "event_type"
t.jsonb "event_data"
t.string "trackable_type"
t.integer "trackable_id"
t.index "date(received_at)", name: "index_activity_logs_date_received_at"
t.index ["admin_id"], name: "idx_18712_index_activity_logs_on_admin_id"
t.index ["event_type"], name: "index_activity_logs_on_event_type"
t.index ["received_at"], name: "index_activity_logs_on_received_at"
t.index ["trackable_type", "trackable_id"], name: "index_activity_logs_on_trackable_type_and_trackable_id"
end
这就是我尝试从表中检索数据的方式(并且尝试最终以错误-响应/返回数据时间太长):
@data = AppLog
.by_event_type(params[:event_type])
.by_admin(params[:admin_id])
.by_date_from(params[:logs_from])
.by_date_to(params[:logs_to])
.page(params[:page]).per(100)
.order('received_at DESC')
我可以使用Rails + PostgreSQL管理这种结构(以及适当的索引编制)还是更适合(且可扩展)以专注于Elastic等第三方解决方案?