Welcome Guest, Not a member yet? Register   Sign In
Why no "limit" to a model select/update?
#1

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
Reply
#2

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

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
Reply
#4

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB