Commit 6a8bd84a authored by unknown's avatar unknown

Bug#27990: Wrong info in MYSQL_FIELD struct members when a tmp table was used.

The change_to_use_tmp_fields function leaves the orig_table member of an
expression's tmp table field filled for the new Item_field being created.
Later orig_table is used by the Field::make_field function to provide some
info about original table and field name to a user. This is ok for a field
but for an expression it should be empty.

The change_to_use_tmp_fields function now resets orig_table member of
an expression's tmp table field to prevent providing a wrong info to a user.
The Field::make_field function now resets the table_name and the org_col_name
variables when the orig_table is set to 0.


sql/field.cc:
  Bug#27990: Wrong info in MYSQL_FIELD struct members when a tmp table was used.
  The Field::make_field function now resets the table_name and the org_col_name
  variables when the orig_table is set to 0.
sql/sql_select.cc:
  Bug#27990: Wrong info in MYSQL_FIELD struct members when a tmp table was used.
  The change_to_use_tmp_fields function now resets orig_table member of
  an expression's tmp table field to prevent providing a wrong info to a user.
tests/mysql_client_test.c:
  The test case for the bug#21635 is altered to test behavior on both const and
  non-const tables.
parent 4430048e
set autocommit=1;
reset master;
create table bug16206 (a int);
insert into bug16206 values(1);
start transaction;
insert into bug16206 values(2);
commit;
show binlog events;
Log_name Pos Event_type Server_id End_log_pos Info
f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4
f n Query 1 n use `test`; create table bug16206 (a int)
f n Query 1 n use `test`; insert into bug16206 values(1)
f n Query 1 n use `test`; insert into bug16206 values(2)
drop table bug16206;
reset master;
create table bug16206 (a int) engine= bdb;
insert into bug16206 values(0);
insert into bug16206 values(1);
start transaction;
insert into bug16206 values(2);
commit;
insert into bug16206 values(3);
show binlog events;
Log_name Pos Event_type Server_id End_log_pos Info
f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4
f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb
f n Query 1 n use `test`; insert into bug16206 values(0)
f n Query 1 n use `test`; insert into bug16206 values(1)
f n Query 1 n use `test`; BEGIN
f n Query 1 n use `test`; insert into bug16206 values(2)
f n Query 1 n use `test`; COMMIT
f n Query 1 n use `test`; insert into bug16206 values(3)
drop table bug16206;
set autocommit=0;
End of 5.0 tests
-- source include/not_embedded.inc
-- source include/have_bdb.inc
#
# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode
#
set autocommit=1;
let $VERSION=`select version()`;
reset master;
create table bug16206 (a int);
insert into bug16206 values(1);
start transaction;
insert into bug16206 values(2);
commit;
--replace_result $VERSION VERSION
--replace_column 1 f 2 n 5 n
show binlog events;
drop table bug16206;
reset master;
create table bug16206 (a int) engine= bdb;
insert into bug16206 values(0);
insert into bug16206 values(1);
start transaction;
insert into bug16206 values(2);
commit;
insert into bug16206 values(3);
--replace_result $VERSION VERSION
--replace_column 1 f 2 n 5 n
show binlog events;
drop table bug16206;
set autocommit=0;
--echo End of 5.0 tests
......@@ -1282,15 +1282,25 @@ void Field_num::add_zerofill_and_unsigned(String &res) const
void Field::make_field(Send_field *field)
{
if (orig_table->s->table_cache_key && *(orig_table->s->table_cache_key))
if (orig_table && orig_table->s->table_cache_key &&
*(orig_table->s->table_cache_key))
{
field->org_table_name= orig_table->s->table_name;
field->db_name= orig_table->s->table_cache_key;
}
else
field->org_table_name= field->db_name= "";
field->table_name= orig_table->alias;
field->col_name= field->org_col_name= field_name;
if (orig_table)
{
field->table_name= orig_table->alias;
field->org_col_name= field_name;
}
else
{
field->table_name= "";
field->org_col_name= "";
}
field->col_name= field_name;
field->charsetnr= charset()->number;
field->length=field_length;
field->type=type();
......
......@@ -14119,6 +14119,9 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
item_field= (Item*) new Item_field(field);
if (!item_field)
DBUG_RETURN(TRUE); // Fatal error
if (item->real_item()->type() != Item::FIELD_ITEM)
field->orig_table= 0;
item_field->name= item->name;
#ifndef DBUG_OFF
if (_db_on_ && !item_field->name)
......
......@@ -15486,7 +15486,7 @@ static void test_bug21635()
char *query_end;
MYSQL_RES *result;
MYSQL_FIELD *field;
unsigned int field_count, i;
unsigned int field_count, i, j;
int rc;
DBUG_ENTER("test_bug21635");
......@@ -15502,28 +15502,35 @@ static void test_bug21635()
myquery(rc);
rc= mysql_query(mysql, "CREATE TABLE t1 (i INT)");
myquery(rc);
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)");
myquery(rc);
/*
We need this loop to ensure correct behavior with both constant and
non-constant tables.
*/
for (j= 0; j < 2 ; j++)
{
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)");
myquery(rc);
rc= mysql_real_query(mysql, query, query_end - query);
myquery(rc);
rc= mysql_real_query(mysql, query, query_end - query);
myquery(rc);
result= mysql_use_result(mysql);
DIE_UNLESS(result);
result= mysql_use_result(mysql);
DIE_UNLESS(result);
field_count= mysql_field_count(mysql);
for (i= 0; i < field_count; ++i)
{
field= mysql_fetch_field_direct(result, i);
printf("%s -> %s ... ", expr[i * 2], field->name);
fflush(stdout);
DIE_UNLESS(field->db[0] == 0 && field->org_table[0] == 0 &&
field->table[0] == 0 && field->org_name[0] == 0);
DIE_UNLESS(strcmp(field->name, expr[i * 2 + 1]) == 0);
puts("OK");
}
field_count= mysql_field_count(mysql);
for (i= 0; i < field_count; ++i)
{
field= mysql_fetch_field_direct(result, i);
printf("%s -> %s ... ", expr[i * 2], field->name);
fflush(stdout);
DIE_UNLESS(field->db[0] == 0 && field->org_table[0] == 0 &&
field->table[0] == 0 && field->org_name[0] == 0);
DIE_UNLESS(strcmp(field->name, expr[i * 2 + 1]) == 0);
puts("OK");
}
mysql_free_result(result);
mysql_free_result(result);
}
rc= mysql_query(mysql, "DROP TABLE t1");
myquery(rc);
......
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