简体   繁体   English

2关于更好地优化数据库设计的问题

[英]2 question about better optimize database design

1) In mysql engines, MyISAM Is Better Or InnoDB ? 1)在mysql引擎中,MyISAM更好还是InnoDB?

2) i want programming a cms that it could add a post with multi category how i must design my database to have a better performance with a few query ? 2)我想编程一个cms,它可以添加一个多类别的帖子我如何设计我的数据库,以便通过一些查询获得更好的性能?

in php how can list posts which category for example = 1 ? 在PHP中如何列出帖子哪个类别例如= 1?

thank you 谢谢

1) If you need foreign keys relations on DB level use InnoDB else use MyISAM 1)如果你需要在DB级别上使用外键关系,请使用InnoDB,否则使用MyISAM

2) You can store all categories in one table with schema like that 2)您可以使用类似的架构将所有类别存储在一个表中

create table categories (
Category_ID int NOT NULL,
ParentCategory_ID int NOT NULL default 0,
CategoryName varchar(150)
);

with Category_ID primary key 使用Category_ID主键

3) 3)

$sql = select * from posts where category_id = 1;
mysql_query($sql);

edit : Schema of post table (example) 编辑:帖子表的模式(示例)

create table posts (
    Post_ID int NOT NULL,
    Category_IDs varchar(50) NOT NULL,
    POSTDescription varchar(1000),
    POSTTime int NOT NULL
)

Post_ID is primary key of posts table. Post_IDposts表的主键。

note the Category_IDs is now varchar store value of categories in it like 1,2,3 if your post belongs to cateory 1,2 and 3.. and for deleting all posts belonging to category 1 you will run following query 请注意,如果您的帖子属于cateory 1,2和3,则Category_IDs现在是varchar存储类别的值,如1,2,3 ,并且对于删除属于类别1的所有帖子,您将运行以下查询

$sql = DELETE
FROM `posts`
WHERE FIND_IN_SET( '1', `Category_IDs` ) >0;

There is no definitive answer as it depends on your requirements but, lots of people will have already mentioned things such as: 没有明确的答案,因为它取决于您的要求,但很多人已经提到了诸如以下内容:

  • innodb has row level locking vs. myisam table locking so innodb can handle more concurrent requests. innodb具有行级锁定与myisam表锁定,因此innodb可以处理更多的并发请求。
  • innodb is transactional so inserts will generally be slower than myisam innodb是事务性的,因此插入通常比myisam慢
  • innodb is a proper RDBMS engine so supports referential integrity (transactions ACID bla bla bla) innodb是一个合适的RDBMS引擎,因此支持参照完整性(事务ACID bla bla bla)
  • innodb is more reliable than myisam innodb比myisam更可靠
  • myisam is faster than innodb for reads (myth) myisam比innodb更快读取(神话)
  • myisam tables have smaller footprints than innodb ones (myth) myisam表的脚印小于innodb表(神话)

However not many people will mention innodb clustered primary key indexes and how a well designed innodb table will easily out perform an equivalent myisam one because of this. 然而,没有多少人会提到innodb聚集的主键索引以及设计良好的innodb表如何能够轻松地执行等效的myisam表。

Here are two links explaining clustered indexes: 以下是解释聚簇索引的两个链接:

http://dev.mysql.com/doc/refman/5.0/en/innodb-index-types.html http://dev.mysql.com/doc/refman/5.0/en/innodb-index-types.html

http://www.xaprb.com/blog/2006/07/04/how-to-exploit-mysql-index-optimizations/ http://www.xaprb.com/blog/2006/07/04/how-to-exploit-mysql-index-optimizations/

Also, have a look at the following examples and articles (second example may have particular relevance) 另外,看看下面的例子和文章(第二个例子可能有特别的相关性)

Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM