Can we save some I/O request via just not selecting * for just user's id? #38613
Unanswered
devbapidey
asked this question in
General
Replies: 1 comment
-
The Otherwise using |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I recently complete a sql book. Book says that we can define a BTREE index, to quickly retrieve data from index table. So we don't need to check sequentially on the table to retrieve data. Book also says sequentially check is not efficient and can take same time.
I am writing this because, when I try to get currently authenticated user id, I always use
auth()->id()
. Now this code makes a queryselect * from
userswhere
id= 2 limit 1;
.Now there is a difference in
select * from
userswhere
id= 2 limit 1;
andselect id from
userswhere
id= 2 limit 1;
. Difference is visible when we use it likeexplain select * from
userswhere
id= 2 limit 1;
andexplain select id from
userswhere
id= 2 limit 1;
Difference is, for second query where I just need id, the sql server server search it using index.

Book says it's way much faster then search without index. Now my question is
When I just need id, then why laravel select everything in user table? Can we just use id when we just required id? @taylorotwell
Beta Was this translation helpful? Give feedback.
All reactions