TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Using Nested Selects for Performance in Rails

6 点作者 kb21将近 10 年前

3 条评论

kenn将近 10 年前
It would be slow on MySQL, though.<p>If you EXPLAIN that query, it&#x27;s a DEPENDENT SUBQUERY which has to fetch N*M records. It would be mitigated if the columns are property indexed, but two separate queries (N+M) just as eager loading would be faster and more predictable than nested scans in terms of IOPS.
yarb将近 10 年前
&quot;But there is no easy way to do this in ActiveRecord without sacrificing eager loading.&quot;<p>Define a relationship:<p>has_many :approved_comments, class_name: &quot;Comments&quot;, condtions: {approved: true}<p>Then eager load approved_comments.
评论 #9862805 未加载
NARKOZ将近 10 年前
Author could use counter cache to solve the problem.
评论 #9805952 未加载