Commit 689b8d06 authored by Monty's avatar Monty

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).
parent adaf0dde
......@@ -3503,6 +3503,7 @@ print_field_types(MYSQL_RES *result)
while ((field = mysql_fetch_field(result)))
{
tee_fprintf(PAGER, "Field %3u: `%s`\n"
"Org_field: `%s`\n"
"Catalog: `%s`\n"
"Database: `%s`\n"
"Table: `%s`\n"
......@@ -3514,8 +3515,8 @@ print_field_types(MYSQL_RES *result)
"Decimals: %u\n"
"Flags: %s\n\n",
++i,
field->name, field->catalog, field->db, field->table,
field->org_table, fieldtype2str(field->type),
field->name, field->org_name, field->catalog, field->db,
field->table, field->org_table, fieldtype2str(field->type),
get_charset_name(field->charsetnr), field->charsetnr,
field->length, field->max_length, field->decimals,
fieldflags2str(field->flags));
......
......@@ -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
connection default;
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
#
This diff is collapsed.
......@@ -17972,7 +17972,14 @@ Field *Item::create_field_for_schema(THD *thd, TABLE *table)
/**
Create a temporary field for Item_field (or its descendant),
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 *
Item_field::create_tmp_field_from_item_field(TABLE *new_table,
Item_ref *orig_item,
......@@ -17980,6 +17987,10 @@ Item_field::create_tmp_field_from_item_field(TABLE *new_table,
{
DBUG_ASSERT(!is_result_field());
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,
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);
const Type_handler *handler= type_handler()->
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);
}
else if (param->table_cant_handle_bit_fields() &&
field->type() == MYSQL_TYPE_BIT)
{
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),
*this, new_table);
}
else
{
LEX_CSTRING *tmp= orig_item ? &orig_item->name : &name;
bool tmp_maybe_null= param->modify_item() ? maybe_null :
field->maybe_null();
result= field->create_tmp_field(new_table->in_use->mem_root, new_table,
tmp_maybe_null);
if (result)
result->field_name= *tmp;
if (result && ! param->modify_item())
result->field_name= *new_name;
}
if (result && param->modify_item())
result_field= result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment