summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/kill.result2
-rw-r--r--mysql-test/r/type_enum.result8
-rw-r--r--mysql-test/t/kill.test53
-rw-r--r--mysql-test/t/type_enum.test8
-rw-r--r--sql/field.cc2
-rw-r--r--sql/sql_select.cc91
6 files changed, 126 insertions, 38 deletions
diff --git a/mysql-test/r/kill.result b/mysql-test/r/kill.result
index 85b6bc65bcb..0d5cd171d2d 100644
--- a/mysql-test/r/kill.result
+++ b/mysql-test/r/kill.result
@@ -123,3 +123,5 @@ release_lock("lock27563")
drop table t1, t2;
drop function bug27563;
drop procedure proc27563;
+PREPARE stmt FROM 'EXPLAIN SELECT * FROM t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16,t17,t18,t19,t20,t21,t22,t23,t24,t25,t26,t27,t28,t29,t30,t31,t32,t33,t34,t35,t36,t37,t38,t39,t40 WHERE a1=a2 AND a2=a3 AND a3=a4 AND a4=a5 AND a5=a6 AND a6=a7 AND a7=a8 AND a8=a9 AND a9=a10 AND a10=a11 AND a11=a12 AND a12=a13 AND a13=a14 AND a14=a15 AND a15=a16 AND a16=a17 AND a17=a18 AND a18=a19 AND a19=a20 AND a20=a21 AND a21=a22 AND a22=a23 AND a23=a24 AND a24=a25 AND a25=a26 AND a26=a27 AND a27=a28 AND a28=a29 AND a29=a30 AND a30=a31 AND a31=a32 AND a32=a33 AND a33=a34 AND a34=a35 AND a35=a36 AND a36=a37 AND a37=a38 AND a38=a39 AND a39=a40 ';
+EXECUTE stmt;
diff --git a/mysql-test/r/type_enum.result b/mysql-test/r/type_enum.result
index 70ef98af420..80323f07f79 100644
--- a/mysql-test/r/type_enum.result
+++ b/mysql-test/r/type_enum.result
@@ -1755,6 +1755,14 @@ t1 CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
End of 4.1 tests
+
+create table t1(f1 set('a','b'), index(f1));
+insert into t1 values(''),(''),('a'),('b');
+select * from t1 where f1='';
+f1
+
+
+drop table t1;
create table t1(russian enum('E','F','EÿF','FÿE') NOT NULL DEFAULT'E');
show create table t1;
Table Create Table
diff --git a/mysql-test/t/kill.test b/mysql-test/t/kill.test
index f3ec9dd3430..959938dcb03 100644
--- a/mysql-test/t/kill.test
+++ b/mysql-test/t/kill.test
@@ -249,3 +249,56 @@ select release_lock("lock27563");
drop table t1, t2;
drop function bug27563;
drop procedure proc27563;
+
+#
+# Bug#28598: mysqld crash when killing a long-running explain query.
+#
+--disable_query_log
+connection con1;
+let $ID= `select connection_id()`;
+let $tab_count= 40;
+
+let $i= $tab_count;
+while ($i)
+{
+ eval CREATE TABLE t$i (a$i int, KEY(a$i));
+ eval INSERT INTO t$i VALUES (1),(2),(3),(4),(5),(6),(7);
+ dec $i ;
+}
+set session optimizer_search_depth=0;
+
+let $i=$tab_count;
+while ($i)
+{
+ let $a= a$i;
+ let $t= t$i;
+ dec $i;
+ if ($i)
+ {
+ let $comma=,;
+ let $from=$comma$t$from;
+ let $where=a$i=$a $and $where;
+ }
+ if (!$i)
+ {
+ let $from=FROM $t$from;
+ let $where=WHERE $where;
+ }
+ let $and=AND;
+}
+
+--enable_query_log
+eval PREPARE stmt FROM 'EXPLAIN SELECT * $from $where';
+send EXECUTE stmt;
+--disable_query_log
+
+connection con2;
+real_sleep 2;
+eval kill query $ID;
+let $i= $tab_count;
+while ($i)
+{
+ eval DROP TABLE t$i;
+ dec $i ;
+}
+--enable_query_log
diff --git a/mysql-test/t/type_enum.test b/mysql-test/t/type_enum.test
index 9be1b7fa10f..200fd063b99 100644
--- a/mysql-test/t/type_enum.test
+++ b/mysql-test/t/type_enum.test
@@ -139,6 +139,14 @@ drop table t1;
--echo End of 4.1 tests
#
+# Bug#28729: Field_enum wrongly reported an error while storing an empty string.
+#
+create table t1(f1 set('a','b'), index(f1));
+insert into t1 values(''),(''),('a'),('b');
+select * from t1 where f1='';
+drop table t1;
+
+#
# Bug#24660 "enum" field type definition problem
#
create table t1(russian enum('E','F','EÿF','FÿE') NOT NULL DEFAULT'E');
diff --git a/sql/field.cc b/sql/field.cc
index fa25871fe61..80acc0e3a32 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -7856,6 +7856,8 @@ int Field_enum::store(const char *from,uint length,CHARSET_INFO *cs)
tmp=0;
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
}
+ if (!table->in_use->count_cuted_fields)
+ err= 0;
}
else
set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 294d5374d4e..4861179fee1 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -49,15 +49,15 @@ static int sort_keyuse(KEYUSE *a,KEYUSE *b);
static void set_position(JOIN *join,uint index,JOIN_TAB *table,KEYUSE *key);
static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, KEYUSE *org_keyuse,
table_map used_tables);
-static void choose_plan(JOIN *join,table_map join_tables);
+static bool choose_plan(JOIN *join,table_map join_tables);
static void best_access_path(JOIN *join, JOIN_TAB *s, THD *thd,
table_map remaining_tables, uint idx,
double record_count, double read_time);
static void optimize_straight_join(JOIN *join, table_map join_tables);
-static void greedy_search(JOIN *join, table_map remaining_tables,
+static bool greedy_search(JOIN *join, table_map remaining_tables,
uint depth, uint prune_level);
-static void best_extension_by_limited_search(JOIN *join,
+static bool best_extension_by_limited_search(JOIN *join,
table_map remaining_tables,
uint idx, double record_count,
double read_time, uint depth,
@@ -69,7 +69,7 @@ static int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
TODO: 'find_best' is here only temporarily until 'greedy_search' is
tested and approved.
*/
-static void find_best(JOIN *join,table_map rest_tables,uint index,
+static bool find_best(JOIN *join,table_map rest_tables,uint index,
double record_count,double read_time);
static uint cache_record_length(JOIN *join,uint index);
static double prev_record_reads(JOIN *join, uint idx, table_map found_ref);
@@ -2755,7 +2755,8 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds,
if (join->const_tables != join->tables)
{
optimize_keyuse(join, keyuse_array);
- choose_plan(join, all_table_map & ~join->const_table_map);
+ if (choose_plan(join, all_table_map & ~join->const_table_map))
+ DBUG_RETURN(TRUE);
}
else
{
@@ -4404,11 +4405,12 @@ best_access_path(JOIN *join,
the array 'join->best_positions', and the cost of the plan in
'join->best_read'.
- RETURN
- None
+ RETURN VALUES
+ FALSE ok
+ TRUE Fatal error
*/
-static void
+static bool
choose_plan(JOIN *join, table_map join_tables)
{
uint search_depth= join->thd->variables.optimizer_search_depth;
@@ -4441,14 +4443,16 @@ choose_plan(JOIN *join, table_map join_tables)
the greedy version. Will be removed when greedy_search is approved.
*/
join->best_read= DBL_MAX;
- find_best(join, join_tables, join->const_tables, 1.0, 0.0);
+ if (find_best(join, join_tables, join->const_tables, 1.0, 0.0))
+ DBUG_RETURN(TRUE);
}
else
{
if (search_depth == 0)
/* Automatically determine a reasonable value for 'search_depth' */
search_depth= determine_search_depth(join);
- greedy_search(join, join_tables, search_depth, prune_level);
+ if (greedy_search(join, join_tables, search_depth, prune_level))
+ DBUG_RETURN(TRUE);
}
}
@@ -4456,7 +4460,7 @@ choose_plan(JOIN *join, table_map join_tables)
Store the cost of this query into a user variable
*/
join->thd->status_var.last_query_cost= join->best_read;
- DBUG_VOID_RETURN;
+ DBUG_RETURN(FALSE);
}
@@ -4684,11 +4688,12 @@ optimize_straight_join(JOIN *join, table_map join_tables)
In the future, 'greedy_search' might be extended to support other
implementations of 'best_extension', e.g. some simpler quadratic procedure.
- RETURN
- None
+ RETURN VALUES
+ FALSE ok
+ TRUE Fatal error
*/
-static void
+static bool
greedy_search(JOIN *join,
table_map remaining_tables,
uint search_depth,
@@ -4710,8 +4715,9 @@ greedy_search(JOIN *join,
do {
/* Find the extension of the current QEP with the lowest cost */
join->best_read= DBL_MAX;
- best_extension_by_limited_search(join, remaining_tables, idx, record_count,
- read_time, search_depth, prune_level);
+ if (best_extension_by_limited_search(join, remaining_tables, idx, record_count,
+ read_time, search_depth, prune_level))
+ DBUG_RETURN(TRUE);
if (size_remain <= search_depth)
{
@@ -4722,7 +4728,7 @@ greedy_search(JOIN *join,
DBUG_EXECUTE("opt", print_plan(join, join->tables,
record_count, read_time, read_time,
"optimal"););
- DBUG_VOID_RETURN;
+ DBUG_RETURN(FALSE);
}
/* select the first table in the optimal extension as most promising */
@@ -4867,11 +4873,12 @@ greedy_search(JOIN *join,
The parameter 'search_depth' provides control over the recursion
depth, and thus the size of the resulting optimal plan.
- RETURN
- None
+ RETURN VALUES
+ FALSE ok
+ TRUE Fatal error
*/
-static void
+static bool
best_extension_by_limited_search(JOIN *join,
table_map remaining_tables,
uint idx,
@@ -4880,9 +4887,11 @@ best_extension_by_limited_search(JOIN *join,
uint search_depth,
uint prune_level)
{
+ DBUG_ENTER("best_extension_by_limited_search");
+
THD *thd= join->thd;
if (thd->killed) // Abort
- return;
+ DBUG_RETURN(TRUE);
DBUG_ENTER("best_extension_by_limited_search");
DBUG_EXECUTE("opt", print_plan(join, idx, read_time, record_count, idx,
@@ -4966,15 +4975,14 @@ best_extension_by_limited_search(JOIN *join,
if ( (search_depth > 1) && (remaining_tables & ~real_table_bit) )
{ /* Recursively expand the current partial plan */
swap_variables(JOIN_TAB*, join->best_ref[idx], *pos);
- best_extension_by_limited_search(join,
- remaining_tables & ~real_table_bit,
- idx + 1,
- current_record_count,
- current_read_time,
- search_depth - 1,
- prune_level);
- if (thd->killed)
- DBUG_VOID_RETURN;
+ if (best_extension_by_limited_search(join,
+ remaining_tables & ~real_table_bit,
+ idx + 1,
+ current_record_count,
+ current_read_time,
+ search_depth - 1,
+ prune_level))
+ DBUG_RETURN(TRUE);
swap_variables(JOIN_TAB*, join->best_ref[idx], *pos);
}
else
@@ -5003,19 +5011,26 @@ best_extension_by_limited_search(JOIN *join,
restore_prev_nj_state(s);
}
}
- DBUG_VOID_RETURN;
+ DBUG_RETURN(FALSE);
}
/*
TODO: this function is here only temporarily until 'greedy_search' is
tested and accepted.
+
+ RETURN VALUES
+ FALSE ok
+ TRUE Fatal error
*/
-static void
+static bool
find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
double read_time)
{
+ DBUG_ENTER("find_best");
THD *thd= join->thd;
+ if (thd->killed)
+ DBUG_RETURN(TRUE);
if (!rest_tables)
{
DBUG_PRINT("best",("read_time: %g record_count: %g",read_time,
@@ -5032,10 +5047,10 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
sizeof(POSITION)*idx);
join->best_read= read_time - 0.001;
}
- return;
+ DBUG_RETURN(FALSE);
}
if (read_time+record_count/(double) TIME_FOR_COMPARE >= join->best_read)
- return; /* Found better before */
+ DBUG_RETURN(FALSE); /* Found better before */
JOIN_TAB *s;
double best_record_count=DBL_MAX,best_read_time=DBL_MAX;
@@ -5068,10 +5083,9 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
best_read_time=current_read_time;
}
swap_variables(JOIN_TAB*, join->best_ref[idx], *pos);
- find_best(join,rest_tables & ~real_table_bit,idx+1,
- current_record_count,current_read_time);
- if (thd->killed)
- return;
+ if (find_best(join,rest_tables & ~real_table_bit,idx+1,
+ current_record_count,current_read_time))
+ DBUG_RETURN(TRUE);
swap_variables(JOIN_TAB*, join->best_ref[idx], *pos);
}
restore_prev_nj_state(s);
@@ -5079,6 +5093,7 @@ find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
break; // Don't test all combinations
}
}
+ DBUG_RETURN(FALSE);
}