Skip to content

Commit

Permalink
MDEV-13209 Cross-database operation with virtual columns fails
Browse files Browse the repository at this point in the history
if we don't need to print field's table name,
we surely don't need to print field's db name either
  • Loading branch information
vuvova committed Jul 5, 2017
1 parent 186075a commit 0559f12
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
17 changes: 17 additions & 0 deletions mysql-test/suite/vcol/r/cross_db.result
@@ -0,0 +1,17 @@
create database mysqltest1;
create table mysqltest1.t1 (i int, j int as (i) persistent);
show create table mysqltest1.t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL,
`j` int(11) GENERATED ALWAYS AS (`i`) STORED
) ENGINE=MyISAM DEFAULT CHARSET=latin1
alter table mysqltest1.t1 add index (i);
show create table mysqltest1.t1;
Table Create Table
t1 CREATE TABLE `t1` (
`i` int(11) DEFAULT NULL,
`j` int(11) GENERATED ALWAYS AS (`i`) STORED,
KEY `i` (`i`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop database mysqltest1;
9 changes: 9 additions & 0 deletions mysql-test/suite/vcol/t/cross_db.test
@@ -0,0 +1,9 @@
#
# MDEV-13209 Cross-database operation with virtual columns fails
#
create database mysqltest1;
create table mysqltest1.t1 (i int, j int as (i) persistent);
show create table mysqltest1.t1;
alter table mysqltest1.t1 add index (i);
show create table mysqltest1.t1;
drop database mysqltest1;
9 changes: 4 additions & 5 deletions sql/item.cc
Expand Up @@ -2669,22 +2669,21 @@ void Item_ident::print(String *str, enum_query_type query_type)
use_db_name= !(cached_table && cached_table->belong_to_view &&
cached_table->belong_to_view->compact_view_format);

if (!use_db_name && use_table_name &&
(query_type & QT_ITEM_IDENT_SKIP_TABLE_NAMES))
if (use_table_name && (query_type & QT_ITEM_IDENT_SKIP_TABLE_NAMES))
{
/*
Don't print the table name if it's the only table in the context
XXX technically, that's a sufficient, but too strong condition
*/
if (!context)
use_table_name= false;
use_db_name= use_table_name= false;
else if (context->outer_context)
use_table_name= true;
else if (context->last_name_resolution_table == context->first_name_resolution_table)
use_table_name= false;
use_db_name= use_table_name= false;
else if (!context->last_name_resolution_table &&
!context->first_name_resolution_table->next_name_resolution_table)
use_table_name= false;
use_db_name= use_table_name= false;
}

if (!field_name || !field_name[0])
Expand Down

0 comments on commit 0559f12

Please sign in to comment.