[MDEV-23519] Protocol packet - "Original Name" info is showing alias name, instead of original name of the column Created: 2020-08-20  Updated: 2023-03-10  Resolved: 2021-09-16

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 10.4.13
Fix Version/s: 10.4.22, 10.5.13, 10.6.5

Type: Bug Priority: Critical
Reporter: suresh ramagiri Assignee: Michael Widenius
Resolution: Fixed Votes: 3
Labels: None

Attachments: Text File 0001-Previous-fix-had-bigger-splash-zone.-So-we-have-redu.patch     PNG File mariadb-10.2-protocol-packet-info.png     PNG File mariadb-10.4-protocol-packet-info.png    
Issue Links:
PartOf
includes MDEV-23341 shadowed field wrong column name meta... Closed
Relates

 Description   

One of the customers, noted that the MySQL protocol packet captured at client 10.4 is having "Original name" parameter using the alias name instead of the original column name which you can see 10.2 is showing up properly.



 Comments   
Comment by Oleksandr Byelkin [ 2021-03-10 ]

The patch is OK (even part of it is already in the sources) biut it lack test case. Without the test case we can not be sure that 1) it really fix the problem 2) noone breack it again in the future.

Comment by Oleksandr Byelkin [ 2021-03-10 ]

Could a test case be added in our standard test suite (mysql-test/) with

--enable_metadata
SELECT...
--disable_metadata

or client test in tests/mysql_client_test.c or just to list here the sequence of SQLs (CREATE TABLE, INSERT, SELECT) to see the problem and I will make the test case.

Comment by Diego Dupin [ 2021-06-08 ]

this would seems a dupplicate of https://jira.mariadb.org/browse/MDEV-23341

Comment by Michael Widenius [ 2021-09-02 ]

Could someone please answer the following questions (which is not clear in the description above and should really be part of the description):

  • Is this a bug in a connector or the server?
  • Why did MariaDB 10.2 give correct names?
  • What change in MariaDB 10.3 or 10.4 caused this to change ?
  • Why cannot we revert the change?
Comment by Diego Dupin [ 2021-09-02 ]

Just to answer the first item, this is a server issue (see duplicated issue MDEV-23341)

Comment by Oleksandr Byelkin [ 2021-09-02 ]

I recall that it is user fix and all should be checked, so I took the test case and compiled it with current 10.4, it passes.

in other words it passes without the fix.

Comment by Oleksandr Byelkin [ 2021-09-02 ]

I checked also 10.4.13 (built from tag) the same - it pass. (I am still trying to fix test suite)

Comment by Oleksandr Byelkin [ 2021-09-02 ]

It shoud be prepered statements protocol I think

Comment by Oleksandr Byelkin [ 2021-09-02 ]

I also checked prepare/execute with changed test from the fix, it pass on unfixed 10.4:

/**
 MDEV-23519: Protocol packet - "Original Name" info is showing alias name, instead of original name of the column
 */
static void test_mdev23519()
{
  int rc;
  MYSQL_RES *result;
  MYSQL_STMT *stmt;
  MYSQL *my= mysql_client_init(NULL);
 
  DBUG_ENTER("test_mdev23519");
  myheader("test_mdev23519");
 
  if (!mysql_real_connect(my, opt_host, opt_user,
                          opt_password, current_db, opt_port,
                          opt_unix_socket, CLIENT_MULTI_RESULTS))
    DIE("mysql_real_connect failed");
 
  rc= mysql_query(mysql, "create table fears("\
                  "`FearID` int(11) DEFAULT NULL,"\
                  "`Fear` varchar(50) DEFAULT NULL"\
                  ")");
 
  DIE_UNLESS(rc == 0);
  DIE_IF(mysql_errno(mysql));
 
  stmt= mysql_simple_prepare(mysql, "select distinct a.Fear as Fears_Fear from fears a");
  check_stmt(stmt);
  result= mysql_stmt_result_metadata(stmt);
  mytest(result);
  mct_log("XXX Orig_name: '%s' name: '%s'", result->fields->org_name,
          result->fields->name);
  DIE_UNLESS(strcmp(result->fields->org_name, "Fear") == 0 && strcmp(result->fields->name, "Fears_Fear") == 0);
  rc= mysql_stmt_execute(stmt);
  check_execute(stmt, rc);
 
  mytest(result);
  mct_log("XXX Orig_name: '%s' name: '%s'", result->fields->org_name,
          result->fields->name);
  DIE_UNLESS(strcmp(result->fields->org_name, "Fear") == 0 && strcmp(result->fields->name, "Fears_Fear") == 0);
 
  mysql_free_result(result);
  mysql_stmt_close(stmt);
  mysql_close(my);
 
  DBUG_VOID_RETURN;
}

Comment by Oleksandr Byelkin [ 2021-09-02 ]

So it needs a way to repeat the bugs (as well as MDEV-23341)

I checked test case from the fix, also changed for using PS test case, both pass without fixes on 10.4.

Comment by Michael Widenius [ 2021-09-13 ]

The bug appeared in 10.4. Here is a test case:

--echo #
--echo # MDEV-23519
--echo #
create or replace table t1 (a int);
create or replace table t2 (a int);
insert into t1 values(1),(2);
insert into t2 values(1),(2);
--enable_metadata
select t1.a as a1 from t1 as t1,t2 order by t2.a;
--disable-metadata
drop table t1,t2;

In 10.3 the meta data is:
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 a a1 3 11 1 Y 32768 0 63

In 10.4 and 10.5 it is:
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
def test t1 t1 a1 a1 3 11 1 Y 32768 0 63

Difference "a a1" compared to "a1 a1"

Now trying to find what causes it

Comment by Michael Widenius [ 2021-09-13 ]

The reason for the bug was a refactoring of temporary table field creation that was done in 10.4
A mistake was done when copying the column name when creating internal temporary tables.
For internal temporary tables we should use the original field name, not the item name (= alias)

Generated at Thu Feb 08 09:23:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.