Bug #99010 The mtr case --send command not use ps-protocol when run with --ps-protocol
Submitted: 20 Mar 2020 13:30 Modified: 6 Apr 2020 5:59
Reporter: Ze Yang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:Tools: MTR / mysql-test-run Severity:S7 (Test Cases)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[20 Mar 2020 13:30] Ze Yang
Description:
send_in_ps_mode.test

CREATE TABLE t(c1 int);
INSERT INTO t VALUES(1),(2);
SET DEBUG_SYNC='wait_in_query_cache_insert WAIT_FOR s1';
--send select * from t
--reap

then gdb attach server:

(gdb) f 13
#13 0x0000000001c4b750 in THD::send_statement_status (this=0x7f0cb01272d0) at /home/yangze.yz/dev/org_5715/sql/sql_class.cc:4987
4987	              server_status, da->last_statement_cond_count());

(gdb) p m_protocol->type()
$1 = Protocol::PROTOCOL_TEXT

The reason is in mysqltest.cc when command is Q_SEND or Q_SEND_VAL, the run query just use 
QUERY_SEND_FLAG but not q_send_flag. And the run_query only when flag with QUERY_SEND_FLAG and QUERY_REAP_FLAG, will call run_query_stmt to run ps-protocol.

client/mysqltest.cc

int main(int argc, char **argv)
{
...
      case Q_SEND:
      case Q_SEND_EVAL:
        if (!*command->first_argument)
        {
          /*
            This is a send without arguments, it indicates that _next_ query
            should be send only
          */
          q_send_flag= 1;
          break;
        }

        /* Remove "send" if this is first iteration */
  if (command->query == command->query_buf)
    command->query= command->first_argument;

  /*
    run_query() can execute a query partially, depending on the flags.
    QUERY_SEND_FLAG flag without QUERY_REAP_FLAG tells it to just send
          the query and read the result some time later when reap instruction
    is given on this connection.
        */
  run_query(cur_con, command, QUERY_SEND_FLAG);
  command_executed++;
        command->last_argument= command->end;
...
}

run_query()
{
...
  my_bool complete_query= ((flags & QUERY_SEND_FLAG) &&
                           (flags & QUERY_REAP_FLAG));
...
  if (ps_protocol_enabled &&
      complete_query &&
      match_re(&ps_re, query))
    run_query_stmt(mysql, command, query, query_len, ds, &ds_warnings);
...
}

How to repeat:
send_in_ps_mode.test

CREATE TABLE t(c1 int);
INSERT INTO t VALUES(1),(2);
SET DEBUG_SYNC='wait_in_query_cache_insert WAIT_FOR s1';
--send select * from t
--reap

then gdb attach server:

(gdb) f 13
#13 0x0000000001c4b750 in THD::send_statement_status (this=0x7f0cb01272d0) at /home/yangze.yz/dev/org_5715/sql/sql_class.cc:4987
4987	              server_status, da->last_statement_cond_count());

(gdb) p m_protocol->type()
$1 = Protocol::PROTOCOL_TEXT

Suggested fix:
May be should call run_query(cur_con, command, q_send_flag);
[23 Mar 2020 13:47] MySQL Verification Team
Hi Mr. Yang,

Thank you for your bug report.

However, your report is not clear enough to us, so we do need some clarifications.

First of all, We do not see what version and release are you using for this report.

Second, is this reproducible with a mysqltest.cc program or with one of the mtr programs. In that respect, I do not see anywhere in our test system a test with a name send_in_ps_mode.test, nor .result. 

Next, how should we test your report. With mysqltest or with mtr ????

In the first case, we need a patch that needs to be applied to mysqltest.cc and in second case with also need .result file.
[6 Apr 2020 5:59] MySQL Verification Team
Thank you for the report and feedback.