1
我已經繼承了一個遺留應用程序,它利用自引用表來促進分層結構。這導致遞歸方法調用正在產生「難聞的氣味」。重新設計自引用mysql表
的PARENT_ID列引用同一個表的主鍵,這裏有大約25萬條記錄:
+-------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+---------+------+-----+---------+----------------+
| phase_id | int(10) | NO | PRI | NULL | auto_increment |
| plat_id | int(10) | YES | MUL | NULL | |
| name | text | YES | | NULL | |
| parent_id | int(10) | YES | MUL | NULL | |
| plan_id | int(10) | YES | MUL | NULL | |
+-------------+---------+------+-----+---------+----------------+
mysql> show table status like 'ref'\G
*************************** 1. row ***************************
Name: phase
Engine: MyISAM
Version: 10
Row_format: Dynamic
Rows: 25223658
Avg_row_length: 20
Data_length: 509450960
Max_data_length: 281474976710655
Index_length: 1026267136
Data_free: 0
Auto_increment: 25238013
我對這種結構的幾個問題:
- 是實現自引用表通常是不好的做法?我能想到的主要負面因素是,在單個查詢中獲取層次結構的最大深度是很困難/不可能的,因爲可能會有X個孩子。
- 值得重新設計嗎?擁有如此多的數據使得移動它變得更加困難。
- 我有什麼選擇?我已經聽到了關於表格分區的一些信息,但不知道它是否適合我的情況。
任何指針將是非常讚賞 NS
可能的[在關係數據庫中存儲分層數據的選項是什麼?]的重複(http://stackoverflow.com/questions/4048151/what-are-the-options-for-storing-hierarchical-data-關係數據庫) – Sebas 2012-07-12 14:10:02
感謝您的鏈接Sebas,我沒有在我的搜索中找到。本文中描述的'平板模型'聽起來非常好:http://www.ferdychristant.com/blog//articles/DOMM-7QJPM7 – nonshatter 2012-07-12 14:33:39
是的,這是一個非常有趣且富有挑戰性的主題。 – Sebas 2012-07-12 14:35:09