Mysql 雄辩的表演哪里有问题
我在3个全局作用域中使用了eloquent where,这些作用域会导致性能显著下降 此查询在服务器上处理大约需要140秒 这是环球镜Mysql 雄辩的表演哪里有问题,mysql,laravel,eloquent,query-performance,Mysql,Laravel,Eloquent,Query Performance,我在3个全局作用域中使用了eloquent where,这些作用域会导致性能显著下降 此查询在服务器上处理大约需要140秒 这是环球镜 protected static function boot() { parent::boot(); if ( !auth('admin')->check() ) { static::addGlobalScope(new DoesntHaveForbiddenArtistScope()); stat
protected static function boot()
{
parent::boot();
if ( !auth('admin')->check() ) {
static::addGlobalScope(new DoesntHaveForbiddenArtistScope());
static::addGlobalScope('has-artist', function (Builder $builder) {
$builder->whereHas('artists');
});
static::addGlobalScope('has-mp3', function (Builder $builder) {
$builder->whereHas('mp3s');
});
}
}
这是我在望远镜里看到的计数查询
from `tracks`
where exists(
select *
from `artists`
inner join `artist_track`
on `artists`.`id` =
`artist_track`.`artist_id`
where `tracks`.`id` = `artist_track`.`track_id`
and `published` = 1
and `forbidden` = 0
)
and `published` = 1
and not exists(
select *
from `artists`
inner join `artist_track`
on `artists`.`id` =
`artist_track`.`artist_id`
where `tracks`.`id` = `artist_track`.`track_id`
and `forbidden` = 1
)
and exists(
select *
from `artists`
inner join `artist_track`
on `artists`.`id` =
`artist_track`.`artist_id`
where `tracks`.`id` = `artist_track`.`track_id`
and `published` = 1
and `forbidden` = 0
)
and exists(
select *
from `track_mp3s`
where `tracks`.`id` = `track_mp3s`.`track_id`
and `downloaded` = 1
)
有什么可以改进我写的有说服力的查询以加快速度?
我目前使用的MySQL索引对每个表的帮助有点大,但有140秒。请为每个表提供
SHOW CREATE TABLE
。当加入
表时,请限定每个列,这样我们就可以很容易地看到每个表都在哪个表中。为了获得性能方面的帮助,我们必须知道禁止是在艺术家
中还是在艺术家曲目
中。等