是的DataSet比DataReader的速度较慢,由于...? [英] Is DataSet slower than DataReader due to...?

查看:386
本文介绍了是的DataSet比DataReader的速度较慢,由于...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据集可以比的DataReader 慢10+次从数据库中检索数据。我想这是由于数据集的开销不必处理的关系等,但就是数据集之间的速度差的DataReader ,由于数据集不必从数据库中检索更多的数据(约关系的信息......),或由于应用程序不必做更多的处理,或两者兼而有之?

DataSets can be 10+ times slower than DataReader at retrieving data from DB. I assume this is due to overhead of DataSets having to deal with relations etc. But is the speed difference between DataSets and DataReader due to DataSets having to retrieve more data (information about relations ...) from DB, or due to application having to do more processing, or both?

我假设 DataAdapter的使用的DataReader 引擎盖下的,因此对命令的应用程序的数量需要执行,以检索100行, DataAdapter的等于或大于命令的应用程序需要执行的,如果这100行是通过的DataReader 。请问的DataReader 在一个时间获取一行在当时还是一个字段(特定行的)?

I assume DataAdapter uses DataReader under the hood and thus the number of commands application needs to execute in order to retrieve 100 rows with DataAdapter is equal to or greater than number of commands app needs to execute if these 100 rows are retrieved directly by DataReader. Does DataReader retrieve one row at the time or one field (of a particular row) at a time?

推荐答案

有一些不同类型的开销,可以使用DataSet在一个DataReader时出现的:

There are some different types of overhead that can occur when using a DataSet over a DataReader:

一个DatSet包含DataTable对象,其中包含DataRow对象,包含的数据。有一个小的开销创建的所有对象。每个DataRow的把所有它的值对象,因此任何类型的值被装箱它增加了一些开销为每个字段。

A DatSet contains DataTable objects, which contains DataRow object, that contain the data. There is a small overhead creating all the objects. Each DataRow treats all it's values as objects, so any value types are boxed which adds a bit of overhead for each field.

当您使用DataAdapter来填充DataSet,很容易获得大量的数据,你不会使用。如果没有指定你想要什么字段,你会得到所有的领域,即使你不会使用它们。如果不过滤查询,你从表中的所有行。即使你对数据表数据视图后过滤它们,你还从数据库中获取它们。使用DataReader你更接近查询,获取数据,所以连接到你的结果得到的是更明显。

When you use a DataAdapter to populate a DataSet, it's easy to get a lot of data that you won't use. If you don't specify what fields you want, you get all the fields even if you won't use them all. If you don't filter the query, you get all the rows from the table. Even if you filter them later with a DataView on the DataTable, you still have fetched them from the database. With a DataReader you are closer to query that gets the data, so the connection to what you get in the result is more obvious.

如果您获取数据到DataSet中,并使用关系数DataTable对象,让数据集相结合的数据,使数据集做,你可以有让数据库做的,这是更多的钱最优化的工作。

If you fetch data into several DataTable objects in a DataSet and use relations to let the DataSet combine the data, you make the DataSet do work that you could have let the database do, which is more optimised for it.

如果您使用DataSet好,开销并不坏,而%,比30 1000%。

If you use a DataSet well, the overhead is not that bad, rather 30% than 1000%.

您是正确的假设一个DataAdapter使用DataReader的。如果您是如何使用DataAdapter你小心,因为如果你使用DataReader自己的数据库操作本身是相同的。

You are correct to assume that a DataAdapter uses a DataReader. If you are careful how you use the DataAdapter, the database operations itself is the same as if you use the DataReader yourself.

一个DataReader将获取的记录从底层的数据库驱动程序,这反过来将获取完整的记录缓冲区从数据库中时间的时间。如果记录是非常大的只有一个可能时间放在缓冲区,但通常都在几十缓冲记录甚至上百个,如果他们是非常小的。

A DataReader will fetch a record at a time from the underlying database driver, which in turn will fetch a buffer full of records at a time from the database. If the records are very large only one at a time might fit in the buffer, but usually there are tens of records in the buffer or even hundreds if they are really small.

这篇关于是的DataSet比DataReader的速度较慢,由于...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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