summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <igor@olga.mysql.com>2007-03-07 07:58:34 -0800
committerunknown <igor@olga.mysql.com>2007-03-07 07:58:34 -0800
commite4cdb5801325acf72dbbe197c3c2eb2f7c7244b7 (patch)
tree3df1dea1b56f11ca6ec5383c4479a05ad00785c5
parent6da758c216f288d8ab95dd454a1d096ac829fac3 (diff)
parentcbd324d26256ba17a3e55ff7c72469ca9c8ad27f (diff)
downloadmariadb-git-e4cdb5801325acf72dbbe197c3c2eb2f7c7244b7.tar.gz
Merge olga.mysql.com:/home/igor/mysql-5.0-opt
into olga.mysql.com:/home/igor/dev-opt/mysql-5.0-opt-bug26560 sql/sql_base.cc: Auto merged sql/sql_select.cc: Auto merged
-rw-r--r--mysql-test/r/func_in.result8
-rw-r--r--mysql-test/r/order_by.result8
-rw-r--r--mysql-test/r/update.result4
-rw-r--r--mysql-test/t/func_in.test6
-rw-r--r--mysql-test/t/order_by.test8
-rw-r--r--mysql-test/t/update.test8
-rw-r--r--sql/sql_base.cc9
-rw-r--r--sql/sql_select.cc17
8 files changed, 61 insertions, 7 deletions
diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result
index 36bcc6f1711..fad9a7157e1 100644
--- a/mysql-test/r/func_in.result
+++ b/mysql-test/r/func_in.result
@@ -463,5 +463,11 @@ CREATE TABLE t3 (a BIGINT UNSIGNED);
INSERT INTO t3 VALUES (9223372036854775551);
SELECT HEX(a) FROM t3 WHERE a IN (9223372036854775807, 42);
HEX(a)
-DROP TABLE t1,t2,t3;
+CREATE TABLE t4 (a DATE);
+INSERT INTO t4 VALUES ('1972-02-06'), ('1972-07-29');
+SELECT * FROM t4 WHERE a IN ('1972-02-06','19772-07-29');
+a
+Warnings:
+Warning 1292 Incorrect date value: '19772-07-29' for column 'a' at row 1
+DROP TABLE t1,t2,t3,t4;
End of 5.0 tests
diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result
index e81d46c9199..0b1edfd3e8f 100644
--- a/mysql-test/r/order_by.result
+++ b/mysql-test/r/order_by.result
@@ -926,3 +926,11 @@ NULL
2
3
DROP TABLE t1,t2,t3,t4;
+create table t1 (a int, b int, c int);
+insert into t1 values (1,2,3), (9,8,3), (19,4,3), (1,4,9);
+select a,(sum(b)/sum(c)) as ratio from t1 group by a order by sum(b)/sum(c) asc;
+a ratio
+1 0.5000
+19 1.3333
+9 2.6667
+drop table t1;
diff --git a/mysql-test/r/update.result b/mysql-test/r/update.result
index b3c5760e2c9..748c2644eb9 100644
--- a/mysql-test/r/update.result
+++ b/mysql-test/r/update.result
@@ -377,6 +377,10 @@ create table t1(f1 int, `*f2` int);
insert into t1 values (1,1);
update t1 set `*f2`=1;
drop table t1;
+create table t1(f1 int);
+update t1 set f2=1 order by f2;
+ERROR 42S22: Unknown column 'f2' in 'order clause'
+drop table t1;
CREATE TABLE t1 (
request_id int unsigned NOT NULL auto_increment,
user_id varchar(12) default NULL,
diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test
index 7ba54747d4b..f9749662ec1 100644
--- a/mysql-test/t/func_in.test
+++ b/mysql-test/t/func_in.test
@@ -354,6 +354,10 @@ INSERT INTO t3 VALUES (9223372036854775551);
SELECT HEX(a) FROM t3 WHERE a IN (9223372036854775807, 42);
-DROP TABLE t1,t2,t3;
+CREATE TABLE t4 (a DATE);
+INSERT INTO t4 VALUES ('1972-02-06'), ('1972-07-29');
+SELECT * FROM t4 WHERE a IN ('1972-02-06','19772-07-29');
+
+DROP TABLE t1,t2,t3,t4;
--echo End of 5.0 tests
diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test
index 012b38ff8b7..a3aa2c0081d 100644
--- a/mysql-test/t/order_by.test
+++ b/mysql-test/t/order_by.test
@@ -640,3 +640,11 @@ SELECT t2.b FROM t1 LEFT JOIN (t2, t3 LEFT JOIN t4 ON t3.a=t4.a)
ON (t1.a=t2.a AND t1.b=t3.b) order by t2.b;
DROP TABLE t1,t2,t3,t4;
+
+#
+# Bug#25376: Incomplete setup of ORDER BY clause results in a wrong result.
+#
+create table t1 (a int, b int, c int);
+insert into t1 values (1,2,3), (9,8,3), (19,4,3), (1,4,9);
+select a,(sum(b)/sum(c)) as ratio from t1 group by a order by sum(b)/sum(c) asc;
+drop table t1;
diff --git a/mysql-test/t/update.test b/mysql-test/t/update.test
index 23ee75d61ea..6cec940d286 100644
--- a/mysql-test/t/update.test
+++ b/mysql-test/t/update.test
@@ -306,6 +306,14 @@ create table t1(f1 int, `*f2` int);
insert into t1 values (1,1);
update t1 set `*f2`=1;
drop table t1;
+
+#
+# Bug#25126: Wrongly resolved field leads to a crash
+#
+create table t1(f1 int);
+--error 1054
+update t1 set f2=1 order by f2;
+drop table t1;
# End of 4.1 tests
#
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 0ebfd2b1044..c2950eceb0e 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -4437,12 +4437,15 @@ bool setup_fields(THD *thd, Item **ref_pointer_array,
bool save_set_query_id= thd->set_query_id;
nesting_map save_allow_sum_func= thd->lex->allow_sum_func;
List_iterator<Item> it(fields);
+ bool save_is_item_list_lookup;
DBUG_ENTER("setup_fields");
thd->set_query_id=set_query_id;
if (allow_sum_func)
thd->lex->allow_sum_func|= 1 << thd->lex->current_select->nest_level;
thd->where= THD::DEFAULT_WHERE;
+ save_is_item_list_lookup= thd->lex->current_select->is_item_list_lookup;
+ thd->lex->current_select->is_item_list_lookup= 0;
/*
To prevent fail on forward lookup we fill it with zerows,
@@ -4465,6 +4468,7 @@ bool setup_fields(THD *thd, Item **ref_pointer_array,
if (!item->fixed && item->fix_fields(thd, it.ref()) ||
(item= *(it.ref()))->check_cols(1))
{
+ thd->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
thd->lex->allow_sum_func= save_allow_sum_func;
thd->set_query_id= save_set_query_id;
DBUG_RETURN(TRUE); /* purecov: inspected */
@@ -4477,6 +4481,7 @@ bool setup_fields(THD *thd, Item **ref_pointer_array,
thd->used_tables|= item->used_tables();
thd->lex->current_select->cur_pos_in_select_list++;
}
+ thd->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
thd->lex->current_select->cur_pos_in_select_list= UNDEF_POS;
thd->lex->allow_sum_func= save_allow_sum_func;
@@ -4973,6 +4978,8 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
*/
bool it_is_update= (select_lex == &thd->lex->select_lex) &&
thd->lex->which_check_option_applicable();
+ bool save_is_item_list_lookup= select_lex->is_item_list_lookup;
+ select_lex->is_item_list_lookup= 0;
DBUG_ENTER("setup_conds");
if (select_lex->conds_processed_with_permanent_arena ||
@@ -5047,9 +5054,11 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
select_lex->where= *conds;
select_lex->conds_processed_with_permanent_arena= 1;
}
+ thd->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
DBUG_RETURN(test(thd->net.report_error));
err_no_arena:
+ select_lex->is_item_list_lookup= save_is_item_list_lookup;
DBUG_RETURN(1);
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 7538d3bf599..af393471b64 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -396,6 +396,7 @@ JOIN::prepare(Item ***rref_pointer_array,
join_list= &select_lex->top_join_list;
union_part= (unit_arg->first_select()->next_select() != 0);
+ thd->lex->current_select->is_item_list_lookup= 1;
/*
If we have already executed SELECT, then it have not sense to prevent
its table from update (see unique_table())
@@ -455,6 +456,17 @@ JOIN::prepare(Item ***rref_pointer_array,
select_lex->fix_prepare_information(thd, &conds, &having);
+ if (order)
+ {
+ ORDER *ord;
+ for (ord= order; ord; ord= ord->next)
+ {
+ Item *item= *ord->item;
+ if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM)
+ item->split_sum_func(thd, ref_pointer_array, all_fields);
+ }
+ }
+
if (having && having->with_sum_func)
having->split_sum_func2(thd, ref_pointer_array, all_fields,
&having, TRUE);
@@ -13265,16 +13277,11 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
We check order_item->fixed because Item_func_group_concat can put
arguments for which fix_fields already was called.
*/
- thd->lex->current_select->is_item_list_lookup= 1;
if (!order_item->fixed &&
(order_item->fix_fields(thd, order->item) ||
(order_item= *order->item)->check_cols(1) ||
thd->is_fatal_error))
- {
- thd->lex->current_select->is_item_list_lookup= 0;
return TRUE; /* Wrong field. */
- }
- thd->lex->current_select->is_item_list_lookup= 0;
uint el= all_fields.elements;
all_fields.push_front(order_item); /* Add new field to field list. */