CodeIgniter Forums
Why no "limit" to a model select/update? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Why no "limit" to a model select/update? (/showthread.php?tid=76996)



Why no "limit" to a model select/update? - Cyto5 - 07-10-2020

When using a model such as

$model->find(1) or $model->update(1,[values])

Why does it not automatically apply a LIMIT 1 in the query? If I am accessing a table with millions of records wouldn't it be a lot slower without the limit in general. If I pass in (one) id and it's the primary id there would never be a case where it should look for or update more then 1 record.

$model->update(1,[values]) turn into UPDATE tbl SET col = 'val' WHERE id IN (1)

Unless the database (mysql, mysqli driver) in my case actuomatically stops trying to find records after reaching one even without the limit? (I do not know)

Thanks


RE: Why no "limit" to a model select/update? - sistemas - 07-17-2020

I have also thought the same. In my case, I do a custom query when the table to query is too big.


RE: Why no "limit" to a model select/update? - MGatner - 07-19-2020

No need for that! All the database engines I know handle that for you. If you lookup a primary or unique key it will stop upon finding it. Maybe some alternate database types would need this down the road but for now it’s a non-issue


RE: Why no "limit" to a model select/update? - Cyto5 - 07-20-2020

(07-19-2020, 11:49 AM)MGatner Wrote: No need for that! All the database engines I know handle that for you. If you lookup a primary or unique key it will stop upon finding it. Maybe some alternate database types would need this down the road but for now it’s a non-issue

Thanks. Yeah I heard that from a few others now too. That's just one of those things I never heard of specifically from any videos or reading any docs so I wasn't sure.