laravel-wherehasin
laravel-wherehasin copied to clipboard
关于wherehasin的子查询能不能选择不用主表关联
select * from test_users
where test_users
.id
in
(
select test_user_profiles
.user_id
from test_user_profiles
where test_users
.id
= test_user_profiles
.user_id
)
改成以下类型
select * from test_users
where test_users
.id
in
(
select test_user_profiles
.user_id
from test_user_profiles
)
当 两个表都 非常大的时候 做了 test_users
.id
= test_user_profiles
.user_id
这个关联就会导致变得很慢 一般使用的时候都会自己写相关的条件比如:
select * from test_users
where test_users
.id
in
(
select test_user_profiles
.user_id
from test_user_profiles
where created_at
=1646642336
)