1

如何优化具有复杂 SQL 的 paginate_by_sqlLEFT JOIN并且GROUP BY在查询结束时有很多?

除了 ,我还有其他选择paginate_by_sql吗?

我们的项目使用 Rails 2.3 和 Ruby 1.8 和 MySQL。

     SELECT Table.name as sql_course_name,Table.id as sql_course_id, 
            table1.name as sql_subject_name, table1.id as sql_subject_id, 
            table3.id as sql_s_c_id, table5.*
       FROM table5
  LEFT JOIN table2 on table2.deleted = false and table2.content_id = table5.id
  LEFT JOIN lessons on lessons.deleted = false and lessons.id = table2.lesson_id
  LEFT JOIN table3 on table3.deleted = false and table3.content_id = table5.id 
  LEFT JOIN table1 on table1.deleted = false and table1.id = table3.subject_id 
  LEFT JOIN Table on Table.deleted = false and table1.course_id = Table.id
  LEFT JOIN table4 on table4.deleted = false and table4.content_id = table5.id
  LEFT JOIN attachments on attachments.deleted = false and attachments.id = table4.attachment_id
      WHERE #{str} 
   GROUP BY table5.id, table3.id
4

0 回答 0