6

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

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

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

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

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

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

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

我错过了什么吗?

4

7 回答 7

14

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

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.

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

于 2009-11-06T19:56:20.473 回答
0

它允许您规范化数据并删除冗余。不是将所有数据存储在一个平面表中(如 Excel 电子表格),而是将不同的数据存储在单独的表中,然后将它们相互关联。

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

用户A -> 产品A

用户A -> 产品B

用户B -> 产品A

用户C -> 产品B

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

于 2009-11-06T19:44:55.567 回答
0

我对你的问题感到困惑。您还建议您如何跟踪各种表格之间的相互关系?

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

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?

SELECT person.*, car.* from person left join on car where person.car_ID = car.ID
于 2009-11-06T19:46:12.480 回答
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.

  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.

于 2009-11-06T19:47:52.813 回答
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?)

于 2009-11-06T19:51:19.817 回答
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.

于 2013-11-13T16:44:59.033 回答
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.

于 2017-10-05T19:06:16.620 回答