mysql native client_SQL Native Client 10性能不佳(由于服务器端游标)

我对这个问题进行了修改,发现了这两个链接:

在第一个链接中,它描述了仅当更改默认选项时,Native Client 10才使用服务器端游标:

When these options are set to their defaults at the time an SQL statement is executed,the SQL Server Native Client ODBC driver does not use a server cursor to implement the result set; instead,it uses a default result set.

Link 2是一个博客,它是一个SQL Dev博客,它说:

It turned out that the developer did not explicitly ask for a server cursor. But when he did block fetches,as a side effect,the SQL Server ODBC driver asked for a server cursor…that is unexpected!

是的,当然这是出乎意料的……

How can I do block fetches over a Default Result Set (fire hose cursor) instead of a server cursor?

现在,解决方案的实施是这样的:

代替:

// crs is a CRecordSet

crs.Open(CRecordset::snapshot,L"SELECT something...");

做这个:

// crs is a CRecordSet

crs.Open(CRecordset::forwardOnly,L"SELECT something...");

这个简单的更改不会触发创建服务器端游标,并模仿MySQL驱动程序的行为.

缺点是现在您无法通过(Microsoft推荐)方式检索行计数:

while(crs.MoveNext()) nCount++;

无论如何,这是一个坏主意.此外,:: SQLGetRowCount()将不再一直有效.

我已经解决了这个问题(这应该适用于任何ANSI兼容的SQL源):

//strQuery is the random query passed to CountRows()

std::wstringstream ssQuery;

ssQuery << L"SELECT COUNT(*) AS Count FROM (" << strQuery << L") AS t";

CRecordset crs(&m_Database);

crs.Open(CRecordset::forwardOnly,ssQuery.str().c_str());

// Now retrieve the only "Count" field from the recordset.

我希望将来可以帮助别人.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值