[英]How to optimize The Table inserted A record that cause Other Tables which directly count( or recurse count) The Tables record nums update in Java?
這是一個 model,我們有
學院--專業--班級--學生
一個學生只屬於A class
A class 只屬於A大調
A專業只屬於A學院
class Academy {
String name;
Integer personCount;
}
class Major {
String name;
Integer academyId;
Integer personCount;
}
class _Class {
String name;
Integer majorId;
Integer personCount;
}
class Student {
Long id;
String name;
Integer academyId;
Integer majorId;
Integer _classId;
}
因此,對於每個實體,現在都有一個表 map,我們向表student
插入一條記錄
記錄保存后,表class
必須更新其記錄(學生屬於),設置 person_count = person_count + 1
完成后,表major
也必須更新其記錄(更新記錄屬於),set person_count = person_count + 1
另外,表academy
仍然需要像major
和class
那樣進行更新
有沒有更好的方案來減少數據庫寫入時間? 或者更好的表結構?
我現在還在想,它確實壓了寫數據庫
學生記錄的限制將低於 100,000。
但在特定時間它會做高頻率的插入
我期待一個快速響應的解決方案
計划 A:使用TRIGGER... ON INSERT...
B 計划:顯式寫入UPDATEs
來增加計數器。
Plan C:將Plan B封裝到Stored Procedures中。
計划 D:不要將計數保留在表中,而是在需要時重新計算它們。 (這是最純粹的方式——“thou shalt not have redundant info”。) 對於一千名學生,我懷疑是否有很大的“壓力”。 對於一百萬學生來說,表現很可能很差。 在這種情況下,您所擁有的(帶有personCount
的表)本質上是Summary Tables
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.