4 ms·
Might be possible to use a CTE instead, something like this: with page_numbers as ( select id from docs order by id limit 25 offset 50 ) sele
by simonw 4y ago
Might be possible to use a CTE instead, something like this:
with page_numbers as (
select id from docs order by id limit 25 offset 50
)
select * from docs where id in (
select id from page_numbers
)
- aarondf 4y agoMmm yeah, that's clever! I like it. I think for my package (the Laravel one) I'll have to hold off on that because CTEs only work with MySQL 8.0 and up. Also the Laravel query builder doesn't have methods to add CTEs, unfortunately. I'm gonna noodle on this though, there's something nice about it.
- aledalgrande 4y agoI don't know if it's the same for MySQL, but in Postgres a CTE would possibly force the planner to make less efficient choices [1]. Would be interesting if someone who knows more than me could clarify on this [1] https://hakibenita.com/be-careful-with-cte-in-postgre-sql https://hakibenita.com/be-careful-with-cte-in-postgre-sql
- Lukas_Skywalker 4y agoThis changed in version 12. See the disclaimer: This article is intended for PostgreSQL versions 11 and prior. Starting at version 12, PostgreSQL changed the way it treats CTE to prevent the issues described in this article.
- aledalgrande 4y agoOhhh nice catch!