簡體   English   中英

如何處理mysql表中的大量行

[英]How to handle large number of rows in mysql table

我有一個表,如帶有100k +行的comment ,並且它每天都在增加

我經常需要從該表中選擇記錄

+----+---------+-------
| id | comment | type |
+----+---------+------+
| 1    aaa       photo|
| 2    bbb       phono|
| 3    ccc       video|
| 4    ddd       video|
| 5    eee       story|
 ...   ...       ...

如果我創建1個表以外的3個表,會更快嗎?

comment_photo
+----+---------+
| id | comment |
+----+---------+
| 1    aaa     |
| 2    bbb     |
 ...   ...    


comment_video
+----+---------+
| id | comment |
+----+---------+
| 1    ccc     |
| 2    ddd     |
 ...   ...   


comment_story
+----+---------+
| id | comment |
+----+---------+
| 1    eee     |
| 2    fff     |
 ...   ...   

制作表格comment_photocomment_video不是一個好主意。 如果將來還會有其他類型該怎么辦? 下一張桌子?

更好的方法是添加表comment_type

+----+--------+
| id | name   |
+----+--------+
| 1    photo  |
| 2    video  |
| 3    story  |
 ...   ...    

然后將comment更改為:

+----+---------+---------
| id | comment | type_id |
+----+---------+---------+
| 1    aaa       1       |
| 2    bbb       1       |
| 3    ccc       2       |
| 4    ddd       2       |
| 5    eee       3       |
 ...   ...       ...

還請記住精心計划的索引。 嘗試EXPLAIN您的疑問並記住-嵌套循環是你的敵人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM