例如以最快的方式:我創建表後 -MySQL的 - 什麼是多個表中檢索記錄
post_id primary key
content varchar
然後我創建表的評論 - 在ASP
comment_id primary key
post_id foreign key reference post(post_id)
content varchar
顯示記錄(活動服務器頁面)
query1: select * from post;
Do while NOT RS1.EOF
{
response.write RS1("post_id")
response.write RS1("content")
query2: select * from comment where post_id = RS1("post_id")
Do while NOT RS2.EOF
{
response.write RS2("comment_id")
response.write RS2("content")
}
}
第二個查詢對錶中的每條記錄在表評論中執行全面掃描,有什麼辦法讓評論搜索比上面的方法更快嗎? 我需要使用該情況下的索引嗎?在此先感謝
也 - 添加索引到POST_ID爲 – Randy 2013-03-25 14:41:03
謝謝您的快速答覆 JW性能:好吧,我將使用JOIN @Randy:這POST_ID?在張貼表或評論? – Adrian 2013-03-25 14:51:08
你不需要手動定義一個索引,因爲從你的表定義,你已經將它設置爲主鍵,而在表'comment'上它已經是一個外鍵。 – 2013-03-25 14:52:50