Skip to content

Commit 66e44af

Browse files
committed
Merge 10.4 into 10.5
2 parents 5fffdbc + f404911 commit 66e44af

File tree

16 files changed

+204
-26
lines changed

16 files changed

+204
-26
lines changed

libmysqld/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,23 @@ ${SSL_INTERNAL_INCLUDE_DIRS}
3030
)
3131

3232
SET(GEN_SOURCES
33-
${CMAKE_BINARY_DIR}/sql/sql_yacc.hh
33+
${CMAKE_BINARY_DIR}/sql/sql_yacc.hh
3434
${CMAKE_BINARY_DIR}/sql/yy_mariadb.cc
3535
${CMAKE_BINARY_DIR}/sql/yy_oracle.hh
3636
${CMAKE_BINARY_DIR}/sql/yy_oracle.cc
37-
${CMAKE_BINARY_DIR}/sql/lex_hash.h
37+
${CMAKE_BINARY_DIR}/sql/lex_hash.h
3838
)
3939

4040
SET_SOURCE_FILES_PROPERTIES(${GEN_SOURCES} PROPERTIES GENERATED TRUE)
4141

42+
IF(CMAKE_C_COMPILER_ID MATCHES "Clang" AND
43+
NOT CMAKE_C_COMPILER_VERSION VERSION_LESS "13.0.0")
44+
ADD_COMPILE_FLAGS(
45+
${CMAKE_BINARY_DIR}/sql/yy_mariadb.cc
46+
${CMAKE_BINARY_DIR}/sql/yy_oracle.cc
47+
COMPILE_FLAGS "-Wno-unused-but-set-variable")
48+
ENDIF()
49+
4250
SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
4351
libmysql.c ../sql-common/errmsg.c
4452
../sql-common/client.c

mysql-test/suite/gcol/r/innodb_virtual_index.result

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
SET default_storage_engine= innodb;
12
SET @saved_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency;
23
SET GLOBAL innodb_purge_rseg_truncate_frequency = 1;
34
#
@@ -248,12 +249,15 @@ ENGINE=InnoDB;
248249
INSERT IGNORE INTO t1 (a,b) VALUES(1,20190132);
249250
Warnings:
250251
Warning 1265 Data truncated for column 'vb' at row 1
252+
SELECT * FROM t1;
253+
a b vb
254+
1 20190132 0000-00-00
251255
BEGIN;
252256
DELETE FROM t1;
253257
INSERT INTO t1 (a,b) VALUES(1,20190123);
254-
ERROR 22007: Incorrect date value: '20190132' for column `test`.`t1`.`vb` at row 1
255258
SELECT * FROM t1;
256259
a b vb
260+
1 20190123 2019-01-23
257261
ROLLBACK;
258262
SELECT * FROM t1;
259263
a b vb
@@ -310,3 +314,62 @@ ALTER TABLE t1 ADD KEY (b), ALGORITHM=INPLACE;
310314
# Cleanup
311315
DROP TABLE t1;
312316
# End of 10.2 tests
317+
#
318+
# MDEV-29299 SELECT from table with vcol index reports warning
319+
#
320+
CREATE TABLE t(fld1 INT NOT NULL,
321+
fld2 INT AS (100/fld1) VIRTUAL,
322+
KEY(fld1), KEY(fld2));
323+
CREATE TABLE t_odd(id int);
324+
INSERT INTO t(fld1) VALUES(1), (2);
325+
connect stop_purge,localhost,root;
326+
START TRANSACTION WITH CONSISTENT SNAPSHOT;
327+
INSERT INTO t_odd VALUES(10000);
328+
connection default;
329+
UPDATE IGNORE t SET fld1= 3 WHERE fld1= 2;
330+
UPDATE IGNORE t SET fld1= 4 WHERE fld1= 3;
331+
UPDATE IGNORE t SET fld1= 0 WHERE fld1= 4;
332+
Warnings:
333+
Warning 1365 Division by 0
334+
SELECT fld2 FROM t FORCE INDEX(fld2);
335+
fld2
336+
NULL
337+
100
338+
SELECT fld2 FROM t FORCE INDEX(fld1);
339+
fld2
340+
100
341+
NULL
342+
Warnings:
343+
Warning 1365 Division by 0
344+
disconnect stop_purge;
345+
DROP TABLE t, t_odd;
346+
#
347+
# MDEV-29753 An error is wrongly reported during INSERT with vcol index
348+
# See also Bug #22990029
349+
#
350+
CREATE TABLE t(pk INT PRIMARY KEY,
351+
fld1 INT NOT NULL,
352+
fld2 INT AS (100/fld1) VIRTUAL,
353+
KEY(fld1), KEY(fld2));
354+
INSERT IGNORE t(pk, fld1) VALUES(1, 0);
355+
Warnings:
356+
Warning 1365 Division by 0
357+
SELECT * FROM t;
358+
pk fld1 fld2
359+
1 0 NULL
360+
Warnings:
361+
Warning 1365 Division by 0
362+
BEGIN;
363+
DELETE FROM t;
364+
Warnings:
365+
Warning 1365 Division by 0
366+
Warning 1365 Division by 0
367+
Warning 1365 Division by 0
368+
INSERT INTO t (pk, fld1) VALUES(1,1);
369+
SELECT * FROM t;
370+
pk fld1 fld2
371+
1 1 100
372+
# Cleanup
373+
ROLLBACK;
374+
DROP TABLE t;
375+
# End of 10.3 tests

mysql-test/suite/gcol/t/innodb_virtual_index.test

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
--source include/have_innodb.inc
22
--source include/have_sequence.inc
33

4+
SET default_storage_engine= innodb;
5+
46
# Ensure that the history list length will actually be decremented by purge.
57
SET @saved_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency;
68
SET GLOBAL innodb_purge_rseg_truncate_frequency = 1;
@@ -273,9 +275,9 @@ DROP TABLE t1;
273275
CREATE TABLE t1(a INT PRIMARY KEY, b INT, vb DATE AS(b) VIRTUAL, KEY(vb))
274276
ENGINE=InnoDB;
275277
INSERT IGNORE INTO t1 (a,b) VALUES(1,20190132);
278+
SELECT * FROM t1;
276279
BEGIN;
277280
DELETE FROM t1;
278-
--error ER_TRUNCATED_WRONG_VALUE
279281
INSERT INTO t1 (a,b) VALUES(1,20190123);
280282
SELECT * FROM t1;
281283
ROLLBACK;
@@ -334,3 +336,49 @@ DROP TABLE t1;
334336

335337
--echo # End of 10.2 tests
336338

339+
--echo #
340+
--echo # MDEV-29299 SELECT from table with vcol index reports warning
341+
--echo #
342+
343+
CREATE TABLE t(fld1 INT NOT NULL,
344+
fld2 INT AS (100/fld1) VIRTUAL,
345+
KEY(fld1), KEY(fld2));
346+
CREATE TABLE t_odd(id int);
347+
INSERT INTO t(fld1) VALUES(1), (2);
348+
349+
--connect stop_purge,localhost,root
350+
# This prevents purge for records in t
351+
START TRANSACTION WITH CONSISTENT SNAPSHOT;
352+
INSERT INTO t_odd VALUES(10000);
353+
354+
--connection default
355+
UPDATE IGNORE t SET fld1= 3 WHERE fld1= 2;
356+
UPDATE IGNORE t SET fld1= 4 WHERE fld1= 3;
357+
UPDATE IGNORE t SET fld1= 0 WHERE fld1= 4;
358+
SELECT fld2 FROM t FORCE INDEX(fld2);
359+
SELECT fld2 FROM t FORCE INDEX(fld1);
360+
361+
--disconnect stop_purge
362+
DROP TABLE t, t_odd;
363+
364+
--echo #
365+
--echo # MDEV-29753 An error is wrongly reported during INSERT with vcol index
366+
--echo # See also Bug #22990029
367+
--echo #
368+
369+
CREATE TABLE t(pk INT PRIMARY KEY,
370+
fld1 INT NOT NULL,
371+
fld2 INT AS (100/fld1) VIRTUAL,
372+
KEY(fld1), KEY(fld2));
373+
INSERT IGNORE t(pk, fld1) VALUES(1, 0);
374+
SELECT * FROM t;
375+
BEGIN;
376+
DELETE FROM t;
377+
INSERT INTO t (pk, fld1) VALUES(1,1);
378+
SELECT * FROM t;
379+
380+
--echo # Cleanup
381+
ROLLBACK;
382+
DROP TABLE t;
383+
384+
--echo # End of 10.3 tests

sql/mysqld.cc

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3708,14 +3708,24 @@ static int init_common_variables()
37083708
if (ignore_db_dirs_init())
37093709
exit(1);
37103710

3711-
#ifdef _WIN32
3712-
get_win_tzname(system_time_zone, sizeof(system_time_zone));
3713-
#elif defined(HAVE_TZNAME)
37143711
struct tm tm_tmp;
3715-
localtime_r(&server_start_time,&tm_tmp);
3716-
const char *tz_name= tzname[tm_tmp.tm_isdst != 0 ? 1 : 0];
3717-
strmake_buf(system_time_zone, tz_name);
3718-
#endif /* HAVE_TZNAME */
3712+
localtime_r(&server_start_time, &tm_tmp);
3713+
3714+
#ifdef HAVE_TZNAME
3715+
#ifdef _WIN32
3716+
/*
3717+
If env.variable TZ is set, derive timezone name from it.
3718+
Otherwise, use IANA tz name from get_win_tzname.
3719+
*/
3720+
if (!getenv("TZ"))
3721+
get_win_tzname(system_time_zone, sizeof(system_time_zone));
3722+
else
3723+
#endif
3724+
{
3725+
const char *tz_name= tzname[tm_tmp.tm_isdst != 0 ? 1 : 0];
3726+
strmake_buf(system_time_zone, tz_name);
3727+
}
3728+
#endif
37193729

37203730
/*
37213731
We set SYSTEM time zone as reasonable default and

sql/sql_class.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,21 @@ class MDL_deadlock_and_lock_abort_error_handler: public Internal_error_handler
19701970
};
19711971

19721972

1973+
struct Suppress_warnings_error_handler : public Internal_error_handler
1974+
{
1975+
bool handle_condition(THD *thd,
1976+
uint sql_errno,
1977+
const char *sqlstate,
1978+
Sql_condition::enum_warning_level *level,
1979+
const char *msg,
1980+
Sql_condition **cond_hdl)
1981+
{
1982+
return *level == Sql_condition::WARN_LEVEL_WARN;
1983+
}
1984+
};
1985+
1986+
1987+
19731988
/**
19741989
Tables that were locked with LOCK TABLES statement.
19751990

sql/table.cc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8794,12 +8794,28 @@ int TABLE::update_virtual_fields(handler *h, enum_vcol_update_mode update_mode)
87948794
DBUG_RETURN(in_use->is_error());
87958795
}
87968796

8797-
int TABLE::update_virtual_field(Field *vf)
8797+
/*
8798+
Calculate the virtual field value for a specified field.
8799+
@param vf A field to calculate
8800+
@param ignore_warnings Ignore the warnings and also make the
8801+
calculations permissive. This usually means
8802+
that a calculation is internal and is not
8803+
expected to fail.
8804+
*/
8805+
int TABLE::update_virtual_field(Field *vf, bool ignore_warnings)
87988806
{
87998807
DBUG_ENTER("TABLE::update_virtual_field");
88008808
Query_arena backup_arena;
88018809
Counting_error_handler count_errors;
8810+
Suppress_warnings_error_handler warning_handler;
88028811
in_use->push_internal_handler(&count_errors);
8812+
bool abort_on_warning;
8813+
if (ignore_warnings)
8814+
{
8815+
abort_on_warning= in_use->abort_on_warning;
8816+
in_use->abort_on_warning= false;
8817+
in_use->push_internal_handler(&warning_handler);
8818+
}
88038819
/*
88048820
TODO: this may impose memory leak until table flush.
88058821
See comment in
@@ -8813,6 +8829,13 @@ int TABLE::update_virtual_field(Field *vf)
88138829
DBUG_RESTORE_WRITE_SET(vf);
88148830
in_use->restore_active_arena(expr_arena, &backup_arena);
88158831
in_use->pop_internal_handler();
8832+
if (ignore_warnings)
8833+
{
8834+
in_use->abort_on_warning= abort_on_warning;
8835+
in_use->pop_internal_handler();
8836+
// This is an internal calculation, we expect it to always succeed
8837+
DBUG_ASSERT(count_errors.errors == 0);
8838+
}
88168839
DBUG_RETURN(count_errors.errors);
88178840
}
88188841

sql/table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ struct TABLE
16781678

16791679
uint actual_n_key_parts(KEY *keyinfo);
16801680
ulong actual_key_flags(KEY *keyinfo);
1681-
int update_virtual_field(Field *vf);
1681+
int update_virtual_field(Field *vf, bool ignore_warnings);
16821682
int update_virtual_fields(handler *h, enum_vcol_update_mode update_mode);
16831683
int update_default_fields(bool ignore_errors);
16841684
void evaluate_update_default_function();

storage/innobase/handler/ha_innodb.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20500,7 +20500,8 @@ innobase_get_computed_value(
2050020500
TABLE* mysql_table,
2050120501
byte* mysql_rec,
2050220502
const dict_table_t* old_table,
20503-
const upd_t* update)
20503+
const upd_t* update,
20504+
bool ignore_warnings)
2050420505
{
2050520506
byte rec_buf2[REC_VERSION_56_MAX_INDEX_COL_LEN];
2050620507
byte* buf;
@@ -20607,7 +20608,9 @@ innobase_get_computed_value(
2060720608

2060820609
MY_BITMAP *old_write_set = dbug_tmp_use_all_columns(mysql_table, &mysql_table->write_set);
2060920610
MY_BITMAP *old_read_set = dbug_tmp_use_all_columns(mysql_table, &mysql_table->read_set);
20610-
ret = mysql_table->update_virtual_field(mysql_table->field[col->m_col.ind]);
20611+
ret = mysql_table->update_virtual_field(
20612+
mysql_table->field[col->m_col.ind],
20613+
ignore_warnings);
2061120614
dbug_tmp_restore_column_map(&mysql_table->read_set, old_read_set);
2061220615
dbug_tmp_restore_column_map(&mysql_table->write_set, old_write_set);
2061320616

storage/innobase/include/row0mysql.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,9 @@ void innobase_report_computed_value_failed(dtuple_t *row);
921921
@param[in] old_table during ALTER TABLE, this is the old table
922922
or NULL.
923923
@param[in] update update vector for the parent row
924-
@param[in] foreign foreign key information
924+
@param[in] ignore_warnings ignore warnings during calculation. Usually
925+
means that a calculation is internal and
926+
should have no side effects.
925927
@return the field filled with computed value */
926928
dfield_t*
927929
innobase_get_computed_value(
@@ -934,8 +936,9 @@ innobase_get_computed_value(
934936
THD* thd,
935937
TABLE* mysql_table,
936938
byte* mysql_rec,
937-
const dict_table_t* old_table,
938-
const upd_t* update);
939+
const dict_table_t* old_table=NULL,
940+
const upd_t* update=NULL,
941+
bool ignore_warnings=false);
939942

940943
/** Get the computed value by supplying the base column values.
941944
@param[in,out] table the table whose virtual column

storage/innobase/include/row0upd.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ the equal ordering fields. NOTE: we compare the fields as binary strings!
150150
@param[in] offsets rec_get_offsets(rec,index), or NULL
151151
@param[in] no_sys skip the system columns
152152
DB_TRX_ID and DB_ROLL_PTR
153+
@param[in] ignore_warnings ignore warnings during vcol calculation, which
154+
means that this calculation is internal only
153155
@param[in] trx transaction (for diagnostics),
154156
or NULL
155157
@param[in] heap memory heap from which allocated
@@ -165,11 +167,12 @@ row_upd_build_difference_binary(
165167
const rec_t* rec,
166168
const rec_offs* offsets,
167169
bool no_sys,
170+
bool ignore_warnings,
168171
trx_t* trx,
169172
mem_heap_t* heap,
170173
TABLE* mysql_table,
171174
dberr_t* error)
172-
MY_ATTRIBUTE((nonnull(1,2,3,7,9), warn_unused_result));
175+
MY_ATTRIBUTE((nonnull(1,2,3,8,10), warn_unused_result));
173176
/** Apply an update vector to an index entry.
174177
@param[in,out] entry index entry to be updated; the clustered index record
175178
must be covered by a lock or a page latch to prevent

storage/innobase/row/row0ins.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ row_ins_clust_index_entry_by_modify(
305305
}
306306

307307
update = row_upd_build_difference_binary(
308-
cursor->index, entry, rec, NULL, true,
308+
cursor->index, entry, rec, NULL, true, true,
309309
thr_get_trx(thr), heap, mysql_table, &err);
310310
if (err != DB_SUCCESS) {
311311
return(err);

storage/innobase/row/row0log.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2252,7 +2252,7 @@ row_log_table_apply_update(
22522252
row, NULL, index, heap, ROW_BUILD_NORMAL);
22532253
upd_t* update = row_upd_build_difference_binary(
22542254
index, entry, btr_pcur_get_rec(&pcur), cur_offsets,
2255-
false, NULL, heap, dup->table, &error);
2255+
false, false, NULL, heap, dup->table, &error);
22562256
if (error != DB_SUCCESS) {
22572257
goto func_exit;
22582258
}

storage/innobase/row/row0sel.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ row_sel_sec_rec_is_for_clust_rec(
332332
&heap, NULL, NULL,
333333
thr_get_trx(thr)->mysql_thd,
334334
thr->prebuilt->m_mysql_table,
335-
record, NULL, NULL);
335+
record, NULL, NULL,
336+
true);
336337

337338
if (vfield == NULL) {
338339
innobase_report_computed_value_failed(row);

storage/innobase/row/row0upd.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ row_upd_build_difference_binary(
675675
const rec_t* rec,
676676
const rec_offs* offsets,
677677
bool no_sys,
678+
bool ignore_warnings,
678679
trx_t* trx,
679680
mem_heap_t* heap,
680681
TABLE* mysql_table,
@@ -773,7 +774,7 @@ row_upd_build_difference_binary(
773774
dfield_t* vfield = innobase_get_computed_value(
774775
update->old_vrow, col, index,
775776
&vc.heap, heap, NULL, thd, mysql_table, record,
776-
NULL, NULL);
777+
NULL, NULL, ignore_warnings);
777778
if (vfield == NULL) {
778779
*error = DB_COMPUTE_VALUE_FAILED;
779780
return(NULL);

0 commit comments

Comments
 (0)