CommandBehavior.SequentialAccess是否有任何性能提升? [英] Is there any performance gain from CommandBehavior.SequentialAccess?

查看:86
本文介绍了CommandBehavior.SequentialAccess是否有任何性能提升?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到我总是按照索引返回它们的顺序来读取字段(使用常量)。因此,据我了解,我的代码已经与CommandBehavior.SequentialAccess兼容。

I realized I always read my fields in the order they are returned by index (using constants). So my code is already compatible with CommandBehavior.SequentialAccess as far as i understand.

如果我打开它会不会有任何好处? DataReader已经是仅转发状态,仅只读才是真正的性能增益?

Would there be any benefits if i turn it on? DataReader is already forward only, read only which is the real performance gain right?

推荐答案

主要用途是读取非常大的CLOB( nvarchar(max)等)或BLOB( varbinary(max))字段。在默认用法中,它会先缓冲整个数据行,然后再靠近它-这可能意味着它必须为任何BLOB / CLOB字段分配一个较大的缓冲区。使用顺序模式时,它不缓冲行;您可以对小字段使用常规API(只要以正确的顺序访问它们即可),但是对于CLOB / BLOB字段,可以使用基于块的API( GetBytes GetChars )依次访问部分数据。这样,您可以例如仅使用1k或4k缓冲区处理40 MB的图像。

The main usage of this is when you are reading very large CLOB (nvarchar(max) etc) or BLOB (varbinary(max)) fields. In the default usage, it buffers the entire row of data before letting you near it - which could mean it has to allocate a large buffer for any BLOB / CLOB fields. When using sequential mode, it does not buffer the row; you can use the regular API for small fields (as long as you access them in the correct order), but for the CLOB / BLOB fields you can use the chunk-based APIs (GetBytes and GetChars) to access fractions of the data in turn. By doing this you could, for example, process a 40 MB image using only a 1k or 4k buffer.

MSDN也这么说

为DataReader提供一种处理包含具有大二进制值的列的行的方法。 SequentialAccess无需加载整个行,而是使DataReader可以将数据作为流加载。然后,您可以使用GetBytes或GetChars方法指定一个字节位置来启动读取操作,并为返回的数据指定一个有限的缓冲区大小。

Provides a way for the DataReader to handle rows that contain columns with large binary values. Rather than loading the entire row, SequentialAccess enables the DataReader to load data as a stream. You can then use the GetBytes or GetChars method to specify a byte location to start the read operation, and a limited buffer size for the data being returned.

这篇关于CommandBehavior.SequentialAccess是否有任何性能提升?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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