[英]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_ID
是posts
表的主键。
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: 没有明确的答案,因为它取决于您的要求,但很多人已经提到了诸如以下内容:
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) 另外,看看下面的例子和文章(第二个例子可能有特别的相关性)
500 million row forum/thread example 500万行论坛/线程示例
MySQL and NoSQL: Help me to choose the right one MySQL和NoSQL:帮我选择合适的
125 million row product/category example 1.25亿行产品/类别示例
Rewriting mysql select to reduce time and writing tmp to disk 重写mysql选择以减少时间并将tmp写入磁盘
100 million row experiment 1亿行实验
Optimal MySQL settings for queries that deliver large amounts of data? 为提供大量数据的查询提供最佳MySQL设置?
Innodb vs. myisam vs. falcon benchmarks Innodb vs. myisam vs. falcon基准
http://www.mysqlperformanceblog.com/2007/01/08/innodb-vs-myisam-vs-falcon-benchmarks-part-1/ http://www.mysqlperformanceblog.com/2007/01/08/innodb-vs-myisam-vs-falcon-benchmarks-part-1/
Hope this helps :) 希望这可以帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.