例如以最快的方式:我创建表后 -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