1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-23519 Protocol packet - "Original Name" info is showing alias name,

instead of original name of the column

When doing refactoring of temporary table field creation 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).
This commit is contained in:
Monty
2021-09-13 18:51:40 +03:00
parent adaf0dde7f
commit 689b8d060a
4 changed files with 52 additions and 7 deletions

View File

@@ -3503,6 +3503,7 @@ print_field_types(MYSQL_RES *result)
while ((field = mysql_fetch_field(result))) while ((field = mysql_fetch_field(result)))
{ {
tee_fprintf(PAGER, "Field %3u: `%s`\n" tee_fprintf(PAGER, "Field %3u: `%s`\n"
"Org_field: `%s`\n"
"Catalog: `%s`\n" "Catalog: `%s`\n"
"Database: `%s`\n" "Database: `%s`\n"
"Table: `%s`\n" "Table: `%s`\n"
@@ -3514,8 +3515,8 @@ print_field_types(MYSQL_RES *result)
"Decimals: %u\n" "Decimals: %u\n"
"Flags: %s\n\n", "Flags: %s\n\n",
++i, ++i,
field->name, field->catalog, field->db, field->table, field->name, field->org_name, field->catalog, field->db,
field->org_table, fieldtype2str(field->type), field->table, field->org_table, fieldtype2str(field->type),
get_charset_name(field->charsetnr), field->charsetnr, get_charset_name(field->charsetnr), field->charsetnr,
field->length, field->max_length, field->decimals, field->length, field->max_length, field->decimals,
fieldflags2str(field->flags)); fieldflags2str(field->flags));

View File

@@ -218,3 +218,22 @@ DELETE ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1 WHERE 1=1' at line 1 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 't1 WHERE 1=1' at line 1
connection default; connection default;
disconnect c1; disconnect c1;
#
# MDEV-23519
#
create or replace table t1 (a int);
create or replace table t2 (b int);
insert into t1 values(1),(2);
insert into t2 values(1),(2);
select t1.a as a1 from t1 as t1,t2 order by t2.b,t1.a;
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
a1
1
2
1
2
drop table t1,t2;
#
# End of 10.4 tests
#

File diff suppressed because one or more lines are too long

View File

@@ -17972,7 +17972,14 @@ Field *Item::create_field_for_schema(THD *thd, TABLE *table)
/** /**
Create a temporary field for Item_field (or its descendant), Create a temporary field for Item_field (or its descendant),
either direct or referenced by an Item_ref. either direct or referenced by an Item_ref.
param->modify_item is set when we create a field for an internal temporary
table. In this case we have to ensure the new field name is identical to
the original field name as the field will info will be sent to the client.
In other cases, the field name is set from orig_item or name if org_item is
not set.
*/ */
Field * Field *
Item_field::create_tmp_field_from_item_field(TABLE *new_table, Item_field::create_tmp_field_from_item_field(TABLE *new_table,
Item_ref *orig_item, Item_ref *orig_item,
@@ -17980,6 +17987,10 @@ Item_field::create_tmp_field_from_item_field(TABLE *new_table,
{ {
DBUG_ASSERT(!is_result_field()); DBUG_ASSERT(!is_result_field());
Field *result; Field *result;
LEX_CSTRING *new_name= (orig_item ? &orig_item->name :
!param->modify_item() ? &name :
&field->field_name);
/* /*
If item have to be able to store NULLs but underlaid field can't do it, If item have to be able to store NULLs but underlaid field can't do it,
create_tmp_field_from_field() can't be used for tmp field creation. create_tmp_field_from_field() can't be used for tmp field creation.
@@ -17998,26 +18009,25 @@ Item_field::create_tmp_field_from_item_field(TABLE *new_table,
Record_addr rec(orig_item ? orig_item->maybe_null : maybe_null); Record_addr rec(orig_item ? orig_item->maybe_null : maybe_null);
const Type_handler *handler= type_handler()-> const Type_handler *handler= type_handler()->
type_handler_for_tmp_table(this); type_handler_for_tmp_table(this);
result= handler->make_and_init_table_field(orig_item ? &orig_item->name : &name, result= handler->make_and_init_table_field(new_name,
rec, *this, new_table); rec, *this, new_table);
} }
else if (param->table_cant_handle_bit_fields() && else if (param->table_cant_handle_bit_fields() &&
field->type() == MYSQL_TYPE_BIT) field->type() == MYSQL_TYPE_BIT)
{ {
const Type_handler *handler= type_handler_long_or_longlong(); const Type_handler *handler= type_handler_long_or_longlong();
result= handler->make_and_init_table_field(&name, result= handler->make_and_init_table_field(new_name,
Record_addr(maybe_null), Record_addr(maybe_null),
*this, new_table); *this, new_table);
} }
else else
{ {
LEX_CSTRING *tmp= orig_item ? &orig_item->name : &name;
bool tmp_maybe_null= param->modify_item() ? maybe_null : bool tmp_maybe_null= param->modify_item() ? maybe_null :
field->maybe_null(); field->maybe_null();
result= field->create_tmp_field(new_table->in_use->mem_root, new_table, result= field->create_tmp_field(new_table->in_use->mem_root, new_table,
tmp_maybe_null); tmp_maybe_null);
if (result) if (result && ! param->modify_item())
result->field_name= *tmp; result->field_name= *new_name;
} }
if (result && param->modify_item()) if (result && param->modify_item())
result_field= result; result_field= result;