简体   繁体   English

MySql | 关系数据库与非关系数据库的性能

[英]MySql | relational database vs non relational database in terms of Performance

What i want to ask, if we define relations, one-to-one, one-to-many etc will that increase the performance in comparison to if we dont create relations but do join the table on the go like 我想要问的是,如果我们定义关系,一对一,一对多等将提高性能,相比之下,如果我们不创建关系,但是像往常一样加入表格

select * from employee inner join user on user.user_id = employee.user_id

i know this question has been asked before and most answers i have got saying that performance don't get affected by not using relations. 我知道之前已经问过这个问题,我得到的大多数答案都说不会因为不使用关系而影响性能。

But i have also heard that creating indexes makes the query faster, so is it possible to create indexes on tables for foreign keys without creating relations. 但我也听说创建索引会使查询更快,因此可以在不创建关系的情况下在外键的表上创建索引。 I'm little confused about index. 我对索引感到困惑。

and what if we have large database like 100+ tables plus alot of records will the relations matter in terms of database query performace?? 如果我们有大型数据库,如100多个表加上大量记录,那么这些关系在数据库查询性能方面是否重要?

im using mysql and php.. 即时通讯使用mysql和PHP ..

Foreign keys are basically used for data integrity. 外键基本上用于数据完整性。

Of course, indexing boosts performance. 当然,索引可以提升性能。

Regarding the performance with or without foreign keys, when it's said they improve performance is because when you define a foreign key you are implicitly defining an index. 关于使用或不使用外键的性能,当它表示它们提高性能时,因为当您定义外键时,您隐式定义了一个索引。 Such an index is created on the referencing table automatically if it does not exist. 如果引用表不存在,则会自动在引用表上创建此索引。

Relations are used to maintain the referential integrity of the database. 关系用于维护数据库的引用完整性。 They do not affect performance of the "select" query at all. 它们根本不影响“选择”查询的性能。 They do reduce performance of "insert", "update" and "delete" queries, but you rarely want a relational database without referntial integrity. 它们确实会降低“插入”,“更新”和“删除”查询的性能,但您很少需要没有引用完整性的关系数据库。

Indexes are what makes the "select" query run faster. 索引是使“选择”查询运行得更快的原因。 They also make insert and update queries significantly slower. 它们还使插入和更新查询显着变慢。 To know more about how the indexes work go to use-the-index-luke . 要了解有关索引如何工作的更多信息,请转到use-the-index-luke This is by far the best site about this topic that I have found. 到目前为止,这是我发现的关于这个主题的最佳网站。

That said, databases usually make indexes automatically when you declare a primary key, and some of them (MySql in particular) make indexes automatically even when you define a foreign key. 也就是说,数据库通常在声明主键时自动生成索引,其中一些(特别是MySql)即使在定义外键时也会自动生成索引。 You can read all about why they do that on the above site. 您可以在上述网站上阅读有关他们为何这样做的所有信息。

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

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