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

查看:20
本文介绍了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) etc) 或 BLOB (varbinary(max)) 字段.在默认用法中,它会在让您靠近它之前缓冲整行数据 - 这可能意味着它必须为任何 BLOB/CLOB 字段分配一个大缓冲区.当使用顺序模式时,它不缓冲行;您可以将常规 API 用于小字段(只要您以正确的顺序访问它们),但对于 CLOB/BLOB 字段,您可以使用基于块的 API (GetBytesGetChars) 依次访问数据的一部分.例如,通过这样做,您可以仅使用 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天全站免登陆