“关系数据库”中的“关系”对我们意味着什么?

时间:2022-01-02 16:53:56

I know, relational database is a database where fields in one table are linking to rows in the others, something like this.

我知道,关系数据库是一个数据库,其中一个表中的字段链接到其他表中的行,就像这样。

But I can't understand what does it mean for me as a web developer!

但我无法理解作为Web开发人员对我来说意味着什么!

As I know, a query with joins and nested select can reduce perfomance (especially drupal-style queries with dozens of joins). Even more, any queries to DB are bottlenecks, and then you have lots of users you have to cache every select request.

据我所知,带有连接和嵌套选择的查询可以降低性能(特别是具有数十个连接的drupal风格查询)。更重要的是,对DB的任何查询都是瓶颈,然后你有很多用户需要缓存每个选择请求。

If you cache every select request, it's better to cache simple requests rather than complicated. You can either cache "select * from tbl1 where id = 123" and "select * from tbl2 where id = 456" or "select * from tbl1, tbl2 where ...", but if you choose the second way, you'll need to cache every combination of objects - it isn't cool.

如果缓存每个选择请求,最好缓存简单请求而不是复杂请求。您可以缓存“select * from tbl1 where id = 123”和“select * from tbl2 where id = 456”或“select * from tbl1,tbl2 where ...”,但是如果你选择第二种方式,你将会需要缓存每个对象组合 - 这并不酷。

Ok, now we use only very simple queries like "select * from tbl1 where id = 123" of "select id from tbl1 order by id limit 0, 30" and cache them (or we can cache only the first type of queries, whatever). There queries and not less simple INSERT, DELETE and UPDATE are all what we need and all what we use!

好的,现在我们只使用非常简单的查询,例如“select * from tbl1 where id = 123”“select id from tbl1 order by id limit 0,30”并缓存它们(或者我们只能缓存第一类查询,无论如何)。有查询,而不是简单的INSERT,DELETE和UPDATE都是我们需要的,也是我们所用的!

As we can see, all the relational logic are in the main language of the application, not in SQL. So, why do we need all this relational things? What do they mean? What do "relational" type has what another types hasn't but it is needed? If we don't use relational features, why do everyone still use MySQL or whatever relational databases, even if he care about the perfomance?

我们可以看到,所有关系逻辑都是应用程序的主要语言,而不是SQL。那么,为什么我们需要所有这些关系的东西呢?他们的意思是什么? “关系型”具有什么样的东西,其他类型没有但需要它?如果我们不使用关系特性,为什么每个人仍然使用MySQL或任何关系数据库,即使他关心性能?

This type of databases has become a standard. Why? I have no clue. I've hardly ever heard about somebody using non-relational database, except for the on in GAE.

这种类型的数据库已成为一种标准。为什么?我没有任何线索。我几乎没有听说有人使用非关系数据库,除了GAE中的on。

Am I missing something?

我错过了什么吗?

7 个解决方案

#1


11  

If you want to learn about what relational means, I recommend the book "SQL and Relational Theory" by C. J. Date.

如果你想了解关系的含义,我推荐C. J. Date的书“SQL和关系理论”。

Relational in this context doesn't refer to relationships. It refers to relations which are basically what tables are called in the mathematical theories that led to the relational model.

在此上下文中的关系不涉及关系。它指的是基本上是在导致关系模型的数学理论中称为表的关系。

The reason that relational databases have become ubiquitous is that they are the most general-purpose solution for organizing data with minimum redundancy.

关系数据库普遍存在的原因是它们是用于组织具有最小冗余的数据的最通用的解决方案。

There are valid reasons to use non-relational solutions. They often solve specific tasks of data-management extremely well, but are weak in other areas. Whereas SQL and relational databases strike a compromise, solving a larger set of problems adequately, with fewer areas of weakness.

