数据库大数据量情况下查询性能低,耗时长的一种问题以及解决思路

  使用联合索引

1.要注意索引时的排列顺序,譬如取最近一周的数据,那么时间作为索引要倒序排列

2.创建联合索引时,索引自身也要注意排序,譬如:

select orderId from Order where  orderTime>=2018-12-5 and orderTime<=2018-12-12 and Region="武汉" and product="computer";

那么我们联合索引的各个索引顺序不能错  必须是orderTime, Region ,LabName

3 其实2中的sql语句还有待商榷:

譬如我们单独查orderTime>=2018-12-5 and orderTime<=2018-12-12 有50万条数据,武汉有20万条数据,computer有25万条数据,那么我们应该把regin条件排在第一,product条件放在第二,orderTime放在第三。

相应的我们的联合索引的排序要按照2的思路作修改。

参考文献:https://blog.csdn.net/Abysscarry/article/details/80792876

原文地址:https://www.cnblogs.com/wholeworld/p/10099905.html