Xml或Sqlite,何时为数据库删除Xml? [英] Xml or Sqlite, When to drop Xml for a Database?

查看:109
本文介绍了Xml或Sqlite,何时为数据库删除Xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢Xml保存数据,但什么时候sqlite /数据库成为更好的选择?例如,当xml有超过 x 个项目或大于 y MB?



rss阅读器,我相信我错误的选择使用xml通过sqlite数据库来存储所有饲料项目的缓存。有一些饲料,一个月后有一个〜1MB的xml文件,另一个有700多个项目,而大多数只有〜30个项目,并且在一个几个月后大小〜50kb。



我目前没有计划实施上限,因为我希望能够搜索所有内容。



所以,我的问题是:


  1. sqlite /数据库的开销是什么时候比使用xml更合理?

  2. 很少的大型xml文件对于数据库来说足够了,但有很多小,但即使是小的也会随着时间增长? (a long long time)

p>

每次在GUI中选择一个Feed时,我都会重新加载该Feed xml文件中的所有项目。



需要修改读/未读状态,当我循环遍历xml中的所有节点找到该项,然后将其设置为读/未读时,这看起来真的很黑。

解决方案

我基本上同意 Mitchel ,这可以高度具体取决于你将使用XML / sqlite做什么。对你的情况(缓存),在我看来,使用sqlite(或其他嵌入式dbs)更有意义。



首先我不认为sqlite将需要比XML更多的开销。我的意思是开发时间开销和运行时开销。只有问题是你有依赖sqlite库。但是因为你需要一些XML库,所以没关系(我认为项目是C / C ++)。



sqlite over xml的优点:




  • 在一个文件中的所有内容,

  • 性能损失低于XML

  • 您可以将Feed元数据与缓存本身(其他表格)分开,但可以以同样的方式访问

  • SQL可能更容易



sqlite的缺点: b


  • 对于访问同一数据库的多个进程(可能不是这种情况)可能会有问题,

  • 您应该至少知道基本SQL。除非在缓存中有成千上万个项目,否则我不认为你需要对其进行优化。

  • 也许在某种程度上,从安全角度看,注射)。另一方面,你不是编写web应用程序,所以这不应该发生。





总结一下您的问题的答案:


  1. 你不会知道,除非你用两个后端测试你的具体应用程序。否则它总是只是一个猜测。对这两个缓存的基本支持不应该是代码的问题。


  2. 由于组织XML文件的方式,sqlite搜索应该总是更快(除非有些情况下无关紧要因为它的速度很快)。加速搜索XML将需要索引数据库,在你的情况下,这意味着缓存缓存,不是一个特别好的主意。但是使用sqlite,你可以将索引作为数据库的一部分。



I really like Xml for saving data, but when does sqlite/database become the better option? eg, when the xml has more than x items or is greater than y MB?

I am coding an rss reader and I believe I made the wrong choice in using xml over a sqlite database to store a cache of all the feeds items. There are some feeds which have an xml file of ~1mb after a month, another has over 700 items, while most only have ~30 items and are ~50kb in size after a several months.

I currently have no plans to implement a cap because I like to be able to search through everything.

So, my questions are:

  1. When is the overhead of sqlite/databases justified over using xml?
  2. Are the few large xml files justification enough for the database when there are a lot of small ones, though even the small ones will grow over time? (a long long time)

updated (more info)

Every time a feed is selected in the GUI I reload all the items from that feeds xml file.

I also need to modify the read/unread status which seems really hacky when I loop through all nodes in the xml to find the item and then set it to read/unread.

解决方案

I basically agree with Mitchel, that this can be highly specific depending on what are you gonna do with XML/sqlite. For your case (cache), it seems to me that using sqlite (or other embedded dbs) makes more sense.

First I don't really think that sqlite will need more overhead than XML. And I mean both development time overhead and runtime overhead. Only problem is that you have a dependance on sqlite library. But since you would need some library for XML anyway it doesn't matter (I assume project is in C/C++).

Advantages of sqlite over xml:

  • everything in one file,
  • performance loss is lower than XML as cache gets bigger,
  • you can keep feed metadata separate from cache itself (other table), but accessible in the same way,
  • SQL is probably easier to work with than XPath for most people.

Disadvantages of sqlite:

  • can be problematic with multiple processes accessing same database (probably not your case),
  • you should know at least basic SQL. Unless there will be hundreds of thousands of items in cache, I don't think you will need to optimize it much,
  • maybe in some way it can be more dangerous from security standpoint (SQL injection). On the other hand, you are not coding web app, so this should not happen.

Other things are on par for both solutions probably.

To sum it up, answers to your questions respectively:

  1. You will not know, unless you test your specific application with both backends. Otherwise it's always just a guess. Basic support for both caches should not be a problem to code. Then benchmark and compare.

  2. Because of the way XML files are organized, sqlite searches should always be faster (barring some corner cases where it doesn't matter anyway because it's blazingly fast). Speeding up searches in XML would require index database anyway, in your case that would mean having cache for cache, not a particularly good idea. But with sqlite you can have indexing as part of database.

这篇关于Xml或Sqlite,何时为数据库删除Xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