选择花费大量时间在联合内所有按日期排序描述?

ws51t4hk  于 2021-06-25  发布在  Mysql
关注(0)|答案(0)|浏览(230)

我有一个选择来获取警报。

select 'comments' prefix, c.foto, c.data as data, c.user, concat(k.user, ' comments your post') as logs from comentarios c 
inner join posts p on c.foto = p.id 
inner join cadastro k on c.user = k.id 
where p.user = 1 and p.user <> c.user and c.delete = 0

union all

select 'like' prefix, l.post, l.data as data, l.user, concat(k.user, ' liked your post') as logs from likes l 
inner join posts p on l.post = p.id 
inner join cadastro k on l.user = k.id 
where p.user = 1 and l.user <> p.user

order by data desc
limit 5

问题是如果我这样运行select,需要2.4871秒。
如果我移除 select 'like'... =0.0024,但是如果我运行这个select-apart,它将只需要0.010,没有order-by-data-desc。
知道为什么吗?我不知道问题是工会还是。。。它们都有很好的索引。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题