Skip to content

Commit

Permalink
MDEV-13242 Wrong results for queries with row constructors and inform…
Browse files Browse the repository at this point in the history
…ation_schema
  • Loading branch information
Alexander Barkov committed Oct 5, 2017
1 parent bcda03b commit 1cfaafa
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
32 changes: 32 additions & 0 deletions mysql-test/r/information_schema.result
Original file line number Diff line number Diff line change
Expand Up @@ -2069,3 +2069,35 @@ Opened_tables 3
drop database mysqltest;
drop database db1;
set global sql_mode=default;
USE test;
#
# End of 10.0 tests
#
#
# Start of 10.1 tests
#
#
# MDEV-13242 Wrong results for queries with row constructors and information_schema
#
CREATE TABLE tt1(c1 INT);
CREATE TABLE tt2(c2 INT);
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt1', 'c1'));
count(*)
1
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt2', 'c2'));
count(*)
1
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt1','c1'),('tt2', 'c2'));
count(*)
2
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);
count(*)
2
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');
count(*)
2
SELECT column_name FROM information_schema.columns WHERE (table_name, column_name) IN (('tt1','c1'),('tt2', 'c2')) ORDER BY column_name;
column_name
c1
c2
DROP TABLE tt1, tt2;
26 changes: 26 additions & 0 deletions mysql-test/t/information_schema.test
Original file line number Diff line number Diff line change
Expand Up @@ -1910,3 +1910,29 @@ disconnect con1;
--source include/wait_until_count_sessions.inc

set global sql_mode=default;

USE test;

--echo #
--echo # End of 10.0 tests
--echo #


--echo #
--echo # Start of 10.1 tests
--echo #


--echo #
--echo # MDEV-13242 Wrong results for queries with row constructors and information_schema
--echo #

CREATE TABLE tt1(c1 INT);
CREATE TABLE tt2(c2 INT);
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt1', 'c1'));
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt2', 'c2'));
SELECT count(*) FROM information_schema.columns WHERE table_schema='test' AND (table_name, column_name) IN (('tt1','c1'),('tt2', 'c2'));
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);
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');
SELECT column_name FROM information_schema.columns WHERE (table_name, column_name) IN (('tt1','c1'),('tt2', 'c2')) ORDER BY column_name;
DROP TABLE tt1, tt2;
2 changes: 2 additions & 0 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -4131,6 +4131,8 @@ class Item_cache_wrapper :public Item_result_field
bool fix_fields(THD *thd, Item **it);
void cleanup();

Item *get_orig_item() const { return orig_item; }

/* Methods of getting value which should be cached in the cache */
void save_val(Field *to);
double val_real();
Expand Down
14 changes: 14 additions & 0 deletions sql/sql_show.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3640,6 +3640,15 @@ bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
return 0;
}
}
else if (item->type() == Item::ROW_ITEM)
{
Item_row *item_row= static_cast<Item_row*>(item);
for (uint i= 0; i < item_row->cols(); i++)
{
if (!uses_only_table_name_fields(item_row->element_index(i), table))
return 0;
}
}
else if (item->type() == Item::FIELD_ITEM)
{
Item_field *item_field= (Item_field*)item;
Expand All @@ -3659,6 +3668,11 @@ bool uses_only_table_name_fields(Item *item, TABLE_LIST *table)
strlen(item_field->field_name), 0)))
return 0;
}
else if (item->type() == Item::EXPR_CACHE_ITEM)
{
Item_cache_wrapper *tmp= static_cast<Item_cache_wrapper*>(item);
return uses_only_table_name_fields(tmp->get_orig_item(), table);
}
else if (item->type() == Item::REF_ITEM)
return uses_only_table_name_fields(item->real_item(), table);

Expand Down

0 comments on commit 1cfaafa

Please sign in to comment.