有正当理由使用非关系解决方案。他们经常很好地解决数据管理的具体任务,但在其他领域却很薄弱。 SQL和关系数据库达成妥协,充分解决了更多问题,减少了弱点。

Other technologies currently available that are not based on the relational model are listed in "The Next-Gen Databases."

目前可用的其他不基于关系模型的技术列在“下一代数据库”中。

#2


0  

I'm confused by your question. How else to you propose you keep track of how various tables relate to each other?

我对你的问题感到困惑。你怎么建议你跟踪各种表格彼此之间的关系?

for example, I have a list of cars, and a list of people, and I need to connect which person owns each car, so I have a car_ID column in the person database. How would propose keeping track of these relations

例如,我有一个汽车列表和一个人员列表,我需要连接哪个人拥有每辆汽车,所以我在人员数据库中有一个car_ID列。如何建议跟踪这些关系

Also, you say that you want to cache 'all queries are bottlenecks' and you only want to cache 'simple' queries. However, I'm 90% sure that making multiple small queries will be more resource intensive than making several smaller queries. you also don't have to cache every combination, only the ones that actually exist. in my example, what's wrong with a query like this?

此外,您说要缓存“所有查询都是瓶颈”,您只想缓存“简单”查询。但是,我90%肯定制作多个小型查询会比制作几个较小的查询更加耗费资源。您也不必缓存每个组合,只需缓存实际存在的组合。在我的例子中,这样的查询出了什么问题?

SELECT person.*, car.* from person left join on car where person.car_ID = car.ID

#3


0  

Relational Databases have become the de-facto database for a number of reasons.

由于多种原因,关系数据库已成为事实上的数据库。

  1. Setting up primary, foreign and unique constraints enforces certain business rules at the lowest levels, helps ensure data integrety, and makes the database relationships easily understandable to just about any level of IT professional.

    设置主要,外部和唯一约束会在最低级别强制执行某些业务规则,有助于确保数据集成,并使数据库关系易于理解,几乎可以与任何级别的IT专业人员理解。

  2. A properly designed relational database is in fact faster behind the scenes for many process (not all).

    事实上,正确设计的关系数据库在许多进程(不是全部)的幕后更快。

  3. The querying of relational database is fairly quick to learn, and easy to do.

    查询关系数据库相当快速,易学易用。

  4. Relational databases help limit data duplication, and from a data engineering standpoint, that is a wonderful thing.

    关系数据库有助于限制数据重复,从数据工程的角度来看,这是一件很棒的事情。

and many others, but these are a few.

和许多其他人,但这些是一些。

#4


0  

If you don't use relations, you need to store everything in a giant table with numerous number of columns. Or you can use a datacube (I think?)

如果不使用关系,则需要将所有内容存储在具有大量列的巨型表中。或者你可以使用datacube(我想?)

#5


0  

It allows you to normalize your data and remove redanancy. Rather than store all data in a flat table (like an excel spreadsheet), you store disparate data in separate tables and then relate them to one another.

它允许您规范化数据并消除重复。您可以将不同的数据存储在单独的表中,然后将它们相互关联,而不是将所有数据存储在平面表中(如excel电子表格)。

For example, you can store users in a Users table and products in a Products table and then use a relationship table to relate which user ordered which products.

例如,您可以将用户存储在Products表中,将产品存储在Products表中,然后使用关系表来关联哪个用户订购了哪些产品。

UserA -> ProductA

UserA - > ProductA

UserA -> ProductB

UserA - > ProductB

UserB -> ProductA

UserB - > ProductA

UserC -> ProductB

UserC - > ProductB

With normalized data, it means if data changes, it only needs to be updated in one place. If a user changes their name, only that user record changes. If a product price needs to be raised, only that product record changes. You don't have to scour your flat table looking for duplicate data to replace.

对于标准化数据,这意味着如果数据发生变化,则只需在一个地方进行更新。如果用户更改其名称,则仅更改该用户记录。如果需要提高产品价格,则只会更改产品记录。您不必搜索平面表以查找要替换的重复数据。

