Mysql Rails 3,急切地加载模型
我有一个查询正在同时运行很多这样的查询Mysql Rails 3,急切地加载模型,mysql,ruby-on-rails,database,performance,eager-loading,Mysql,Ruby On Rails,Database,Performance,Eager Loading,我有一个查询正在同时运行很多这样的查询 print Account.where("id%100=0").where(:has_videos=>true).count print Account.where("id%100=1").where(:has_videos=>true).count print Account.where("id%100=2").where(:has_videos=>true).count 我想知道是否有一种方法可以使用“急切加载”或类似的方法,使其仍
print Account.where("id%100=0").where(:has_videos=>true).count
print Account.where("id%100=1").where(:has_videos=>true).count
print Account.where("id%100=2").where(:has_videos=>true).count
我想知道是否有一种方法可以使用“急切加载”或类似的方法,使其仍然能够快速工作,但只需要一次拉动。试试看
Account.group('id % 100').count
这将返回一个散列,其中键是剩余模100,值是计数 试试看
Account.group('id % 100').count
这将返回一个散列,其中键是剩余模100,值是计数 你不能在一个查询中加载所有结果,然后按你喜欢的方式破坏结果集吗?你不能在一个查询中加载所有结果,然后按你喜欢的方式破坏结果集吗?这太棒了。你能再解释一下组函数是如何工作的吗?与其他使用方法一样,Rails只是公开了SQL组函数。非常适合聚合数据,例如订单数量,但每个客户都有单独的合计,这太棒了。你能再解释一下组函数是如何工作的吗?与其他使用方法一样,Rails只是公开了SQL组函数。适用于聚合数据,例如订单数量,但每个客户有单独的总计