现有三个表: 书籍表 books(bid,bookname)
卷册表nclass(nid,bid,nname)
章节表chapters(cid,nid,cname,...)
对应关系是这样的:一本书籍下有多个卷册,一卷下有多个章节
每个表的id都己经设为主关键字,现在查询是这样的,先根据书籍表bid查卷册,然后根据卷册表nid查,章节(select * from nclass where bid=111,select * from chapters where nid=111),当我的nclass表数据跟chapters数据达到几十W之后,查询就有点慢了
请问一下大家这情情况下索引该怎么建? 提高查询的效率
卷册表nclass(nid,bid,nname)
章节表chapters(cid,nid,cname,...)
对应关系是这样的:一本书籍下有多个卷册,一卷下有多个章节
每个表的id都己经设为主关键字,现在查询是这样的,先根据书籍表bid查卷册,然后根据卷册表nid查,章节(select * from nclass where bid=111,select * from chapters where nid=111),当我的nclass表数据跟chapters数据达到几十W之后,查询就有点慢了
请问一下大家这情情况下索引该怎么建? 提高查询的效率
chapters 在 nid上建索引
章节表chapters(cid,nid,cname,...)
这两个表里分别加个符合索引
例如:nclass(nid,bid,nname) 索引:nid,bid
chapters(cid,nid,cname,...) cid,nid
create index idx_chapters_nid on chapters(nid) tablespace xx;不想放在另外的表空间就不要tablespace子句。