#6


0  

Valya, if the data in your application will not be added to, updated or deleted, then a cache is the fastest way to search and display it. I am curious to know what this data is that everyone is in such a hurry to see, but will not be updating? Maybe some details would help. I know someone who stored his entire database in memory with a write-through cache, and yes, it flew! He is the only developer I know of who could pull this off. Maybe you need to reinvent the rocket engine, and maybe you don't.

Valya,如果您的应用程序中的数据不会被添加,更新或删除,那么缓存是搜索和显示它的最快方式。我很想知道这些数据是什么,每个人都急着看,但不会更新?也许一些细节会有所帮助。我知道有人通过直写缓存将他的整个数据库存储在内存中,是的,它飞了!他是我所知道的唯一可以解决这个问题的开发人员。也许你需要重新发明火箭发动机,也许你不需要。

#7


0  

Relation is the mathematical word for table. Columns are in relation with each other, otherwise they were not in the same table.

关系是表的数学词。列彼此相关,否则它们不在同一个表中。

For example, two numbers are in relation with each other if they differ a multiple of 3. Let's write a few of them down: (0,0), (1,4), (2,-1), etc. You see a collection of rows appear, which is a table.

例如,如果它们的3的倍数不同,则两个数字相互关联。让我们写下一些数字:(0,0),(1,4),(2,-1)等。你看出现一组行,这是一个表。

#1


11  

If you want to learn about what relational means, I recommend the book "SQL and Relational Theory" by C. J. Date.

如果你想了解关系的含义,我推荐C. J. Date的书“SQL和关系理论”。

Relational in this context doesn't refer to relationships. It refers to relations which are basically what tables are called in the mathematical theories that led to the relational model.

在此上下文中的关系不涉及关系。它指的是基本上是在导致关系模型的数学理论中称为表的关系。

The reason that relational databases have become ubiquitous is that they are the most general-purpose solution for organizing data with minimum redundancy.

关系数据库普遍存在的原因是它们是用于组织具有最小冗余的数据的最通用的解决方案。

There are valid reasons to use non-relational solutions. They often solve specific tasks of data-management extremely well, but are weak in other areas. Whereas SQL and relational databases strike a compromise, solving a larger set of problems adequately, with fewer areas of weakness.

有正当理由使用非关系解决方案。他们经常很好地解决数据管理的具体任务,但在其他领域却很薄弱。 SQL和关系数据库达成妥协,充分解决了更多问题,减少了弱点。

Other technologies currently available that are not based on the relational model are listed in "The Next-Gen Databases."

目前可用的其他不基于关系模型的技术列在“下一代数据库”中。

#2


0  

I'm confused by your question. How else to you propose you keep track of how various tables relate to each other?

我对你的问题感到困惑。你怎么建议你跟踪各种表格彼此之间的关系?

for example, I have a list of cars, and a list of people, and I need to connect which person owns each car, so I have a car_ID column in the person database. How would propose keeping track of these relations

例如,我有一个汽车列表和一个人员列表,我需要连接哪个人拥有每辆汽车,所以我在人员数据库中有一个car_ID列。如何建议跟踪这些关系

Also, you say that you want to cache 'all queries are bottlenecks' and you only want to cache 'simple' queries. However, I'm 90% sure that making multiple small queries will be more resource intensive than making several smaller queries. you also don't have to cache every combination, only the ones that actually exist. in my example, what's wrong with a query like this?

此外,您说要缓存“所有查询都是瓶颈”,您只想缓存“简单”查询。但是,我90%肯定制作多个小型查询会比制作几个较小的查询更加耗费资源。您也不必缓存每个组合,只需缓存实际存在的组合。在我的例子中,这样的查询出了什么问题?

SELECT person.*, car.* from person left join on car where person.car_ID = car.ID

