简体   繁体   English

Sql Server XML列替代Document DB?

[英]Sql Server XML columns substitute for Document DB?

Is it possible to use Sql Server XML columns as a substitute for a real Document DB (such as Couch or Mongo) ? 是否可以使用Sql Server XML列替代真正的文档数据库(如Couch或Mongo)?

If I were to create a table with a guid PK Id and an XML column for the document. 如果我要为文档创建一个带有guid PK Id和XML列的表。 What would be the main problems compared to using a document DB? 与使用文档数据库相比,主要问题是什么?

Sql Server supports indexing over XML columns so querying should not be completely horrible? Sql Server支持对XML列进行索引,因此查询不应该是完全可怕的吗?

You've got several questions in here: 你在这里有几个问题:

Is it possible to use Sql Server XML columns as a substitute for a real Document DB (such as Couch or Mongo) ? 是否可以使用Sql Server XML列替代真正的文档数据库(如Couch或Mongo)? Yes, you can use it as a substitute, but no, you probably wouldn't be satisfied with performance if you're exclusively storing XML and not leveraging any of SQL Server's relational tools. 是的,您可以将它用作替代品,但是,如果您只是存储XML而不是利用任何SQL Server的关系工具,那么您可能不会对性能感到满意。

If I were to create a table with a guid PK Id and an XML column for the document. 如果我要为文档创建一个带有guid PK Id和XML列的表。 What would be the main problems compared to using a document DB? 与使用文档数据库相比,主要问题是什么? In a nutshell, scaling out. 简而言之,扩展。 SQL Server doesn't scale this kind of thing out well. SQL Server不能很好地扩展这种东西。 You can do it with replication, but it's painful to manage relative to a "real" Document DB. 您可以通过复制来完成,但相对于“真正的”文档数据库来管理是很痛苦的。

Sql Server supports indexing over XML columns so querying should not be completely horrible? Sql Server支持对XML列进行索引,因此查询不应该是完全可怕的吗? The problem is that SQL Server's XML indexes can take several times the storage space of the original data. 问题是SQL Server的XML索引可能需要几倍于原始数据的存储空间。 These indexes can't be maintained online (as in defrags), so you end up with locking issues during maintenance windows. 这些索引无法在线维护(如defrags),因此在维护窗口期间最终会出现锁定问题。

I'm doing some experimenting with this on: http://rogeralsing.com/2011/03/02/linq-to-sqlxml-projections/ 我正在做一些实验: http//rogeralsing.com/2011/03/02/linq-to-sqlxml-projections/

Query speed is 'decent' , it's nothing I'd use for scaling. 查询速度“体面”,我没有用于缩放。 But the joy of schema free storage running on standard infrastructure is quite nice. 但是,在标准基础架构上运行的无架构存储的乐趣非常好。

Yes, you can. 是的你可以。 Storing a document inside a SqlServer XML column will work and if you use standard XML serialization that will leave you with a decent ACID complant key/value store. 将文档存储在SqlServer XML列中将起作用,如果使用标准XML序列化,将为您提供一个合适的ACID complant键/值存储。 Also, it will allow you to do queries on it with relative ease and you can join the results to data that you store in a more relational way. 此外,它允许您相对轻松地对其进行查询,并且您可以将结果加入到以更关系方式存储的数据中。 We do so, it works. 我们这样做,它的工作原理。 If you store content in XML fields, storage demands are a lot lower than using NTEXT and querying it will be more flexible and faster. 如果将内容存储在XML字段中,则存储需求远低于使用NTEXT,并且查询它将更灵活,更快速。

What SqlServer will not get you (comparing to mongo) is the seamless failover of replica-sets an the autosharding of mongo. 什么SqlServer不会得到你(与mongo相比)是副本集的无缝故障转移和mongo的自动调整。 Also, atomic operations like incrementing a specific property deep inside a document is hard (though not impossible with the XQuery update function). 此外,诸如在文档内部增加特定属性的原子操作很难(尽管XQuery更新功能并非不可能)。 Updates tend to be faster on most NoSql databases, because they are more relaxed on the "data is only safe on disk" principle. 在大多数NoSql数据库上更新往往更快,因为它们在“数据仅在磁盘上是安全的”原则上更加宽松。

Yes, it is possible. 对的,这是可能的。 As to whether it's a good idea, this is just my 2 cents... 至于这是不是一个好主意,这只是我的2美分......

Before the XML datatype came along I worked on a system storing XML in an NTEXT column - that wasn't pleasant, and to get any real use out of the data meant shredding some of that data out into relational form. 在XML数据类型出现之前,我研究了一个在NTEXT列中存储XML的系统 - 这并不令人愉快,并且从数据中获得任何实际用途意味着将一些数据分解为关系形式。

OK, the XML datatype now makes it easier to query an XML blob and to extract certain values/index them. 好的,XML数据类型现在可以更轻松地查询XML blob并提取某些值/索引它们。 But personally, in general, I wouldn't. 但就个人而言,一般而言,我不会。 I'm not saying never use XML as there are scenarios for that - rather if that's all your planning on doing then I'd be thinking "is this the right tool for the job". 我并不是说永远不会使用XML,因为有这样的情况 - 相反,如果这是你的所有计划,那么我会想“这是适合这项工作的工具”。 Using a RDBMS as a document database makes me feel a bit uneasy. 使用RDBMS作为文档数据库让我感到有点不安。 Whereas something like MongoDB has been built from the ground up as a document database. 而像MongoDB这样的东西已经从头开始构建为文档数据库。

In all honesty, I haven't done any performance testing on storing data as XML so I can't give you an indication of what performance would be like. 老实说,我没有对将数据存储为XML进行任何性能测试,因此我无法向您说明性能会是什么样的。 Would be interested to know how this performs at scale. 有兴趣知道这是如何大规模表现的。

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

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