PERF: work around LIMIT breaking query plan
(CTE is a optimisation boundary, so limit no longer has any effect on plan)
This commit is contained in:
parent
c80ef9e3fa
commit
ca2100d012
|
@ -130,6 +130,7 @@ class TopicTrackingState
|
||||||
new = TopicQuery.new_filter(Topic, "xxx").where_values.join(" AND ").gsub!("'xxx'", treat_as_new_topic_clause)
|
new = TopicQuery.new_filter(Topic, "xxx").where_values.join(" AND ").gsub!("'xxx'", treat_as_new_topic_clause)
|
||||||
|
|
||||||
sql = <<SQL
|
sql = <<SQL
|
||||||
|
WITH x AS (
|
||||||
SELECT u.id AS user_id,
|
SELECT u.id AS user_id,
|
||||||
topics.id AS topic_id,
|
topics.id AS topic_id,
|
||||||
topics.created_at,
|
topics.created_at,
|
||||||
|
@ -163,7 +164,8 @@ SQL
|
||||||
if topic_id
|
if topic_id
|
||||||
sql << " AND topics.id = :topic_id"
|
sql << " AND topics.id = :topic_id"
|
||||||
end
|
end
|
||||||
sql << " ORDER BY topics.bumped_at DESC LIMIT 500"
|
|
||||||
|
sql << " ORDER BY topics.bumped_at DESC ) SELECT * FROM x LIMIT 500"
|
||||||
|
|
||||||
SqlBuilder.new(sql)
|
SqlBuilder.new(sql)
|
||||||
.map_exec(TopicTrackingState, user_ids: user_ids, topic_id: topic_id)
|
.map_exec(TopicTrackingState, user_ids: user_ids, topic_id: topic_id)
|
||||||
|
|
Loading…
Reference in New Issue