Skip to content

Commit 46135c6

Browse files
committed
MDEV-36979 Same alias name with different case on same table is not working in functions
table keys {db,table,alias} must be compared with table_alias_charset
1 parent 9253d6d commit 46135c6

File tree

6 files changed

+85
-3
lines changed

6 files changed

+85
-3
lines changed

mysql-test/main/lowercase_fs_off.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,21 @@ CREATE TABLE t1 (a Mariadb_schema.date);
271271
ERROR HY000: Unknown data type: 'Mariadb_schema.date'
272272
CREATE TABLE t1 (a mariadb_schema.date);
273273
DROP TABLE t1;
274+
# End of 10.3 tests
275+
#
276+
# MDEV-36979 Same alias name with different case on same table is not working in functions
277+
#
278+
create table t1 (a int);
279+
insert t1 values (1);
280+
create table T1 (b int);
281+
insert T1 values (10);
282+
create function t1test(val int) returns int
283+
begin
284+
return (select a from t1 where exists (select b from T1 where b > val));
285+
end//
286+
select t1test(1);
287+
t1test(1)
288+
1
289+
drop function t1test;
290+
drop table t1, T1;
291+
# End of 10.11 tests

mysql-test/main/lowercase_fs_off.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,24 @@ CREATE TABLE t1 (a Mariadb_schema.date);
146146

147147
CREATE TABLE t1 (a mariadb_schema.date);
148148
DROP TABLE t1;
149+
150+
--echo # End of 10.3 tests
151+
152+
--echo #
153+
--echo # MDEV-36979 Same alias name with different case on same table is not working in functions
154+
--echo #
155+
create table t1 (a int);
156+
insert t1 values (1);
157+
create table T1 (b int);
158+
insert T1 values (10);
159+
delimiter //;
160+
create function t1test(val int) returns int
161+
begin
162+
return (select a from t1 where exists (select b from T1 where b > val));
163+
end//
164+
delimiter ;//
165+
select t1test(1);
166+
drop function t1test;
167+
drop table t1, T1;
168+
169+
--echo # End of 10.11 tests

mysql-test/main/sp-bugs2.result

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,25 @@ Warnings:
2121
Note 1050 Table 't2' already exists
2222
DROP PROCEDURE sp;
2323
DROP TABLE t1, t2;
24+
#
25+
# MDEV-36979 Same alias name with different case on same table is not working in functions
26+
#
27+
create table t1 ( id int primary key auto_increment, name varchar(10));
28+
insert into t1 (name) values ('wrbyviwb');
29+
insert into t1 (name) values ('wrbyrwb1');
30+
insert into t1 (name) values ('wrbrwb3');
31+
select cnt.name from t1 cnt join ( select CMT.id from t1 CMT where CMT.id=1) t2 on t2.id=cnt.id;
32+
name
33+
wrbyviwb
34+
create function t1test(val int) returns varchar(400) charset utf8
35+
begin
36+
declare output varchar(400) default '';
37+
set output = (select cnt.name from t1 cnt join ( select CMT.id from t1 CMT where CMT.id=val) t2 on t2.id=cnt.id);
38+
return output;
39+
end//
40+
select t1test(1);
41+
t1test(1)
42+
wrbyviwb
43+
drop function t1test;
44+
drop table t1;
45+
# End of 10.11 tests

mysql-test/main/sp-bugs2.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,24 @@ CALL sp();
2727
DROP PROCEDURE sp;
2828
DROP TABLE t1, t2;
2929

30+
--echo #
31+
--echo # MDEV-36979 Same alias name with different case on same table is not working in functions
32+
--echo #
33+
create table t1 ( id int primary key auto_increment, name varchar(10));
34+
insert into t1 (name) values ('wrbyviwb');
35+
insert into t1 (name) values ('wrbyrwb1');
36+
insert into t1 (name) values ('wrbrwb3');
37+
select cnt.name from t1 cnt join ( select CMT.id from t1 CMT where CMT.id=1) t2 on t2.id=cnt.id;
38+
delimiter //;
39+
create function t1test(val int) returns varchar(400) charset utf8
40+
begin
41+
declare output varchar(400) default '';
42+
set output = (select cnt.name from t1 cnt join ( select CMT.id from t1 CMT where CMT.id=val) t2 on t2.id=cnt.id);
43+
return output;
44+
end//
45+
delimiter ;//
46+
select t1test(1);
47+
drop function t1test;
48+
drop table t1;
49+
50+
--echo # End of 10.11 tests

mysql-test/suite/binlog/r/binlog_unsafe.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,13 +2544,13 @@ Log_name Pos Event_type Server_id End_log_pos Info
25442544
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
25452545
master-bin.000001 # Annotate_rows # # insert into t2(a) values(new.a)
25462546
master-bin.000001 # Table_map # # table_id: # (test.t1)
2547-
master-bin.000001 # Table_map # # table_id: # (test.t3)
25482547
master-bin.000001 # Table_map # # table_id: # (test.t2)
2548+
master-bin.000001 # Table_map # # table_id: # (test.t3)
25492549
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
25502550
master-bin.000001 # Annotate_rows # # insert into t3(a) values(new.a)
25512551
master-bin.000001 # Table_map # # table_id: # (test.t1)
2552-
master-bin.000001 # Table_map # # table_id: # (test.t3)
25532552
master-bin.000001 # Table_map # # table_id: # (test.t2)
2553+
master-bin.000001 # Table_map # # table_id: # (test.t3)
25542554
master-bin.000001 # Write_rows_v1 # # table_id: #
25552555
master-bin.000001 # Write_rows_v1 # # table_id: # flags: STMT_END_F
25562556
master-bin.000001 # Query # # COMMIT

sql/sp_head.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ sp_head::sp_head(MEM_ROOT *mem_root_arg, sp_package *parent,
606606
m_lex.empty();
607607
my_init_dynamic_array(key_memory_sp_head_main_root, &m_instr,
608608
sizeof(sp_instr *), 16, 8, MYF(0));
609-
my_hash_init(key_memory_sp_head_main_root, &m_sptabs, system_charset_info, 0,
609+
my_hash_init(key_memory_sp_head_main_root, &m_sptabs, table_alias_charset, 0,
610610
0, 0, sp_table_key, 0, 0);
611611
my_hash_init(key_memory_sp_head_main_root, &m_sroutines, system_charset_info,
612612
0, 0, 0, sp_sroutine_key, 0, 0);

0 commit comments

Comments
 (0)