表大小
24943*24943
1.原語(yǔ)句
SELECT A.ID1,A.ID2,A.relation FROM element_relations as A where ID1= 17 or ID2=17 order by relation DESC limit 300;
分別建立ID1,和ID2的索引
索引id1损姜,id2未用上
查詢時(shí)間
2.使用union all
(SELECT A.ID1,A.ID2,A.relation FROM element_relations as A where ID1= 1 order by relation DESC limit 300) union all (SELECT A.ID1,A.ID2,A.relation FROM element_relations as A where ID2= 1 order by relation DESC limit 300) order by relation DESC limit 300;
效果并不理想
3.重新建立索引
索引1:使用id1和relation聯(lián)合索引
索引2:使用id3和relation聯(lián)合索引
使用語(yǔ)句1
使用語(yǔ)句二 order by