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

发布于 2024-11-01 08:25:39 字数 161 浏览 1 评论 0原文

1)在mysql引擎中,MyISAM更好还是InnoDB更好?

2)我想编写一个CMS,它可以添加带有多类别的帖子 我必须如何设计数据库才能通过一些查询获得更好的性能?

在 php 中如何列出帖子的类别例如 = 1 ?

谢谢

1) In mysql engines, MyISAM Is Better Or 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 ?

in php how can list posts which category for example = 1 ?

thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜巴黎 2024-11-08 08:25:39

1) 如果您需要数据库级别的外键关系,请使用 InnoDB,否则使用 MyISAM

2) 您可以将所有类别存储在一个表中,其架构类似于

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

具有 Category_ID 主键的

架构3)

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

编辑:post 表的架构(示例)

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

Post_ID< /code> 是 posts 表的主键。

请注意,如果您的帖子属于类别 1,2 和 3,则 Category_ID 现在是 varchar 存储类别的值,如 1,2,3 ..以及删除所有帖子属于类别 1,您将运行以下查询

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

1) If you need foreign keys relations on DB level use InnoDB else use MyISAM

2) You can store all categories in one table with schema like that

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

with Category_ID primary key

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.

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

$sql = DELETE
FROM `posts`
WHERE FIND_IN_SET( '1', `Category_IDs` ) >0;
巡山小妖精 2024-11-08 08:25:39

没有明确的答案,因为这取决于您的需求,但是,很多人已经提到过以下内容:

  • innodb 具有行级锁定与 myisam 表锁定,因此 innodb 可以处理更多并发请求。
  • innodb 是事务性的,所以插入通常会比 myisam 慢
  • innodb 是一个合适的 RDBMS 引擎,因此支持引用完整性(事务 ACID bla bla bla)
  • innodb 比 myisam 更可靠
  • myisam 比 innodb 读取更快(神话)
  • myisam 表的占用空间比 innodb 更小innodb 索引(神话)

然而,没有多少人会提到 innodb 聚集主键索引,以及一张设计良好的 innodb 表如何轻松地胜过同等的 myisam 索引。

以下是解释聚集索引的两个链接:

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/

此外,请查看以下示例和文章(第二个示例可能具有特别相关性)

希望这有帮助:)

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 is transactional so inserts will generally be slower than myisam
  • innodb is a proper RDBMS engine so supports referential integrity (transactions ACID bla bla bla)
  • innodb is more reliable than myisam
  • myisam is faster than innodb for reads (myth)
  • myisam tables have smaller footprints than innodb ones (myth)

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.

Here are two links explaining clustered indexes:

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/

Also, have a look at the following examples and articles (second example may have particular relevance)

Hope this helps :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文