mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Fix for #1992
This bug happens when a query, having subselects in the fields list, needs temporary table. Item_subselect::get_tmp_table_item isn't implemented and just returns *this. So the tmp_table_item takes value not from temporary but from original table. mysql-test/r/subselect.result: appropriate test result added mysql-test/t/subselect.test: test case added sql/item_subselect.cc: Item_subselect::get_tmp_table_item implementation sql/item_subselect.h: Item_subselect::get_tmp_table_item declaration
This commit is contained in:
@@ -1569,3 +1569,13 @@ INSERT INTO t2 VALUES (100, 200, 'C');
|
|||||||
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
|
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
|
||||||
COLC
|
COLC
|
||||||
DROP TABLE t1, t2;
|
DROP TABLE t1, t2;
|
||||||
|
CREATE TABLE t1 (a int(1));
|
||||||
|
INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
|
||||||
|
SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
|
||||||
|
(SELECT a)
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
4
|
||||||
|
5
|
||||||
|
DROP TABLE t1;
|
||||||
|
@@ -1009,3 +1009,8 @@ INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365');
|
|||||||
INSERT INTO t2 VALUES (100, 200, 'C');
|
INSERT INTO t2 VALUES (100, 200, 'C');
|
||||||
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
|
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
|
||||||
DROP TABLE t1, t2;
|
DROP TABLE t1, t2;
|
||||||
|
|
||||||
|
CREATE TABLE t1 (a int(1));
|
||||||
|
INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
|
||||||
|
SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
|
||||||
|
DROP TABLE t1;
|
||||||
|
@@ -166,6 +166,12 @@ bool Item_subselect::const_item() const
|
|||||||
return const_item_cache;
|
return const_item_cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item *Item_subselect::get_tmp_table_item(THD *thd)
|
||||||
|
{
|
||||||
|
if (!with_sum_func && !const_item())
|
||||||
|
return new Item_field(result_field);
|
||||||
|
return copy_or_same(thd);
|
||||||
|
}
|
||||||
|
|
||||||
void Item_subselect::update_used_tables()
|
void Item_subselect::update_used_tables()
|
||||||
{
|
{
|
||||||
|
@@ -89,6 +89,7 @@ public:
|
|||||||
bool const_item() const;
|
bool const_item() const;
|
||||||
inline table_map get_used_tables_cache() { return used_tables_cache; }
|
inline table_map get_used_tables_cache() { return used_tables_cache; }
|
||||||
inline bool get_const_item_cache() { return const_item_cache; }
|
inline bool get_const_item_cache() { return const_item_cache; }
|
||||||
|
Item *get_tmp_table_item(THD *thd);
|
||||||
void update_used_tables();
|
void update_used_tables();
|
||||||
void print(String *str);
|
void print(String *str);
|
||||||
bool change_engine(subselect_engine *eng)
|
bool change_engine(subselect_engine *eng)
|
||||||
|
Reference in New Issue
Block a user