#3


0  

Relational Databases have become the de-facto database for a number of reasons.

由于多种原因,关系数据库已成为事实上的数据库。

  1. Setting up primary, foreign and unique constraints enforces certain business rules at the lowest levels, helps ensure data integrety, and makes the database relationships easily understandable to just about any level of IT professional.

    设置主要,外部和唯一约束会在最低级别强制执行某些业务规则,有助于确保数据集成,并使数据库关系易于理解,几乎可以与任何级别的IT专业人员理解。

  2. A properly designed relational database is in fact faster behind the scenes for many process (not all).

    事实上,正确设计的关系数据库在许多进程(不是全部)的幕后更快。

  3. The querying of relational database is fairly quick to learn, and easy to do.

    查询关系数据库相当快速,易学易用。

  4. Relational databases help limit data duplication, and from a data engineering standpoint, that is a wonderful thing.

    关系数据库有助于限制数据重复,从数据工程的角度来看,这是一件很棒的事情。

and many others, but these are a few.

和许多其他人,但这些是一些。

#4


0  

If you don't use relations, you need to store everything in a giant table with numerous number of columns. Or you can use a datacube (I think?)

如果不使用关系,则需要将所有内容存储在具有大量列的巨型表中。或者你可以使用datacube(我想?)

#5


0  

It allows you to normalize your data and remove redanancy. Rather than store all data in a flat table (like an excel spreadsheet), you store disparate data in separate tables and then relate them to one another.

它允许您规范化数据并消除重复。您可以将不同的数据存储在单独的表中,然后将它们相互关联,而不是将所有数据存储在平面表中(如excel电子表格)。

For example, you can store users in a Users table and products in a Products table and then use a relationship table to relate which user ordered which products.

例如,您可以将用户存储在Products表中,将产品存储在Products表中,然后使用关系表来关联哪个用户订购了哪些产品。

UserA -> ProductA

UserA - > ProductA

UserA -> ProductB

UserA - > ProductB

UserB -> ProductA

UserB - > ProductA

UserC -> ProductB

UserC - > ProductB

With normalized data, it means if data changes, it only needs to be updated in one place. If a user changes their name, only that user record changes. If a product price needs to be raised, only that product record changes. You don't have to scour your flat table looking for duplicate data to replace.

对于标准化数据,这意味着如果数据发生变化,则只需在一个地方进行更新。如果用户更改其名称,则仅更改该用户记录。如果需要提高产品价格,则只会更改产品记录。您不必搜索平面表以查找要替换的重复数据。

#6


0  

Valya, if the data in your application will not be added to, updated or deleted, then a cache is the fastest way to search and display it. I am curious to know what this data is that everyone is in such a hurry to see, but will not be updating? Maybe some details would help. I know someone who stored his entire database in memory with a write-through cache, and yes, it flew! He is the only developer I know of who could pull this off. Maybe you need to reinvent the rocket engine, and maybe you don't.

Valya,如果您的应用程序中的数据不会被添加,更新或删除,那么缓存是搜索和显示它的最快方式。我很想知道这些数据是什么,每个人都急着看,但不会更新?也许一些细节会有所帮助。我知道有人通过直写缓存将他的整个数据库存储在内存中,是的,它飞了!他是我所知道的唯一可以解决这个问题的开发人员。也许你需要重新发明火箭发动机,也许你不需要。

#7


0  

Relation is the mathematical word for table. Columns are in relation with each other, otherwise they were not in the same table.

关系是表的数学词。列彼此相关,否则它们不在同一个表中。

For example, two numbers are in relation with each other if they differ a multiple of 3. Let's write a few of them down: (0,0), (1,4), (2,-1), etc. You see a collection of rows appear, which is a table.

例如,如果它们的3的倍数不同,则两个数字相互关联。让我们写下一些数字:(0,0),(1,4),(2,-1)等。你看出现一组行,这是一个表。