请问mysql提供的C API中,mysql_use_reslut返回的结果集存储在mysql服务器了吗?如果是,存储在内存还是磁盘还是其他的地方了呢?请大家踊跃发言,在线等,谢谢~~~~~

解决方案 »

  1.   


    调用端的内存指的是mysql服务器的内存吗?但是我做实验测试了一下,返回一个大约64M的结果集,mysql内存只涨了几兆。这是为什么呢?
      

  2.   

    我说了是调用端,就是你执行API的地方
      

  3.   


    汗!大哥,去吧mysql手册看清楚,msyql_stroe_reslut才是返回到调用端的内存。
      

  4.   

    不用讨论,手册上写得很清楚。
    mysql_use_result() initiates a result set retrieval but does not actually read the result set into the client like mysql_store_result() does. Instead, each row must be retrieved individually by making calls to mysql_fetch_row(). This reads the result of a query directly from the server without storing it in a temporary table or local buffer, which is somewhat faster and uses much less memory than mysql_store_result(). The client allocates memory only for the current row and a communication buffer that may grow up to max_allowed_packet bytes. On the other hand, you shouldn't use mysql_use_result() if you are doing a lot of processing for each row on the client side, or if the output is sent to a screen on which the user may type a ^S (stop scroll). This ties up the server and prevent other threads from updating any tables from which the data is being fetched. When using mysql_use_result(), you must execute mysql_fetch_row() until a NULL value is returned, otherwise, the unfetched rows are returned as part of the result set for your next query. The C API gives the error Commands out of sync; you can't run this command now if you forget to do this! 
      

  5.   

    不好意思,现在明白你的意思了,你其实想知道和msyql_stroe_reslut的区别吧
    毫无疑问,他们最终都是把结果放到客户端内存的
    只不过mysql_use_reslut是通过mysql_fetch_row,把记录一条一条读过来的,消耗的内存较少。
      

  6.   


    手册上面只是说了客户端的情况,我现在想知道,在mysql_use_result()查询语句返回结果集时,整个结果集在mysql端做了什么?我做了一个测试,大致如下:
          线程1做查询:select * from tab;
          在mysql_use_result()返回结果集后, mysql_fetch_row之前,另外开一个线程2,对tab表进行更新:update tab set col1 = 'new' where col1 = 'old';更新后,表的数据变化了
          此时线程1执行 mysql_fetch_row,发现返回的结果是更新前的内容,即:col1 = 'old'
    实验表名,mysql_use_result()的整个结果集被缓存。我想问的是:此结果集缓存在哪了?是mysql内存吗?但是mysql服务器并没有增涨那么多的内存啊?
      

  7.   

    你的表类型是innodb? myisam?