spring boot jpa訪問mysql返回數據慢的解決方法

最近寫了個股票數據項目,存儲歷史的表大約有1.3G左右,在根據字段查詢數據庫的時候發現每次須要上10秒才能返回數據。java

解決方法就是給實體類字段添加索引,修改後查詢基本都在1秒內返回數據,爽翻天的感受,害我查了很久都找不到緣由。數據庫

給實體類添加索引示例以下;學習

@Entity
@Table(name = "HistoryEntity",
    indexes = {@Index(name = "my_code",  columnList="code", unique = false)}
)
public class HistoryEntity {
@Column(name = "code", nullable = false)
    private String code;

//get/set方法忽略

}

 

本文只是學習總結。code

感謝Moddy大哥的指教!索引

相關文章
相關標籤/搜索