Skip to content

Commit 1cfaafa

Browse files
author
Alexander Barkov
committed
MDEV-13242 Wrong results for queries with row constructors and information_schema
1 parent bcda03b commit 1cfaafa

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

mysql-test/r/information_schema.result

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2069,3 +2069,35 @@ Opened_tables 3
20692069
drop database mysqltest;
20702070
drop database db1;
20712071
set global sql_mode=default;
2072+
USE test;
2073+
#
2074+
# End of 10.0 tests
2075+
#
2076+
#
2077+
# Start of 10.1 tests
2078+
#
2079+
#
2080+
# MDEV-13242 Wrong results for queries with row constructors and information_schema
2081+
#
2082+
CREATE TABLE tt1(c1 INT);
2083+
CREATE TABLE tt2(c2 INT);
2084+
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt1', 'c1'));
2085+
count(*)
2086+
1
2087+
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt2', 'c2'));
2088+
count(*)
2089+
1
2090+
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt1','c1'),('tt2', 'c2'));
2091+
count(*)
2092+
2
2093+
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (SELECT 'tt1','c1' FROM dual UNION SELECT 'tt2', 'c2' FROM dual);
2094+
count(*)
2095+
2
2096+
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name='tt1' AND column_name='c1') OR (table_name='tt2' AND column_name='c2');
2097+
count(*)
2098+
2
2099+
SELECT column_name FROM information_schema.columns WHERE (table_name, column_name) IN (('tt1','c1'),('tt2', 'c2')) ORDER BY column_name;
2100+
column_name
2101+
c1
2102+
c2
2103+
DROP TABLE tt1, tt2;

mysql-test/t/information_schema.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,3 +1910,29 @@ disconnect con1;
19101910
--source include/wait_until_count_sessions.inc
19111911

19121912
set global sql_mode=default;
1913+
1914+
USE test;
1915+
1916+
--echo #
1917+
--echo # End of 10.0 tests
1918+
--echo #
1919+
1920+
1921+
--echo #
1922+
--echo # Start of 10.1 tests
1923+
--echo #
1924+
1925+
1926+
--echo #
1927+
--echo # MDEV-13242 Wrong results for queries with row constructors and information_schema
1928+
--echo #
1929+
1930+
CREATE TABLE tt1(c1 INT);
1931+
CREATE TABLE tt2(c2 INT);
1932+
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt1', 'c1'));
1933+
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt2', 'c2'));
1934+
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt1','c1'),('tt2', 'c2'));
1935+
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (SELECT 'tt1','c1' FROM dual UNION SELECT 'tt2', 'c2' FROM dual);
1936+
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name='tt1' AND column_name='c1') OR (table_name='tt2' AND column_name='c2');
1937+
SELECT column_name FROM information_schema.columns WHERE (table_name, column_name) IN (('tt1','c1'),('tt2', 'c2')) ORDER BY column_name;
1938+
DROP TABLE tt1, tt2;

sql/item.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,6 +4131,8 @@ class Item_cache_wrapper :public Item_result_field
41314131
bool fix_fields(THD *thd, Item **it);
41324132
void cleanup();
41334133

4134+
Item *get_orig_item() const { return orig_item; }
4135+
41344136
/* Methods of getting value which should be cached in the cache */
41354137
void save_val(Field *to);
41364138
double val_real();

sql/sql_show.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3640,6 +3640,15 @@ bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
36403640
return 0;
36413641
}
36423642
}
3643+
else if (item->type() == Item::ROW_ITEM)
3644+
{
3645+
Item_row *item_row= static_cast<Item_row*>(item);
3646+
for (uint i= 0; i < item_row->cols(); i++)
3647+
{
3648+
if (!uses_only_table_name_fields(item_row->element_index(i), table))
3649+
return 0;
3650+
}
3651+
}
36433652
else if (item->type() == Item::FIELD_ITEM)
36443653
{
36453654
Item_field *item_field= (Item_field*)item;
@@ -3659,6 +3668,11 @@ bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
36593668
strlen(item_field->field_name), 0)))
36603669
return 0;
36613670
}
3671+
else if (item->type() == Item::EXPR_CACHE_ITEM)
3672+
{
3673+
Item_cache_wrapper *tmp= static_cast<Item_cache_wrapper*>(item);
3674+
return uses_only_table_name_fields(tmp->get_orig_item(), table);
3675+
}
36623676
else if (item->type() == Item::REF_ITEM)
36633677
return uses_only_table_name_fields(item->real_item(), table);
36643678

0 commit comments

Comments
 (0)