Bug #99073 The new mysql_fetch_row_nonblocking does not increment the row count
Submitted: 25 Mar 2020 21:27 Modified: 30 Mar 2020 18:37
Reporter: Jay Edgar Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:8.0.19 OS:Any
Assigned to: CPU Architecture:Any

[25 Mar 2020 21:27] Jay Edgar
Description:
When using mysql_use_result, the mysql_fetch_row_nonblocking() function does not increment the number of rows, so that after all the rows are fetched, mysql_num_rows() will return the incorrect number of rows.

How to repeat:
Make the following modifications to the client test.  They change the code to use mysql_use_result instead of mysql_store_result_nonblocking and then check mysql_num_rows() after the rows are fetched.  Without the fix the test will fail.

diff --git a/testclients/mysql_client_test.cc b/testclients/mysql_client_test.cc
index 2c45d41da89..d272c5c4cdc 100644
--- a/testclients/mysql_client_test.cc
+++ b/testclients/mysql_client_test.cc
@@ -20225,18 +20225,8 @@ static void test_wl11381() {
   } else {
     fprintf(stdout, "\n mysql_real_query_nonblocking() passed");
   }
-  status = mysql_store_result_nonblocking(mysql_local, &result);
-  /* do some other task */
-  perform_arithmatic();
-  while (status == NET_ASYNC_NOT_READY) {
-    status = mysql_store_result_nonblocking(mysql_local, &result);
-  }
-  if (!result) {
-    fprintf(stdout, "\n mysql_store_result_nonblocking() fetched 0 records");
-    exit(1);
-  } else {
-    fprintf(stdout, "\n mysql_store_result_nonblocking() passed");
-  }
+
+  result = mysql_use_result(mysql_local);

   row = mysql_fetch_row(result);
   DIE_UNLESS(strcmp(row[0], "10") == 0);
@@ -20263,6 +20253,7 @@ static void test_wl11381() {
     fprintf(stdout, "\n mysql_fetch_row_nonblocking() passed");
   }

+  DIE_UNLESS(mysql_num_rows(result) == 3);
   while ((status = mysql_free_result_nonblocking(result)) != NET_ASYNC_COMPLETE)
     ;
   fprintf(stdout, "\n mysql_free_result_nonblocking() passed");

Suggested fix:
diff --git a/sql-common/client.cc b/sql-common/client.cc
index fd36e9950cf..60ca2e3340b 100644
--- a/sql-common/client.cc
+++ b/sql-common/client.cc
@@ -7534,6 +7534,7 @@ net_async_status STDCALL mysql_fetch_row_nonblocking(MYSQL_RES *res,
         }

         if (!ret) {
+          res->row_count++;
           *row = res->current_row = res->row;
           goto end;
         }
[26 Mar 2020 7:18] MySQL Verification Team
Hello Jay Edgar,

Thank you for the report and feedback.

Thanks,
Umesh
[30 Mar 2020 18:37] Paul DuBois
Posted by developer:
 
Fixed in 8.0.21.

For result sets processed using mysql_use_result(),
mysql_fetch_row_nonblocking() did not increment the number of rows,
so that after all the rows were fetched, mysql_num_rows() returned an
incorrect number of rows.