Use a nested query to save a rountrip#4
Use a nested query to save a rountrip#4casperisfine wants to merge 1 commit intoplanetscale:mainfrom
Conversation
|
Thanks @casperisfine! I have it separate because MySQL doesn't support subqueries with limit. The single query would be great though, maybe we could get AR to produce this: Which would work with MySQL. I'll try playing with it later 😄 |
|
@mscoutermarsh Hey! Any update on getting this somehow merged? Maybe as an option? It seems to be working just fine. I'm wondering which version of MySQL were you talking about, when saying that the limit subquery does not work? |
|
@pusewicz I tried it on 8.0.27 I believe. I believe it's only an issue with 8+. Did you try with an older version? |
|
@mscoutermarsh Correct! I've been running similar queries on 5.7. |
|
Thanks! I also confirmed it works with MySQL 5.7. But not newer versions. Here’s what I’m thinking. Since 5.7 is end-of-life this year, I’m not sure it’s worth doing the work of adding a config option. I personally haven’t benchmarked it though, maybe you all are seeing a great perf increase from the single query? Might make sense to run a fork of the gem with just this change in it to see if it’s worth it. |
There might be a reason that escapes me, but I don't get why the gem is doing a full roundtrip to fetch the ids. Active Record supports nested queries just fine.