2

单表自关联 操作

 3 years ago
source link: https://www.oschina.net/question/4780473_2322175
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

单表自关联 操作

osc_27182321 发布于 昨天 16:51

有这样一个问题  是一个单表自关联操作

select t.m_id as mId,t.box as box from tb_features t where  t.m_id != #{mId} and t.index_flag = 'Y' 
and t.vector_index = 1  and (select sum(t1.vector * t2.vector) from tb_features t1 left join tb_features t2 on 
t1.vector_index = t2.vector_index where t1.m_id = #{mId} and t1.vector_index != 1 and t2.m_id = t.m_id) > 
(t.vector * (select t3.vector from tb_features t3 where  t3.m_id = #{mId} and t3.vector_index = 1) * 0.9)

vector 浮点类型 vector_index 是vector的下标 下标相等的才会相乘

几乎都需要全表扫描 mysql 的性能达不到理想效果  有什么优化的地方吗 或者换个存储方式


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK