Skip to content

Commit 083279f

Browse files
committed
Merge commit '6b8802e8dd5467556a024d807a1df23940b00895' into bb-10.3-fix_len_dec
2 parents 0121d5a + 6b8802e commit 083279f

27 files changed

+892
-592
lines changed

mysql-test/main/alter_table.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,5 +2380,16 @@ t1 CREATE TABLE `t1` (
23802380
) ENGINE=MyISAM DEFAULT CHARSET=latin1
23812381
drop table t1;
23822382
#
2383+
# MDEV-11071: Assertion `thd->transaction.stmt.is_empty()' failed
2384+
# in Locked_tables_list::unlock_locked_tables
2385+
#
2386+
CREATE TABLE t1 (d DATETIME DEFAULT CURRENT_TIMESTAMP, i INT) ENGINE=InnoDB;
2387+
INSERT INTO t1 (i) VALUES (1),(1);
2388+
LOCK TABLE t1 WRITE;
2389+
ALTER TABLE t1 ADD UNIQUE(i);
2390+
ERROR 23000: Duplicate entry '1' for key 'i'
2391+
UNLOCK TABLES;
2392+
DROP TABLE t1;
2393+
#
23832394
# End of 10.2 tests
23842395
#

mysql-test/main/alter_table.test

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,22 @@ alter table t1 change b new_b int not null, add column b char(1), add constraint
19371937
show create table t1;
19381938
drop table t1;
19391939

1940+
--echo #
1941+
--echo # MDEV-11071: Assertion `thd->transaction.stmt.is_empty()' failed
1942+
--echo # in Locked_tables_list::unlock_locked_tables
1943+
--echo #
1944+
1945+
CREATE TABLE t1 (d DATETIME DEFAULT CURRENT_TIMESTAMP, i INT) ENGINE=InnoDB;
1946+
INSERT INTO t1 (i) VALUES (1),(1);
1947+
LOCK TABLE t1 WRITE;
1948+
--error ER_DUP_ENTRY
1949+
ALTER TABLE t1 ADD UNIQUE(i);
1950+
1951+
# Cleanup
1952+
UNLOCK TABLES;
1953+
DROP TABLE t1;
1954+
1955+
19401956
--echo #
19411957
--echo # End of 10.2 tests
19421958
--echo #

sql/item.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4674,7 +4674,7 @@ class Item_func_or_sum: public Item_result_field,
46744674
also to make printing of items inherited from Item_sum uniform.
46754675
*/
46764676
virtual const char *func_name() const= 0;
4677-
virtual void fix_length_and_dec()= 0;
4677+
virtual bool fix_length_and_dec()= 0;
46784678
bool const_item() const { return const_item_cache; }
46794679
table_map used_tables() const { return used_tables_cache; }
46804680
Item* build_clone(THD *thd);

sql/item_cmpfunc.cc

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ bool Item_func::setup_args_and_comparator(THD *thd, Arg_comparator *cmp)
449449
}
450450

451451

452-
void Item_bool_rowready_func2::fix_length_and_dec()
452+
bool Item_bool_rowready_func2::fix_length_and_dec()
453453
{
454454
max_length= 1; // Function returns 0 or 1
455455

@@ -458,8 +458,8 @@ void Item_bool_rowready_func2::fix_length_and_dec()
458458
we have to check for out of memory conditions here
459459
*/
460460
if (!args[0] || !args[1])
461-
return;
462-
setup_args_and_comparator(current_thd, &cmp);
461+
return FALSE;
462+
return setup_args_and_comparator(current_thd, &cmp);
463463
}
464464

465465

@@ -1107,12 +1107,13 @@ int Arg_comparator::compare_e_str_json()
11071107
}
11081108

11091109

1110-
void Item_func_truth::fix_length_and_dec()
1110+
bool Item_func_truth::fix_length_and_dec()
11111111
{
11121112
maybe_null= 0;
11131113
null_value= 0;
11141114
decimals= 0;
11151115
max_length= 1;
1116+
return FALSE;
11161117
}
11171118

11181119

@@ -1731,10 +1732,11 @@ longlong Item_func_eq::val_int()
17311732

17321733
/** Same as Item_func_eq, but NULL = NULL. */
17331734

1734-
void Item_func_equal::fix_length_and_dec()
1735+
bool Item_func_equal::fix_length_and_dec()
17351736
{
1736-
Item_bool_rowready_func2::fix_length_and_dec();
1737+
bool rc= Item_bool_rowready_func2::fix_length_and_dec();
17371738
maybe_null=null_value=0;
1739+
return rc;
17381740
}
17391741

17401742
longlong Item_func_equal::val_int()
@@ -1831,7 +1833,7 @@ bool Item_func_interval::fix_fields(THD *thd, Item **ref)
18311833
}
18321834

18331835

1834-
void Item_func_interval::fix_length_and_dec()
1836+
bool Item_func_interval::fix_length_and_dec()
18351837
{
18361838
uint rows= row->cols();
18371839

@@ -1849,10 +1851,13 @@ void Item_func_interval::fix_length_and_dec()
18491851
not_null_consts&= el->const_item() && !el->is_null();
18501852
}
18511853

1852-
if (not_null_consts &&
1853-
(intervals= (interval_range*) current_thd->alloc(sizeof(interval_range) *
1854-
(rows - 1))))
1854+
if (not_null_consts)
18551855
{
1856+
intervals= (interval_range*) current_thd->alloc(sizeof(interval_range) *
1857+
(rows - 1));
1858+
if (!intervals)
1859+
return TRUE;
1860+
18561861
if (use_decimal_comparison)
18571862
{
18581863
for (uint i= 1; i < rows; i++)
@@ -1893,6 +1898,7 @@ void Item_func_interval::fix_length_and_dec()
18931898
with_sum_func= with_sum_func || row->with_sum_func;
18941899
with_param= with_param || row->with_param;
18951900
with_field= with_field || row->with_field;
1901+
return FALSE;
18961902
}
18971903

18981904

@@ -2053,7 +2059,7 @@ void Item_func_between::fix_after_pullout(st_select_lex *new_parent,
20532059
eval_not_null_tables(NULL);
20542060
}
20552061

2056-
void Item_func_between::fix_length_and_dec()
2062+
bool Item_func_between::fix_length_and_dec()
20572063
{
20582064
max_length= 1;
20592065

@@ -2062,15 +2068,16 @@ void Item_func_between::fix_length_and_dec()
20622068
we have to check for out of memory conditions here
20632069
*/
20642070
if (!args[0] || !args[1] || !args[2])
2065-
return;
2071+
return TRUE;
20662072
if (m_comparator.aggregate_for_comparison(Item_func_between::func_name(),
20672073
args, 3, true))
20682074
{
20692075
DBUG_ASSERT(current_thd->is_error());
2070-
return;
2076+
return TRUE;
20712077
}
20722078

2073-
m_comparator.type_handler()->Item_func_between_fix_length_and_dec(this);
2079+
return m_comparator.type_handler()->
2080+
Item_func_between_fix_length_and_dec(this);
20742081
}
20752082

20762083

@@ -2093,7 +2100,7 @@ bool Item_func_between::fix_length_and_dec_numeric(THD *thd)
20932100
}
20942101
}
20952102
}
2096-
return false;
2103+
return FALSE;
20972104
}
20982105

20992106

@@ -2455,7 +2462,7 @@ void Item_func_nullif::update_used_tables()
24552462

24562463

24572464

2458-
void
2465+
bool
24592466
Item_func_nullif::fix_length_and_dec()
24602467
{
24612468
/*
@@ -2605,6 +2612,8 @@ Item_func_nullif::fix_length_and_dec()
26052612
m_cache= args[0]->cmp_type() == STRING_RESULT ?
26062613
new (thd->mem_root) Item_cache_str_for_nullif(thd, args[0]) :
26072614
args[0]->get_cache(thd);
2615+
if (!m_cache)
2616+
return TRUE;
26082617
m_cache->setup(thd, args[0]);
26092618
m_cache->store(args[0]);
26102619
m_cache->set_used_tables(args[0]->used_tables());
@@ -2618,7 +2627,8 @@ Item_func_nullif::fix_length_and_dec()
26182627
fix_char_length(args[2]->max_char_length());
26192628
maybe_null=1;
26202629
m_arg0= args[0];
2621-
setup_args_and_comparator(thd, &cmp);
2630+
if (setup_args_and_comparator(thd, &cmp))
2631+
return TRUE;
26222632
/*
26232633
A special code for EXECUTE..PREPARE.
26242634
@@ -2658,6 +2668,7 @@ Item_func_nullif::fix_length_and_dec()
26582668
*/
26592669
if (args[0] == m_arg0)
26602670
m_arg0= NULL;
2671+
return FALSE;
26612672
}
26622673

26632674

@@ -3053,26 +3064,26 @@ bool Item_func_case_simple::prepare_predicant_and_values(THD *thd,
30533064
}
30543065

30553066

3056-
void Item_func_case_searched::fix_length_and_dec()
3067+
bool Item_func_case_searched::fix_length_and_dec()
30573068
{
30583069
THD *thd= current_thd;
3059-
aggregate_then_and_else_arguments(thd, when_count());
3070+
return aggregate_then_and_else_arguments(thd, when_count());
30603071
}
30613072

30623073

3063-
void Item_func_case_simple::fix_length_and_dec()
3074+
bool Item_func_case_simple::fix_length_and_dec()
30643075
{
30653076
THD *thd= current_thd;
3066-
if (!aggregate_then_and_else_arguments(thd, when_count() + 1))
3067-
aggregate_switch_and_when_arguments(thd, false);
3077+
return (aggregate_then_and_else_arguments(thd, when_count() + 1) ||
3078+
aggregate_switch_and_when_arguments(thd, false));
30683079
}
30693080

30703081

3071-
void Item_func_decode_oracle::fix_length_and_dec()
3082+
bool Item_func_decode_oracle::fix_length_and_dec()
30723083
{
30733084
THD *thd= current_thd;
3074-
if (!aggregate_then_and_else_arguments(thd, when_count() + 1))
3075-
aggregate_switch_and_when_arguments(thd, true);
3085+
return (aggregate_then_and_else_arguments(thd, when_count() + 1) ||
3086+
aggregate_switch_and_when_arguments(thd, true));
30763087
}
30773088

30783089

@@ -4178,7 +4189,7 @@ bool Item_func_in::prepare_predicant_and_values(THD *thd, uint *found_types)
41784189
}
41794190

41804191

4181-
void Item_func_in::fix_length_and_dec()
4192+
bool Item_func_in::fix_length_and_dec()
41824193
{
41834194
THD *thd= current_thd;
41844195
uint found_types;
@@ -4188,25 +4199,28 @@ void Item_func_in::fix_length_and_dec()
41884199
if (prepare_predicant_and_values(thd, &found_types))
41894200
{
41904201
DBUG_ASSERT(thd->is_error()); // Must set error
4191-
return;
4202+
return TRUE;
41924203
}
41934204

41944205
if (arg_types_compatible) // Bisection condition #1
41954206
{
4196-
m_comparator.type_handler()->
4197-
Item_func_in_fix_comparator_compatible_types(thd, this);
4207+
if (m_comparator.type_handler()->
4208+
Item_func_in_fix_comparator_compatible_types(thd, this))
4209+
return TRUE;
41984210
}
41994211
else
42004212
{
42014213
DBUG_ASSERT(m_comparator.cmp_type() != ROW_RESULT);
4202-
fix_for_scalar_comparison_using_cmp_items(thd, found_types);
4214+
if ( fix_for_scalar_comparison_using_cmp_items(thd, found_types))
4215+
return TRUE;
42034216
}
42044217

42054218
DBUG_EXECUTE_IF("Item_func_in",
42064219
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
42074220
ER_UNKNOWN_ERROR, "DBUG: types_compatible=%s bisect=%s",
42084221
arg_types_compatible ? "yes" : "no",
42094222
array != NULL ? "yes" : "no"););
4223+
return FALSE;
42104224
}
42114225

42124226

@@ -4634,7 +4648,8 @@ Item_cond::fix_fields(THD *thd, Item **ref)
46344648
with_window_func|= item->with_window_func;
46354649
maybe_null|= item->maybe_null;
46364650
}
4637-
fix_length_and_dec();
4651+
if (fix_length_and_dec())
4652+
return TRUE;
46384653
fixed= 1;
46394654
return FALSE;
46404655
}
@@ -5669,16 +5684,16 @@ bool Item_func_regex::fix_fields(THD *thd, Item **ref)
56695684
return Item_bool_func::fix_fields(thd, ref);
56705685
}
56715686

5672-
void
5687+
bool
56735688
Item_func_regex::fix_length_and_dec()
56745689
{
5675-
Item_bool_func::fix_length_and_dec();
5676-
5677-
if (agg_arg_charsets_for_comparison(cmp_collation, args, 2))
5678-
return;
5690+
if (Item_bool_func::fix_length_and_dec() ||
5691+
agg_arg_charsets_for_comparison(cmp_collation, args, 2))
5692+
return TRUE;
56795693

56805694
re.init(cmp_collation.collation, 0);
56815695
re.fix_owner(this, args[0], args[1]);
5696+
return FALSE;
56825697
}
56835698

56845699

@@ -5702,15 +5717,16 @@ bool Item_func_regexp_instr::fix_fields(THD *thd, Item **ref)
57025717
}
57035718

57045719

5705-
void
5720+
bool
57065721
Item_func_regexp_instr::fix_length_and_dec()
57075722
{
57085723
if (agg_arg_charsets_for_comparison(cmp_collation, args, 2))
5709-
return;
5724+
return TRUE;
57105725

57115726
re.init(cmp_collation.collation, 0);
57125727
re.fix_owner(this, args[0], args[1]);
57135728
max_length= MY_INT32_NUM_DECIMAL_DIGITS; // See also Item_func_locate
5729+
return FALSE;
57145730
}
57155731

57165732

@@ -6653,7 +6669,8 @@ bool Item_equal::fix_fields(THD *thd, Item **ref)
66536669
}
66546670
if (prev_equal_field && last_equal_field != first_equal_field)
66556671
last_equal_field->next_equal_field= first_equal_field;
6656-
fix_length_and_dec();
6672+
if (fix_length_and_dec())
6673+
return TRUE;
66576674
fixed= 1;
66586675
return FALSE;
66596676
}
@@ -6739,11 +6756,12 @@ longlong Item_equal::val_int()
67396756
}
67406757

67416758

6742-
void Item_equal::fix_length_and_dec()
6759+
bool Item_equal::fix_length_and_dec()
67436760
{
67446761
Item *item= get_first(NO_PARTICULAR_TAB, NULL);
67456762
const Type_handler *handler= item->type_handler();
67466763
eval_item= handler->make_cmp_item(current_thd, item->collation.collation);
6764+
return eval_item == NULL;
67476765
}
67486766

67496767

0 commit comments

Comments
 (0)