FETCH的速度问题(Unix)

表中有10万左右的记录,表的字段有15个左右。
我用下列方法读取记录。
EXEC SQL DECLARE a_cur CURSOR FOR select a1,a2 from a where a.c1='ccc' and a.c2='ddd';
EXEC SQL OPEN a_cur;
EXEC SQL FETCH a_cur into :cha1,:cha2;
while(sqlca.sqlcode==0)
{
printf("a1=%s,a2=%s\n",cha1,cha2);
EXEC SQL FETCH a_cur into :cha1,:cha2;
printf("code=%d\n",sqlca.sqlcode);
}
EXEC SQL CLOSE a_cur;
OPEN后的FETCH速度很快,但在while循环中的FETCH地方停顿时间很长。大约有40秒左右。查询结果只有一条记录,循环中的FETCH实际上已经走到记录集的末尾了。返回的sqlcode是100。
请问各位大侠,这是什么原因造成的?有没有优化的方法?
---------------------------------------------------------------

这样试试看exec sql DECLARE a_cur CURSOR FOR select a1,a2 from a where a.c1='ccc' and a.c2='ddd' for read only

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus