【问题标题】:Internaly, how does Postgre store XML data?在内部,Postgres 如何存储 XML 数据?
【发布时间】:2017-06-20 23:54:37
【问题描述】:

当 Oracle 将 XML 存储为二进制数据时,它的存储是不带 XML 标记的。 正如我们在这里看到的:Oracle Patent

这种机制允许 Oracle 在存储其 XM​​L 数据时消耗更少的内存。

我想知道 PostgreSQL 如何存储它的 XML 数据。 我找到了这个文档,它说内部 Postgre 将通过 UTF-8 将 XML 处理为字符串(如果它被配置为通过另一个标准处理数据,许多函数都不起作用):Postgre Documentation

我没有找到任何可以准确说明 Postgre 如何存储其二进制 XML 数据的信息... 由于它不通过其 DTD (Postgre Documentation) 验证 XML 输入数据,我认为它确实存储了所有文档的所有 XML 标签。

有没有人确切知道或有更准确的参考资料说明 Postgre 如何存储 XML 数据? - 如果它没有像 Oracle 那样的标签存储,或者所有文档的所有 XML 标签都被存储。

提前谢谢...

【问题讨论】:

  • 依靠已申请的专利来获取有关实际产品行为的信息是非常不明智的。专利通常是针对从未成为产品的想法提交的,或者,设计可能会在产品开发过程中被修改和改进,甚至被放弃。
  • 感谢您的观察,迈克尔!

标签: xml oracle postgresql storage


【解决方案1】:

存储为 UTF-8 字符串。

摘自出处:

    /*
     * Parse the data to check if it is well-formed XML data.  Assume that
     * xml_parse will throw ERROR if not.
     */
    doc = xml_parse(result, xmloption, true, encoding);
    xmlFreeDoc(doc);

    /* Now that we know what we're dealing with, convert to server encoding */
    newstr = pg_any_to_server(str, nbytes, encoding);

xml.c via github

基本上postgres检查xml字符串是否有效,然后相对原样存储。

从 pg_any_to_server :

/*
 * Convert any encoding to server encoding.
 *
 * See the notes about string conversion functions at the top of this file.
 *
 * Unlike the other string conversion functions, this will apply validation
 * even if encoding == DatabaseEncoding->encoding.  This is because this is
 * used to process data coming in from outside the database, and we never
 * want to just assume validity.
 */
char *
pg_any_to_server(const char *s, int len, int encoding)
{

mbutils.c via github

因此,它被格式化为 UTF-8 字符串,然后像任何字符串一样由 postgres 存储。

【讨论】:

  • 请注意,它通常会使用 TOAST 进行离线存储和压缩。
猜你喜欢
  • 2014-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多