在数据库中存储html用于使用有哪些缺点?

时间:2022-10-17 18:51:15

Altough its very easy to do a search about the topic, it's not as easy to come to a conclusion. What are some cons of storing html in a database for use?

虽然很容易对这个话题进行搜索,但得出结论并不容易。在数据库中存储html用于使用有哪些缺点?

3 个解决方案

#1


3  

HTML is static, and querying the data from a database uses database resources; database resources are typically among the more restricted on moderate to heavy use systems, therefore it makes sense to not store HTML in the database, but to place it on the filesystem, where it can be retrieved without using critical resources.

HTML是静态的,从数据库查询数据使用数据库资源;数据库资源通常受到中度到重度使用系统的限制,因此不将HTML存储在数据库中,而是将它放在文件系统中,在那里可以不使用关键资源检索它。

#2


2  

In the broadest sense, HTML is a document markup language and serves to structure data into a document. The database on the other hand should contain raw data organized along its logical relations. Documents use formatting and may present data redundantly, but the true, underlying data is always fixed. Thus you should store the most immediate, raw form of data that you possibly can, and retrieve it in meaningful ways using both the query language itself to create suitable views for your purposes, and other, output-specific data processing to generate documents.

从最广泛的意义上说,HTML是一种文档标记语言,用于将数据结构化为文档。另一方面,数据库应该包含按照其逻辑关系组织的原始数据。文档使用格式,并可能冗余地显示数据,但真实的底层数据总是固定的。因此,您应该尽可能地存储最直接、最原始的数据形式,并使用查询语言本身以有意义的方式检索数据,以便为您的目的创建适当的视图,以及其他特定于输出的数据处理以生成文档。

Of course you may like to cache the result of an output formatting operation, and you may choose to store the cache in a database, too. That's fine of course. But concerning the raw payload data, I would always go for the above.

当然,您可能希望缓存输出格式化操作的结果,也可能选择将缓存存储在数据库中。当然这很好。但是对于原始的有效载荷数据,我总是使用上面的方法。

#3


2  

That depends on the use of the HTML in the database. If it's data that you only ever access as a blob (meaning you never/rarely query the contents of the HTML), then I think it can be a good idea in some cases. Then the question is essentially the same as "Should I store files in xyz format in my database?" And the answer to questions like that depends on several things:

这取决于在数据库中使用HTML。如果您只访问作为blob的数据(意味着您从不/很少查询HTML的内容),那么在某些情况下,我认为这是一个好主意。那么问题本质上与“我应该在我的数据库中存储xyz格式的文件吗?”这类问题的答案取决于以下几点:

  1. How large are the files? Would storing them on the filesystem, with just their filename/path in the DB be more efficient?
  2. 文件有多大?将它们存储在文件系统上,只使用它们在DB中的文件名/路径更有效?
  3. Do you need to replicate the data to other servers? If so, then storing raw files in the DB may be easier than on the FS, if you already have DB-sync infrastructure in place.
  4. 是否需要将数据复制到其他服务器?如果是这样,那么在DB中存储原始文件可能比在FS上更容易,如果您已经有DB-sync基础结构的话。
  5. What are your query uses like? Are they friendlier to a DB or a file system storage?
  6. 查询的用途是什么?它们对DB或文件系统存储更友好吗?

Now, if you're talking about storing HTML data that you frequently have to query, that changes the game entirely.

现在,如果要存储经常要查询的HTML数据,这将彻底改变游戏。

Any database normalization nazi would tell you never to do it. But there might be cases when it's useful. For instance, if you're using some sort of full-text searching engine, you may want that in a database--or in whatever form the full-text search engine uses.

任何数据库归一化的纳粹都会告诉你永远不要这样做。但也有可能是有用的。例如,如果您正在使用某种类型的全文搜索引擎,您可能希望在数据库中——或者在任何形式的全文搜索引擎中使用。

#1


3  

HTML is static, and querying the data from a database uses database resources; database resources are typically among the more restricted on moderate to heavy use systems, therefore it makes sense to not store HTML in the database, but to place it on the filesystem, where it can be retrieved without using critical resources.

HTML是静态的,从数据库查询数据使用数据库资源;数据库资源通常受到中度到重度使用系统的限制,因此不将HTML存储在数据库中,而是将它放在文件系统中,在那里可以不使用关键资源检索它。

#2


2  

In the broadest sense, HTML is a document markup language and serves to structure data into a document. The database on the other hand should contain raw data organized along its logical relations. Documents use formatting and may present data redundantly, but the true, underlying data is always fixed. Thus you should store the most immediate, raw form of data that you possibly can, and retrieve it in meaningful ways using both the query language itself to create suitable views for your purposes, and other, output-specific data processing to generate documents.

从最广泛的意义上说,HTML是一种文档标记语言,用于将数据结构化为文档。另一方面,数据库应该包含按照其逻辑关系组织的原始数据。文档使用格式,并可能冗余地显示数据,但真实的底层数据总是固定的。因此,您应该尽可能地存储最直接、最原始的数据形式,并使用查询语言本身以有意义的方式检索数据,以便为您的目的创建适当的视图,以及其他特定于输出的数据处理以生成文档。

Of course you may like to cache the result of an output formatting operation, and you may choose to store the cache in a database, too. That's fine of course. But concerning the raw payload data, I would always go for the above.

当然,您可能希望缓存输出格式化操作的结果,也可能选择将缓存存储在数据库中。当然这很好。但是对于原始的有效载荷数据,我总是使用上面的方法。

#3


2  

That depends on the use of the HTML in the database. If it's data that you only ever access as a blob (meaning you never/rarely query the contents of the HTML), then I think it can be a good idea in some cases. Then the question is essentially the same as "Should I store files in xyz format in my database?" And the answer to questions like that depends on several things:

这取决于在数据库中使用HTML。如果您只访问作为blob的数据(意味着您从不/很少查询HTML的内容),那么在某些情况下,我认为这是一个好主意。那么问题本质上与“我应该在我的数据库中存储xyz格式的文件吗?”这类问题的答案取决于以下几点:

  1. How large are the files? Would storing them on the filesystem, with just their filename/path in the DB be more efficient?
  2. 文件有多大?将它们存储在文件系统上,只使用它们在DB中的文件名/路径更有效?
  3. Do you need to replicate the data to other servers? If so, then storing raw files in the DB may be easier than on the FS, if you already have DB-sync infrastructure in place.
  4. 是否需要将数据复制到其他服务器?如果是这样,那么在DB中存储原始文件可能比在FS上更容易,如果您已经有DB-sync基础结构的话。
  5. What are your query uses like? Are they friendlier to a DB or a file system storage?
  6. 查询的用途是什么?它们对DB或文件系统存储更友好吗?

Now, if you're talking about storing HTML data that you frequently have to query, that changes the game entirely.

现在,如果要存储经常要查询的HTML数据,这将彻底改变游戏。

Any database normalization nazi would tell you never to do it. But there might be cases when it's useful. For instance, if you're using some sort of full-text searching engine, you may want that in a database--or in whatever form the full-text search engine uses.

任何数据库归一化的纳粹都会告诉你永远不要这样做。但也有可能是有用的。例如,如果您正在使用某种类型的全文搜索引擎,您可能希望在数据库中——或者在任何形式的全文搜索引擎中使用。