summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2021-04-14 12:32:27 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2021-04-14 12:32:27 +0300
commitd2e2d32933823623fa3598c8e2b8a5a322e435bb (patch)
tree4a0094ff26be1e985281ef008433ce1493b58ae7
parent72e0601d11ac40a27ce071cba8626612bc625e3c (diff)
parent6c3e860cbf36831c118f6ea183acbbeb3c889bed (diff)
downloadmariadb-git-d2e2d32933823623fa3598c8e2b8a5a322e435bb.tar.gz
Merge 10.5 into 10.6
-rw-r--r--CMakeLists.txt4
-rw-r--r--cmake/maintainer.cmake6
-rwxr-xr-xdebian/autobake-deb.sh9
-rw-r--r--debian/control2
-rw-r--r--debian/mariadb-server-10.6.postinst4
-rw-r--r--extra/mariabackup/backup_copy.cc14
-rw-r--r--extra/mariabackup/backup_mysql.cc8
-rw-r--r--extra/mariabackup/datasink.h6
-rw-r--r--extra/mariabackup/ds_archive.cc1
-rw-r--r--extra/mariabackup/ds_buffer.cc1
-rw-r--r--extra/mariabackup/ds_compress.cc1
-rw-r--r--extra/mariabackup/ds_local.cc6
-rw-r--r--extra/mariabackup/ds_stdout.cc1
-rw-r--r--extra/mariabackup/ds_tmpfile.cc1
-rw-r--r--extra/mariabackup/ds_xbstream.cc1
-rw-r--r--extra/mariabackup/innobackupex.cc14
-rw-r--r--extra/mariabackup/xtrabackup.cc68
-rw-r--r--extra/mariabackup/xtrabackup.h2
-rw-r--r--mysql-test/include/icp_tests.inc12
-rw-r--r--mysql-test/lib/mtr_cases.pm4
-rw-r--r--mysql-test/lib/mtr_report.pm30
-rw-r--r--mysql-test/main/derived_opt.result27
-rw-r--r--mysql-test/main/derived_opt.test33
-rw-r--r--mysql-test/main/func_group.result2
-rw-r--r--mysql-test/main/func_group.test2
-rw-r--r--mysql-test/main/group_min_max.result2
-rw-r--r--mysql-test/main/index_merge_myisam.result3
-rw-r--r--mysql-test/main/index_merge_myisam.test4
-rw-r--r--mysql-test/main/innodb_icp.result12
-rw-r--r--mysql-test/main/myisam_icp.result12
-rw-r--r--mysql-test/main/mysqldump-nl.test8
-rw-r--r--mysql-test/main/parser_not_embedded.test2
-rw-r--r--mysql-test/main/ps.result41
-rw-r--r--mysql-test/main/ps.test60
-rw-r--r--mysql-test/main/range.result11
-rw-r--r--mysql-test/main/range.test11
-rw-r--r--mysql-test/main/range_mrr_icp.result11
-rw-r--r--mysql-test/main/range_vs_index_merge.result8
-rw-r--r--mysql-test/main/range_vs_index_merge.test8
-rw-r--r--mysql-test/main/range_vs_index_merge_innodb.result8
-rw-r--r--mysql-test/main/selectivity_innodb.result2
-rw-r--r--mysql-test/main/subselect_mat_cost_bugs.result8
-rw-r--r--mysql-test/main/subselect_mat_cost_bugs.test8
-rw-r--r--mysql-test/main/userstat.result2
-rw-r--r--mysql-test/main/userstat.test2
-rwxr-xr-xmysql-test/mysql-test-run.pl10
-rw-r--r--mysql-test/suite/galera/disabled.def2
-rw-r--r--mysql-test/suite/galera/r/galera_var_sst_auth.result2
-rw-r--r--mysql-test/suite/galera/r/galera_virtual_blob.result21
-rw-r--r--mysql-test/suite/galera/t/galera_binlog_stmt_autoinc.cnf7
-rw-r--r--mysql-test/suite/galera/t/galera_var_sst_auth.cnf5
-rw-r--r--mysql-test/suite/galera/t/galera_var_sst_auth.test8
-rw-r--r--mysql-test/suite/galera/t/galera_virtual_blob.test10
-rw-r--r--mysql-test/suite/galera/t/galera_vote_rejoin_ddl.cnf6
-rw-r--r--mysql-test/suite/gcol/r/virtual_index_drop.result69
-rw-r--r--mysql-test/suite/gcol/t/virtual_index_drop.test71
-rw-r--r--mysql-test/suite/innodb/r/innodb_buffer_pool_fail.result8
-rw-r--r--mysql-test/suite/innodb/r/instant_alter_debug.result30
-rw-r--r--mysql-test/suite/innodb/t/innodb_buffer_pool_fail.test11
-rw-r--r--mysql-test/suite/innodb/t/instant_alter_debug.test38
-rw-r--r--mysql-test/suite/innodb_fts/r/fulltext.result14
-rw-r--r--mysql-test/suite/innodb_fts/t/fulltext.test16
-rw-r--r--mysql-test/suite/maria/icp.result12
-rw-r--r--mysql-test/suite/mariabackup/error_during_copyback.result10
-rw-r--r--mysql-test/suite/mariabackup/error_during_copyback.test25
-rw-r--r--mysql-test/suite/mariabackup/innodb_force_recovery.result26
-rw-r--r--mysql-test/suite/mariabackup/innodb_force_recovery.test138
-rw-r--r--mysql-test/suite/optimizer_unfixed_bugs/r/bug42991.result2
-rw-r--r--mysql-test/suite/optimizer_unfixed_bugs/t/bug42991.test4
-rw-r--r--mysql-test/suite/rpl/t/rpl_row_tbl_metadata.test2
-rw-r--r--mysql-test/suite/versioning/r/alter.result51
-rw-r--r--mysql-test/suite/versioning/r/autoinc.result (renamed from mysql-test/suite/versioning/r/auto_increment.result)10
-rw-r--r--mysql-test/suite/versioning/t/alter.test40
-rw-r--r--mysql-test/suite/versioning/t/autoinc.test (renamed from mysql-test/suite/versioning/t/auto_increment.test)13
-rw-r--r--mysys/CMakeLists.txt32
-rw-r--r--mysys/crc32/crc32_x86.c28
-rw-r--r--mysys/crc32/crc32c.cc955
-rw-r--r--mysys/crc32/crc32c_amd64.cc711
-rw-r--r--mysys/crc32ieee.cc20
-rw-r--r--plugin/userstat/index_stats.cc2
-rw-r--r--scripts/mysql_setpermission.sh45
-rw-r--r--scripts/wsrep_sst_mariabackup.sh4
-rw-r--r--sql/handler.cc25
-rw-r--r--sql/item.cc33
-rw-r--r--sql/item.h3
-rw-r--r--sql/item_cmpfunc.h6
-rw-r--r--sql/item_subselect.h3
-rw-r--r--sql/opt_range.cc70
-rw-r--r--sql/spatial.cc22
-rw-r--r--sql/sql_base.cc2
-rw-r--r--sql/sql_lex.cc10
-rw-r--r--sql/sql_lex.h3
-rw-r--r--sql/sql_parse.cc14
-rw-r--r--sql/sql_prepare.cc9
-rw-r--r--sql/sql_select.cc13
-rw-r--r--sql/sql_table.cc5
-rw-r--r--sql/sql_update.cc37
-rw-r--r--sql/wsrep_trans_observer.h4
-rw-r--r--storage/innobase/btr/btr0btr.cc59
-rw-r--r--storage/innobase/btr/btr0bulk.cc28
-rw-r--r--storage/innobase/btr/btr0cur.cc34
-rw-r--r--storage/innobase/btr/btr0defragment.cc7
-rw-r--r--storage/innobase/btr/btr0pcur.cc48
-rw-r--r--storage/innobase/btr/btr0sea.cc31
-rw-r--r--storage/innobase/dict/dict0dict.cc13
-rw-r--r--storage/innobase/dict/dict0mem.cc5
-rw-r--r--storage/innobase/dict/dict0stats.cc30
-rw-r--r--storage/innobase/dict/dict0stats_bg.cc19
-rw-r--r--storage/innobase/fts/fts0fts.cc21
-rw-r--r--storage/innobase/gis/gis0rtree.cc66
-rw-r--r--storage/innobase/gis/gis0sea.cc58
-rw-r--r--storage/innobase/handler/ha_innodb.cc12
-rw-r--r--storage/innobase/handler/handler0alter.cc92
-rw-r--r--storage/innobase/ibuf/ibuf0ibuf.cc9
-rw-r--r--storage/innobase/include/btr0bulk.h2
-rw-r--r--storage/innobase/include/btr0pcur.h6
-rw-r--r--storage/innobase/include/dict0mem.h73
-rw-r--r--storage/innobase/include/gis0rtree.ic5
-rw-r--r--storage/innobase/include/page0cur.ic5
-rw-r--r--storage/innobase/include/rem0rec.h10
-rw-r--r--storage/innobase/include/row0merge.h20
-rw-r--r--storage/innobase/lock/lock0lock.cc14
-rw-r--r--storage/innobase/page/page0cur.cc36
-rw-r--r--storage/innobase/page/page0page.cc34
-rw-r--r--storage/innobase/page/page0zip.cc30
-rw-r--r--storage/innobase/rem/rem0rec.cc86
-rw-r--r--storage/innobase/row/row0ftsort.cc6
-rw-r--r--storage/innobase/row/row0import.cc3
-rw-r--r--storage/innobase/row/row0ins.cc26
-rw-r--r--storage/innobase/row/row0log.cc11
-rw-r--r--storage/innobase/row/row0merge.cc34
-rw-r--r--storage/innobase/row/row0mysql.cc17
-rw-r--r--storage/innobase/row/row0purge.cc12
-rw-r--r--storage/innobase/row/row0row.cc10
-rw-r--r--storage/innobase/row/row0sel.cc57
-rw-r--r--storage/innobase/row/row0uins.cc3
-rw-r--r--storage/innobase/row/row0umod.cc16
-rw-r--r--storage/innobase/row/row0undo.cc3
-rw-r--r--storage/innobase/row/row0upd.cc22
-rw-r--r--storage/innobase/row/row0vers.cc38
-rw-r--r--storage/innobase/srv/srv0start.cc2
-rw-r--r--storage/innobase/trx/trx0i_s.cc3
-rw-r--r--storage/innobase/trx/trx0rec.cc3
-rw-r--r--storage/innobase/trx/trx0sys.cc2
-rw-r--r--storage/innobase/ut/ut0ut.cc4
145 files changed, 2828 insertions, 1496 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 579c8a21783..72b9f8611ab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (c) 2006, 2017, Oracle and/or its affiliates.
-# Copyright (c) 2008, 2020, MariaDB Corporation.
+# Copyright (c) 2008, 2021, MariaDB Corporation.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -140,7 +140,7 @@ ENDIF()
# NUMA
SET(WITH_NUMA "AUTO" CACHE STRING "Build with non-uniform memory access, allowing --innodb-numa-interleave. Options are ON|OFF|AUTO. ON = enabled (requires NUMA library), OFF = disabled, AUTO = enabled if NUMA library found.")
-SET(MYSQL_MAINTAINER_MODE "AUTO" CACHE STRING "MySQL maintainer-specific development environment. Options are: ON OFF AUTO.")
+SET(MYSQL_MAINTAINER_MODE "AUTO" CACHE STRING "Enable MariaDB maintainer-specific warnings. One of: NO (warnings are disabled) WARN (warnings are enabled) ERR (warnings are errors) AUTO (warnings are errors in Debug only)")
# Packaging
IF (NOT CPACK_GENERATOR)
diff --git a/cmake/maintainer.cmake b/cmake/maintainer.cmake
index f50fea22563..0df943be863 100644
--- a/cmake/maintainer.cmake
+++ b/cmake/maintainer.cmake
@@ -1,5 +1,5 @@
# Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
-# Copyright (c) 2020, MariaDB
+# Copyright (c) 2011, 2021, MariaDB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -14,7 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
-IF(MSVC)
+IF(MYSQL_MAINTAINER_MODE STREQUAL "NO")
RETURN()
ENDIF()
@@ -50,7 +50,7 @@ IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION VERSION_LESS "6.0.0")
SET(MY_ERROR_FLAGS ${MY_ERROR_FLAGS} -Wno-error=maybe-uninitialized)
ENDIF()
-IF(MYSQL_MAINTAINER_MODE MATCHES "OFF")
+IF(MYSQL_MAINTAINER_MODE MATCHES "OFF|WARN")
RETURN()
ELSEIF(MYSQL_MAINTAINER_MODE MATCHES "AUTO")
SET(WHERE DEBUG)
diff --git a/debian/autobake-deb.sh b/debian/autobake-deb.sh
index a5677c7fd8c..09db5dc23cb 100755
--- a/debian/autobake-deb.sh
+++ b/debian/autobake-deb.sh
@@ -82,6 +82,15 @@ then
sed "/Package: mariadb-plugin-rocksdb/,/^$/d" -i debian/control
fi
+# From Debian Stretch/Ubuntu Bionic onwards dh-systemd is just an empty
+# transitional metapackage and the functionality was merged into debhelper.
+# In Ubuntu Hirsute is was completely removed, so it can't be referenced anymore.
+# Keep using it only on Debian Jessie and Ubuntu Xenial.
+if apt-cache madison dh-systemd | grep 'dh-systemd' >/dev/null 2>&1
+then
+ sed 's/debhelper (>= 9.20160709~),/debhelper (>= 9), dh-systemd,/' -i debian/control
+fi
+
# If rocksdb-tools is not available (before Debian Buster and Ubuntu Disco)
# remove the dependency from the RocksDB plugin so it can install properly
# and instead ship the one built from MariaDB sources
diff --git a/debian/control b/debian/control
index a005770d93b..ec38fe5f12e 100644
--- a/debian/control
+++ b/debian/control
@@ -5,7 +5,7 @@ Maintainer: MariaDB Developers <maria-developers@lists.launchpad.net>
Build-Depends: bison,
cmake,
cracklib-runtime <!nocheck>,
- debhelper (>= 9),
+ debhelper (>= 9.20160709~),
dh-exec,
dh-systemd,
flex [amd64],
diff --git a/debian/mariadb-server-10.6.postinst b/debian/mariadb-server-10.6.postinst
index 40b91505247..9b0120cb58f 100644
--- a/debian/mariadb-server-10.6.postinst
+++ b/debian/mariadb-server-10.6.postinst
@@ -238,8 +238,8 @@ EOF
;;
triggered)
- if [ -x "$(command -v systemctl)" ]; then
- systemctl daemon-reload
+ if [ -d /run/systemd/system ]; then
+ systemctl --system daemon-reload
else
invoke-rc.d mariadb restart
fi
diff --git a/extra/mariabackup/backup_copy.cc b/extra/mariabackup/backup_copy.cc
index 5f44e031245..a078daacc23 100644
--- a/extra/mariabackup/backup_copy.cc
+++ b/extra/mariabackup/backup_copy.cc
@@ -1006,6 +1006,7 @@ copy_file(ds_ctxt_t *datasink,
ds_file_t *dstfile = NULL;
datafile_cur_t cursor;
xb_fil_cur_result_t res;
+ DBUG_ASSERT(datasink->datasink->remove);
const char *dst_path =
(xtrabackup_copy_back || xtrabackup_move_back)?
dst_file_path : trim_dotslash(dst_file_path);
@@ -1031,6 +1032,7 @@ copy_file(ds_ctxt_t *datasink,
if (ds_write(dstfile, cursor.buf, cursor.buf_read)) {
goto error;
}
+ DBUG_EXECUTE_IF("copy_file_error", errno=ENOSPC;goto error;);
}
if (res == XB_FIL_CUR_ERROR) {
@@ -1048,6 +1050,7 @@ copy_file(ds_ctxt_t *datasink,
error:
datafile_close(&cursor);
if (dstfile != NULL) {
+ datasink->datasink->remove(dstfile->path);
ds_close(dstfile);
}
@@ -1092,17 +1095,18 @@ move_file(ds_ctxt_t *datasink,
if (my_rename(src_file_path, dst_file_path_abs, MYF(0)) != 0) {
if (my_errno == EXDEV) {
- bool ret;
- ret = copy_file(datasink, src_file_path,
- dst_file_path, thread_n);
+ /* Fallback to copy/unlink */
+ if(!copy_file(datasink, src_file_path,
+ dst_file_path, thread_n))
+ return false;
msg(thread_n,"Removing %s", src_file_path);
if (unlink(src_file_path) != 0) {
my_strerror(errbuf, sizeof(errbuf), errno);
- msg("Error: unlink %s failed: %s",
+ msg("Warning: unlink %s failed: %s",
src_file_path,
errbuf);
}
- return(ret);
+ return true;
}
my_strerror(errbuf, sizeof(errbuf), my_errno);
msg("Can not move file %s to %s: %s",
diff --git a/extra/mariabackup/backup_mysql.cc b/extra/mariabackup/backup_mysql.cc
index b7efd61f182..ffa23db888e 100644
--- a/extra/mariabackup/backup_mysql.cc
+++ b/extra/mariabackup/backup_mysql.cc
@@ -44,6 +44,7 @@ Street, Fifth Floor, Boston, MA 02110-1335 USA
#include <mysql.h>
#include <mysqld.h>
#include <my_sys.h>
+#include <stdlib.h>
#include <string.h>
#include <limits>
#include "common.h"
@@ -108,6 +109,13 @@ xb_mysql_connect()
return(NULL);
}
+#if !defined(DONT_USE_MYSQL_PWD)
+ if (!opt_password)
+ {
+ opt_password=getenv("MYSQL_PWD");
+ }
+#endif
+
if (!opt_secure_auth) {
mysql_options(connection, MYSQL_SECURE_AUTH,
(char *) &opt_secure_auth);
diff --git a/extra/mariabackup/datasink.h b/extra/mariabackup/datasink.h
index 201bbfd3267..5c82556b9ba 100644
--- a/extra/mariabackup/datasink.h
+++ b/extra/mariabackup/datasink.h
@@ -50,9 +50,15 @@ struct datasink_struct {
ds_file_t *(*open)(ds_ctxt_t *ctxt, const char *path, MY_STAT *stat);
int (*write)(ds_file_t *file, const unsigned char *buf, size_t len);
int (*close)(ds_file_t *file);
+ int (*remove)(const char *path);
void (*deinit)(ds_ctxt_t *ctxt);
};
+
+static inline int dummy_remove(const char *) {
+ return 0;
+}
+
/* Supported datasink types */
typedef enum {
DS_TYPE_STDOUT,
diff --git a/extra/mariabackup/ds_archive.cc b/extra/mariabackup/ds_archive.cc
index c8fcfa1f5f5..3a5081119b3 100644
--- a/extra/mariabackup/ds_archive.cc
+++ b/extra/mariabackup/ds_archive.cc
@@ -57,6 +57,7 @@ datasink_t datasink_archive = {
&archive_open,
&archive_write,
&archive_close,
+ &dummy_remove,
&archive_deinit
};
diff --git a/extra/mariabackup/ds_buffer.cc b/extra/mariabackup/ds_buffer.cc
index 308070ab3b3..d6a420951cb 100644
--- a/extra/mariabackup/ds_buffer.cc
+++ b/extra/mariabackup/ds_buffer.cc
@@ -54,6 +54,7 @@ datasink_t datasink_buffer = {
&buffer_open,
&buffer_write,
&buffer_close,
+ &dummy_remove,
&buffer_deinit
};
diff --git a/extra/mariabackup/ds_compress.cc b/extra/mariabackup/ds_compress.cc
index 54c49deac16..960bc766b1e 100644
--- a/extra/mariabackup/ds_compress.cc
+++ b/extra/mariabackup/ds_compress.cc
@@ -75,6 +75,7 @@ datasink_t datasink_compress = {
&compress_open,
&compress_write,
&compress_close,
+ &dummy_remove,
&compress_deinit
};
diff --git a/extra/mariabackup/ds_local.cc b/extra/mariabackup/ds_local.cc
index 06b061f3646..ddaa213491d 100644
--- a/extra/mariabackup/ds_local.cc
+++ b/extra/mariabackup/ds_local.cc
@@ -43,12 +43,18 @@ static int local_write(ds_file_t *file, const uchar *buf, size_t len);
static int local_close(ds_file_t *file);
static void local_deinit(ds_ctxt_t *ctxt);
+static int local_remove(const char *path)
+{
+ return unlink(path);
+}
+
extern "C" {
datasink_t datasink_local = {
&local_init,
&local_open,
&local_write,
&local_close,
+ &local_remove,
&local_deinit
};
}
diff --git a/extra/mariabackup/ds_stdout.cc b/extra/mariabackup/ds_stdout.cc
index d30c105d258..08776e99329 100644
--- a/extra/mariabackup/ds_stdout.cc
+++ b/extra/mariabackup/ds_stdout.cc
@@ -40,6 +40,7 @@ datasink_t datasink_stdout = {
&stdout_open,
&stdout_write,
&stdout_close,
+ &dummy_remove,
&stdout_deinit
};
diff --git a/extra/mariabackup/ds_tmpfile.cc b/extra/mariabackup/ds_tmpfile.cc
index 4851c2f0263..80b9d3bb4d0 100644
--- a/extra/mariabackup/ds_tmpfile.cc
+++ b/extra/mariabackup/ds_tmpfile.cc
@@ -51,6 +51,7 @@ datasink_t datasink_tmpfile = {
&tmpfile_open,
&tmpfile_write,
&tmpfile_close,
+ &dummy_remove,
&tmpfile_deinit
};
diff --git a/extra/mariabackup/ds_xbstream.cc b/extra/mariabackup/ds_xbstream.cc
index 7522510ab27..4d165ad11d9 100644
--- a/extra/mariabackup/ds_xbstream.cc
+++ b/extra/mariabackup/ds_xbstream.cc
@@ -50,6 +50,7 @@ datasink_t datasink_xbstream = {
&xbstream_open,
&xbstream_write,
&xbstream_close,
+ &dummy_remove,
&xbstream_deinit
};
diff --git a/extra/mariabackup/innobackupex.cc b/extra/mariabackup/innobackupex.cc
index e874890ad27..aaa1ca8de91 100644
--- a/extra/mariabackup/innobackupex.cc
+++ b/extra/mariabackup/innobackupex.cc
@@ -208,7 +208,8 @@ enum innobackupex_options
OPT_STREAM,
OPT_TABLES_FILE,
OPT_THROTTLE,
- OPT_USE_MEMORY
+ OPT_USE_MEMORY,
+ OPT_INNODB_FORCE_RECOVERY,
};
ibx_mode_t ibx_mode = IBX_MODE_BACKUP;
@@ -626,6 +627,16 @@ static struct my_option ibx_long_options[] =
0, GET_LL, REQUIRED_ARG, 100*1024*1024L, 1024*1024L, LONGLONG_MAX, 0,
1024*1024L, 0},
+ {"innodb-force-recovery", OPT_INNODB_FORCE_RECOVERY,
+ "This option starts up the embedded InnoDB instance in crash "
+ "recovery mode to ignore page corruption; should be used "
+ "with the \"--apply-log\" option, in emergencies only. The "
+ "default value is 0. Refer to \"innodb_force_recovery\" server "
+ "system variable documentation for more details.",
+ (uchar*)&xtrabackup_innodb_force_recovery,
+ (uchar*)&xtrabackup_innodb_force_recovery,
+ 0, GET_ULONG, OPT_ARG, 0, 0, SRV_FORCE_IGNORE_CORRUPT, 0, 0, 0},
+
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
@@ -671,6 +682,7 @@ innobackupex [--compress] [--compress-threads=NUMBER-OF-THREADS] [--compress-chu
innobackupex --apply-log [--use-memory=B]\n\
[--defaults-file=MY.CNF]\n\
[--export] [--ibbackup=IBBACKUP-BINARY]\n\
+ [--innodb-force-recovery=1]\n\
BACKUP-DIR\n\
\n\
innobackupex --copy-back [--defaults-file=MY.CNF] [--defaults-group=GROUP-NAME] BACKUP-DIR\n\
diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc
index 5fbf9fd9892..8894544be10 100644
--- a/extra/mariabackup/xtrabackup.cc
+++ b/extra/mariabackup/xtrabackup.cc
@@ -261,6 +261,12 @@ static char *xtrabackup_debug_sync = NULL;
my_bool xtrabackup_incremental_force_scan = FALSE;
+/*
+ * Ignore corrupt pages (disabled by default; used
+ * by "innobackupex" as a command line argument).
+ */
+ulong xtrabackup_innodb_force_recovery = 0;
+
/* The flushed lsn which is read from data files */
lsn_t flushed_lsn= 0;
@@ -979,7 +985,8 @@ enum options_xtrabackup
OPT_BACKUP_ROCKSDB,
OPT_XTRA_CHECK_PRIVILEGES,
OPT_XTRA_MYSQLD_ARGS,
- OPT_XB_IGNORE_INNODB_PAGE_CORRUPTION
+ OPT_XB_IGNORE_INNODB_PAGE_CORRUPTION,
+ OPT_INNODB_FORCE_RECOVERY
};
struct my_option xb_client_options[]= {
@@ -1591,6 +1598,13 @@ struct my_option xb_server_options[] =
&opt_check_privileges, &opt_check_privileges,
0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 },
+ {"innodb_force_recovery", OPT_INNODB_FORCE_RECOVERY,
+ "(for --prepare): Crash recovery mode (ignores "
+ "page corruption; for emergencies only).",
+ (G_PTR*)&srv_force_recovery,
+ (G_PTR*)&srv_force_recovery,
+ 0, GET_ULONG, OPT_ARG, 0, 0, SRV_FORCE_IGNORE_CORRUPT, 0, 0, 0},
+
{"mysqld-args", OPT_XTRA_MYSQLD_ARGS,
"All arguments that follow this argument are considered as server "
"options, and if some of them are not supported by mariabackup, they "
@@ -1727,31 +1741,33 @@ static int prepare_export()
// Process defaults-file , it can have some --lc-language stuff,
// which is* unfortunately* still necessary to get mysqld up
- if (strncmp(orig_argv1,"--defaults-file=",16) == 0)
+ if (strncmp(orig_argv1,"--defaults-file=", 16) == 0)
{
snprintf(cmdline, sizeof cmdline,
- IF_WIN("\"","") "\"%s\" --mysqld \"%s\" "
+ IF_WIN("\"","") "\"%s\" --mysqld \"%s\""
" --defaults-extra-file=./backup-my.cnf --defaults-group-suffix=%s --datadir=."
" --innodb --innodb-fast-shutdown=0 --loose-partition"
" --innodb_purge_rseg_truncate_frequency=1 --innodb-buffer-pool-size=%llu"
- " --console --skip-log-error --skip-log-bin --bootstrap < "
+ " --console --skip-log-error --skip-log-bin --bootstrap %s< "
BOOTSTRAP_FILENAME IF_WIN("\"",""),
- mariabackup_exe,
+ mariabackup_exe,
orig_argv1, (my_defaults_group_suffix?my_defaults_group_suffix:""),
- xtrabackup_use_memory);
+ xtrabackup_use_memory,
+ (srv_force_recovery ? "--innodb-force-recovery=1 " : ""));
}
else
{
- sprintf(cmdline,
- IF_WIN("\"","") "\"%s\" --mysqld"
+ snprintf(cmdline, sizeof cmdline,
+ IF_WIN("\"","") "\"%s\" --mysqld"
" --defaults-file=./backup-my.cnf --defaults-group-suffix=%s --datadir=."
" --innodb --innodb-fast-shutdown=0 --loose-partition"
" --innodb_purge_rseg_truncate_frequency=1 --innodb-buffer-pool-size=%llu"
- " --console --log-error= --skip-log-bin --bootstrap < "
+ " --console --log-error= --skip-log-bin --bootstrap %s< "
BOOTSTRAP_FILENAME IF_WIN("\"",""),
mariabackup_exe,
(my_defaults_group_suffix?my_defaults_group_suffix:""),
- xtrabackup_use_memory);
+ xtrabackup_use_memory,
+ (srv_force_recovery ? "--innodb-force-recovery=1 " : ""));
}
msg("Prepare export : executing %s\n", cmdline);
@@ -1898,6 +1914,13 @@ xb_get_one_option(const struct my_option *opt,
ADD_PRINT_PARAM_OPT(innobase_buffer_pool_filename);
break;
+ case OPT_INNODB_FORCE_RECOVERY:
+
+ if (srv_force_recovery) {
+ ADD_PRINT_PARAM_OPT(srv_force_recovery);
+ }
+ break;
+
case OPT_XTRA_TARGET_DIR:
strmake(xtrabackup_real_target_dir,argument, sizeof(xtrabackup_real_target_dir)-1);
xtrabackup_target_dir= xtrabackup_real_target_dir;
@@ -2138,6 +2161,29 @@ static bool innodb_init_param()
srv_undo_dir = (char*) ".";
}
+ compile_time_assert(SRV_FORCE_IGNORE_CORRUPT == 1);
+
+ /*
+ * This option can be read both from the command line, and the
+ * defaults file. The assignment should account for both cases,
+ * and for "--innobackupex". Since the command line argument is
+ * parsed after the defaults file, it takes precedence.
+ */
+ if (xtrabackup_innodb_force_recovery) {
+ srv_force_recovery = xtrabackup_innodb_force_recovery;
+ }
+
+ if (srv_force_recovery >= SRV_FORCE_IGNORE_CORRUPT) {
+ if (!xtrabackup_prepare) {
+ msg("mariabackup: The option \"innodb_force_recovery\""
+ " should only be used with \"%s\".",
+ (innobackupex_mode ? "--apply-log" : "--prepare"));
+ goto error;
+ } else {
+ msg("innodb_force_recovery = %lu", srv_force_recovery);
+ }
+ }
+
#ifdef _WIN32
srv_use_native_aio = TRUE;
#endif
@@ -6342,6 +6388,8 @@ int main(int argc, char **argv)
char **client_defaults;
char **backup_defaults;
+ my_getopt_prefix_matching= 0;
+
if (get_exepath(mariabackup_exe,FN_REFLEN, argv[0]))
strncpy(mariabackup_exe,argv[0], FN_REFLEN-1);
diff --git a/extra/mariabackup/xtrabackup.h b/extra/mariabackup/xtrabackup.h
index aff7d1cb287..9842d1eb8ee 100644
--- a/extra/mariabackup/xtrabackup.h
+++ b/extra/mariabackup/xtrabackup.h
@@ -174,6 +174,8 @@ enum binlog_info_enum { BINLOG_INFO_OFF, BINLOG_INFO_ON,
extern ulong opt_binlog_info;
+extern ulong xtrabackup_innodb_force_recovery;
+
void xtrabackup_io_throttling(void);
my_bool xb_write_delta_metadata(const char *filename,
const xb_delta_info_t *info);
diff --git a/mysql-test/include/icp_tests.inc b/mysql-test/include/icp_tests.inc
index bfa09e1c01e..d78fe0dd209 100644
--- a/mysql-test/include/icp_tests.inc
+++ b/mysql-test/include/icp_tests.inc
@@ -487,11 +487,11 @@ CREATE TABLE t1 (
INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1);
-EXPLAIN SELECT pk, c1 FROM t1 WHERE pk <> 3;
+EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
SET SESSION optimizer_switch='index_condition_pushdown=off';
-SELECT pk, c1 FROM t1 WHERE pk <> 3;
+SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
DROP TABLE t1;
@@ -733,17 +733,17 @@ insert into t2 select seq from seq_1_to_100;
SET SESSION optimizer_switch='index_condition_pushdown=off';
--replace_column 9 #
EXPLAIN
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
SET SESSION optimizer_switch='index_condition_pushdown=on';
--replace_column 9 #
EXPLAIN
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
DROP TABLE t1,t2;
diff --git a/mysql-test/lib/mtr_cases.pm b/mysql-test/lib/mtr_cases.pm
index b61333535dc..dd003dea31d 100644
--- a/mysql-test/lib/mtr_cases.pm
+++ b/mysql-test/lib/mtr_cases.pm
@@ -64,8 +64,8 @@ my $plugin_suitedir_regex;
my $overlay_regex;
if (-d '../sql') {
- @plugin_suitedirs= ('storage/*/mysql-test', 'plugin/*/mysql-test');
- $overlay_regex= '\b(?:storage|plugin)/(\w+)/mysql-test\b';
+ @plugin_suitedirs= ('storage/*/mysql-test', 'plugin/*/mysql-test', 'storage/*/*/mysql-test', );
+ $overlay_regex= '\b(?:storage|plugin|storage[/][^/]*)/(\w+)/mysql-test\b';
} else {
@plugin_suitedirs= ('mysql-test/plugin/*');
$overlay_regex= '\bmysql-test/plugin/(\w+)\b';
diff --git a/mysql-test/lib/mtr_report.pm b/mysql-test/lib/mtr_report.pm
index 473b21441e2..8144a6ef02e 100644
--- a/mysql-test/lib/mtr_report.pm
+++ b/mysql-test/lib/mtr_report.pm
@@ -497,23 +497,21 @@ sub mtr_report_stats ($$$$) {
$test_time = sprintf("%.3f", $test->{timer} / 1000);
$test->{'name'} =~ s/$current_suite\.//;
- my $test_result;
-
- # if a test case has to be retried it should have the result MTR_RES_FAILED in jUnit XML
- if ($test->{'retries'} > 0) {
- $test_result = "MTR_RES_FAILED";
+ my $combinations;
+ if (defined($test->{combinations})){
+ $combinations = join ',', sort @{$test->{combinations}};
} else {
- $test_result = $test->{'result'};
+ $combinations = "";
}
- $xml_report .= qq(\t\t<testcase assertions="" classname="$current_suite" name="$test->{'name'}" status="$test_result" time="$test_time");
+ $xml_report .= qq(\t\t<testcase assertions="" classname="$current_suite" name="$test->{'name'}" ).
+ qq(status="$test->{'result'}" time="$test_time" combinations="$combinations");
- my $comment = $test->{'comment'};
- $comment =~ s/[\"]//g;
+ my $comment= replace_special_symbols($test->{'comment'});
- # if a test case has to be retried it should have the result MTR_RES_FAILED in jUnit XML
- if ($test->{'result'} eq "MTR_RES_FAILED" || $test->{'retries'} > 0) {
+ if ($test->{'result'} eq "MTR_RES_FAILED") {
my $logcontents = $test->{'logfile-failed'} || $test->{'logfile'};
+ $logcontents= $logcontents.$test->{'warnings'}."\n";
# remove any double ] that would end the cdata
$logcontents =~ s/]]/\x{fffd}/g;
# replace wide characters that aren't allowed in XML 1.0
@@ -576,6 +574,16 @@ sub mtr_print_line () {
print '-' x 74 . "\n";
}
+sub replace_special_symbols($) {
+ my $text= shift;
+ $text =~ s/&/&#38;/g;
+ $text =~ s/'/&#39;/g;
+ $text =~ s/"/&#34;/g;
+ $text =~ s/</&lt;/g;
+ $text =~ s/>/&gt;/g;
+ return $text;
+}
+
sub mtr_print_thick_line {
my $char= shift || '=';
diff --git a/mysql-test/main/derived_opt.result b/mysql-test/main/derived_opt.result
index 9da9e6e4413..cf0c1cb617f 100644
--- a/mysql-test/main/derived_opt.result
+++ b/mysql-test/main/derived_opt.result
@@ -540,4 +540,31 @@ id select_type table type possible_keys key key_len ref rows Extra
set join_cache_level=default;
set optimizer_switch= @save_optimizer_switch;
DROP TABLE t1,t2;
+set @save_optimizer_switch= @@optimizer_switch;
+set optimizer_switch="derived_merge=on";
+CREATE TABLE t1 (id int, d2 datetime, id1 int) ;
+insert into t1 values (1,'2020-01-01 10:10:10',1),(2,'2020-01-01 10:10:10',2),(3,'2020-01-01 10:10:10',3);
+CREATE TABLE t2 (id int, d1 datetime, id1 int) ;
+insert into t2 values (1,'2020-01-01 10:10:10',1),(2,'2020-01-01 10:10:10',2),(3,'2020-01-01 10:10:10',2);
+prepare stmt from "
+SELECT * from
+ (SELECT min(d2) AS d2, min(d1) AS d1 FROM
+ (SELECT t1.d2 AS d2, (SELECT t2.d1
+ FROM t2 WHERE t1.id1 = t2.id1
+ ORDER BY t2.id DESC LIMIT 1) AS d1
+ FROM t1
+ ) dt2
+ ) ca
+ ORDER BY ca.d2;";
+execute stmt;
+d2 d1
+2020-01-01 10:10:10 2020-01-01 10:10:10
+execute stmt;
+d2 d1
+2020-01-01 10:10:10 2020-01-01 10:10:10
+set optimizer_switch= @save_optimizer_switch;
+DROP TABLE t1, t2;
+#
+# End of 10.3 tests
+#
set optimizer_switch=@exit_optimizer_switch;
diff --git a/mysql-test/main/derived_opt.test b/mysql-test/main/derived_opt.test
index eccf4c13020..dee424559ee 100644
--- a/mysql-test/main/derived_opt.test
+++ b/mysql-test/main/derived_opt.test
@@ -406,5 +406,38 @@ set optimizer_switch= @save_optimizer_switch;
DROP TABLE t1,t2;
+#
+# MDEV-25182: Complex query in Store procedure corrupts results
+#
+set @save_optimizer_switch= @@optimizer_switch;
+set optimizer_switch="derived_merge=on";
+
+CREATE TABLE t1 (id int, d2 datetime, id1 int) ;
+insert into t1 values (1,'2020-01-01 10:10:10',1),(2,'2020-01-01 10:10:10',2),(3,'2020-01-01 10:10:10',3);
+
+CREATE TABLE t2 (id int, d1 datetime, id1 int) ;
+insert into t2 values (1,'2020-01-01 10:10:10',1),(2,'2020-01-01 10:10:10',2),(3,'2020-01-01 10:10:10',2);
+
+prepare stmt from "
+SELECT * from
+ (SELECT min(d2) AS d2, min(d1) AS d1 FROM
+ (SELECT t1.d2 AS d2, (SELECT t2.d1
+ FROM t2 WHERE t1.id1 = t2.id1
+ ORDER BY t2.id DESC LIMIT 1) AS d1
+ FROM t1
+ ) dt2
+ ) ca
+ ORDER BY ca.d2;";
+
+execute stmt;
+execute stmt;
+
+set optimizer_switch= @save_optimizer_switch;
+DROP TABLE t1, t2;
+
+--echo #
+--echo # End of 10.3 tests
+--echo #
+
# The following command must be the last one the file
set optimizer_switch=@exit_optimizer_switch;
diff --git a/mysql-test/main/func_group.result b/mysql-test/main/func_group.result
index 0f09aedc22a..177f0950a77 100644
--- a/mysql-test/main/func_group.result
+++ b/mysql-test/main/func_group.result
@@ -606,7 +606,7 @@ select min(a1) from t1 where a1 > 'KKK' or a1 < 'XXX';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 0 NULL 15 Using where; Using index
explain
-select min(a1) from t1 where a1 != 'KKK';
+select min(a1) from t1 where (a1 < 'KKK' or a1 > 'KKK');
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 3 NULL 14 Using where; Using index
explain
diff --git a/mysql-test/main/func_group.test b/mysql-test/main/func_group.test
index 10b92cbadca..a28b39c28f6 100644
--- a/mysql-test/main/func_group.test
+++ b/mysql-test/main/func_group.test
@@ -359,7 +359,7 @@ select min(t1.a1), min(t2.a4) from t1,t2 where t1.a1 < 'KKK' and t2.a4 < 'KKK';
explain
select min(a1) from t1 where a1 > 'KKK' or a1 < 'XXX';
explain
-select min(a1) from t1 where a1 != 'KKK';
+select min(a1) from t1 where (a1 < 'KKK' or a1 > 'KKK');
explain
select max(a3) from t1 where a2 < 2 and a3 < 'SEA';
explain
diff --git a/mysql-test/main/group_min_max.result b/mysql-test/main/group_min_max.result
index 5f51be715fe..c7164fcc74c 100644
--- a/mysql-test/main/group_min_max.result
+++ b/mysql-test/main/group_min_max.result
@@ -2942,7 +2942,7 @@ NULL
EXPLAIN
SELECT MIN( a ) FROM t1 WHERE a <> NULL;
id select_type table type possible_keys key key_len ref rows Extra
-x x x x x x x x x Impossible WHERE noticed after reading const tables
+x x x x x x x x x Using where; Using index
SELECT MIN( a ) FROM t1 WHERE a <> NULL;
MIN( a )
NULL
diff --git a/mysql-test/main/index_merge_myisam.result b/mysql-test/main/index_merge_myisam.result
index 1a4906801a0..053239b7fb1 100644
--- a/mysql-test/main/index_merge_myisam.result
+++ b/mysql-test/main/index_merge_myisam.result
@@ -1687,7 +1687,8 @@ INSERT INTO t1 VALUES
ALTER TABLE t1 ENABLE KEYS;
EXPLAIN
SELECT * FROM t1 FORCE KEY (PRIMARY , i , c1 , c2)
-WHERE pk = 255 OR i = 22 OR (pk IN (1 , 136) AND c2 IN ('c' , 'w') AND (c1 NOT BETWEEN 'e' AND 'i' OR c2 > 'g')) OR pk != 1 ;
+WHERE pk = 255 OR i = 22 OR (pk IN (1 , 136) AND c2 IN ('c' , 'w') AND (c1
+NOT BETWEEN 'e' AND 'i' OR c2 > 'g')) OR (pk is not null and (pk <1 or pk>1)) ;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge PRIMARY,c1,i,c2 PRIMARY,i 0,5 NULL 69 Using sort_union(PRIMARY,i); Using where
DROP TABLE t1;
diff --git a/mysql-test/main/index_merge_myisam.test b/mysql-test/main/index_merge_myisam.test
index e35ce567573..10ddbee36b2 100644
--- a/mysql-test/main/index_merge_myisam.test
+++ b/mysql-test/main/index_merge_myisam.test
@@ -236,9 +236,11 @@ INSERT INTO t1 VALUES
ALTER TABLE t1 ENABLE KEYS;
+# note: (pk is not null and (pk <1 or pk>1)) below is a sargable form of pk!=1
EXPLAIN
SELECT * FROM t1 FORCE KEY (PRIMARY , i , c1 , c2)
-WHERE pk = 255 OR i = 22 OR (pk IN (1 , 136) AND c2 IN ('c' , 'w') AND (c1 NOT BETWEEN 'e' AND 'i' OR c2 > 'g')) OR pk != 1 ;
+WHERE pk = 255 OR i = 22 OR (pk IN (1 , 136) AND c2 IN ('c' , 'w') AND (c1
+NOT BETWEEN 'e' AND 'i' OR c2 > 'g')) OR (pk is not null and (pk <1 or pk>1)) ;
DROP TABLE t1;
diff --git a/mysql-test/main/innodb_icp.result b/mysql-test/main/innodb_icp.result
index adf65780d21..c89d49cad0c 100644
--- a/mysql-test/main/innodb_icp.result
+++ b/mysql-test/main/innodb_icp.result
@@ -455,11 +455,11 @@ c1 INT NOT NULL,
PRIMARY KEY (pk)
);
INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1);
-EXPLAIN SELECT pk, c1 FROM t1 WHERE pk <> 3;
+EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where
SET SESSION optimizer_switch='index_condition_pushdown=off';
-SELECT pk, c1 FROM t1 WHERE pk <> 3;
+SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
pk c1
1 9
2 7
@@ -689,23 +689,23 @@ INSERT INTO t2 VALUES
insert into t2 select seq from seq_1_to_100;
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using where; Using filesort
1 SIMPLE t2 ref a a 515 test.t1.a # Using where
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
SET SESSION optimizer_switch='index_condition_pushdown=on';
EXPLAIN
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using where; Using filesort
1 SIMPLE t2 ref a a 515 test.t1.a # Using where
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
diff --git a/mysql-test/main/myisam_icp.result b/mysql-test/main/myisam_icp.result
index f059c3f95e5..d0614913480 100644
--- a/mysql-test/main/myisam_icp.result
+++ b/mysql-test/main/myisam_icp.result
@@ -448,11 +448,11 @@ c1 INT NOT NULL,
PRIMARY KEY (pk)
);
INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1);
-EXPLAIN SELECT pk, c1 FROM t1 WHERE pk <> 3;
+EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 Using where
SET SESSION optimizer_switch='index_condition_pushdown=off';
-SELECT pk, c1 FROM t1 WHERE pk <> 3;
+SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
pk c1
1 9
2 7
@@ -682,23 +682,23 @@ INSERT INTO t2 VALUES
insert into t2 select seq from seq_1_to_100;
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL # Using where; Using filesort
1 SIMPLE t2 ref a a 515 test.t1.a # Using where
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
SET SESSION optimizer_switch='index_condition_pushdown=on';
EXPLAIN
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL # Using where; Using filesort
1 SIMPLE t2 ref a a 515 test.t1.a # Using where
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
diff --git a/mysql-test/main/mysqldump-nl.test b/mysql-test/main/mysqldump-nl.test
index 863c846b9a6..4451b0605c2 100644
--- a/mysql-test/main/mysqldump-nl.test
+++ b/mysql-test/main/mysqldump-nl.test
@@ -26,10 +26,10 @@ create procedure sp() select * from `v1
flush tables;
use test;
-exec $MYSQL_DUMP --compact --comment --routines --add-drop-database --databases 'mysqltest1
+exec $MYSQL_DUMP --compact --comments --routines --add-drop-database --databases 'mysqltest1
1tsetlqsym';
-exec $MYSQL_DUMP --compact --comment --routines --add-drop-database --databases 'mysqltest1
+exec $MYSQL_DUMP --compact --comments --routines --add-drop-database --databases 'mysqltest1
1tsetlqsym' | $MYSQL;
show tables from `mysqltest1
@@ -45,11 +45,11 @@ create database `test\``
show databases like 'test%';
-exec $MYSQL_DUMP --compact --comment --add-drop-database --databases 'test`' 'test\`
+exec $MYSQL_DUMP --compact --comments --add-drop-database --databases 'test`' 'test\`
\! ls
#';
-exec $MYSQL_DUMP --compact --comment --add-drop-database --databases 'test`' 'test\`
+exec $MYSQL_DUMP --compact --comments --add-drop-database --databases 'test`' 'test\`
\! ls
#' | $MYSQL;
diff --git a/mysql-test/main/parser_not_embedded.test b/mysql-test/main/parser_not_embedded.test
index 3ebd23e888e..3af1260f4ad 100644
--- a/mysql-test/main/parser_not_embedded.test
+++ b/mysql-test/main/parser_not_embedded.test
@@ -21,7 +21,7 @@ select 7 as expected, /*!01000 1 + /*!01000 8 + /*!01000 error */ 16 + */ 2 + */
select 4 as expected, /* 1 + /*!01000 8 + */ 2 + */ 4;
EOF
---exec $MYSQL --comment --force --table test <$MYSQLTEST_VARDIR/tmp/bug39559.sql
+--exec $MYSQL --comments --force --table test <$MYSQLTEST_VARDIR/tmp/bug39559.sql
--remove_file $MYSQLTEST_VARDIR/tmp/bug39559.sql
--echo # Bug#46527 "COMMIT AND CHAIN RELEASE does not make sense"
diff --git a/mysql-test/main/ps.result b/mysql-test/main/ps.result
index 1c13b0a0b84..7f5d94ed63d 100644
--- a/mysql-test/main/ps.result
+++ b/mysql-test/main/ps.result
@@ -5514,6 +5514,43 @@ id select_type table type possible_keys key key_len ref rows Extra
DEALLOCATE PREPARE stmt;
DROP TABLE t1;
#
+# MDEV-25108: Running of the EXPLAIN EXTENDED statement produces extra warning
+# in case it is executed in PS (prepared statement) mode
+#
+CREATE TABLE t1 (c int);
+CREATE TABLE t2 (d int);
+# EXPLAIN EXTENDED in regular way (not PS mode)
+EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) FROM t1;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 Const row not found
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1
+Note 1003 /* select#1 */ select (/* select#2 */ select 1 from `test`.`t2` where 0) AS `(SELECT 1 FROM t2 WHERE d = c)` from `test`.`t1`
+SHOW WARNINGS;
+Level Code Message
+Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1
+Note 1003 /* select#1 */ select (/* select#2 */ select 1 from `test`.`t2` where 0) AS `(SELECT 1 FROM t2 WHERE d = c)` from `test`.`t1`
+# Now run the same EXPLAIN EXTENDED in PS mode. Number of warnings
+# and their content must be the same as in case running the statement
+# in regular way
+PREPARE stmt FROM "EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) FROM t1";
+Warnings:
+Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1
+EXECUTE stmt;
+id select_type table type possible_keys key key_len ref rows filtered Extra
+1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 Const row not found
+2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
+Warnings:
+Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1
+Note 1003 /* select#1 */ select (/* select#2 */ select 1 from `test`.`t2` where 0) AS `(SELECT 1 FROM t2 WHERE d = c)` from `test`.`t1`
+SHOW WARNINGS;
+Level Code Message
+Note 1276 Field or reference 'test.t1.c' of SELECT #2 was resolved in SELECT #1
+Note 1003 /* select#1 */ select (/* select#2 */ select 1 from `test`.`t2` where 0) AS `(SELECT 1 FROM t2 WHERE d = c)` from `test`.`t1`
+DEALLOCATE PREPARE stmt;
+DROP TABLE t1, t2;
+#
# End of 10.2 tests
#
#
@@ -5531,6 +5568,4 @@ ERROR 42S02: Table 'test.x' doesn't exist
DEALLOCATE PREPARE stmt;
DROP VIEW v1;
DROP TABLE t1;
-#
-# End of 10.4 tests
-#
+# MDEV-25413 FIXME: enable the MDEV-25197 test
diff --git a/mysql-test/main/ps.test b/mysql-test/main/ps.test
index 2ce78b78e90..cf70bb1ae18 100644
--- a/mysql-test/main/ps.test
+++ b/mysql-test/main/ps.test
@@ -4956,6 +4956,26 @@ DEALLOCATE PREPARE stmt;
DROP TABLE t1;
--echo #
+--echo # MDEV-25108: Running of the EXPLAIN EXTENDED statement produces extra warning
+--echo # in case it is executed in PS (prepared statement) mode
+--echo #
+CREATE TABLE t1 (c int);
+CREATE TABLE t2 (d int);
+
+--echo # EXPLAIN EXTENDED in regular way (not PS mode)
+EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) FROM t1;
+SHOW WARNINGS;
+
+--echo # Now run the same EXPLAIN EXTENDED in PS mode. Number of warnings
+--echo # and their content must be the same as in case running the statement
+--echo # in regular way
+PREPARE stmt FROM "EXPLAIN EXTENDED SELECT (SELECT 1 FROM t2 WHERE d = c) FROM t1";
+EXECUTE stmt;
+SHOW WARNINGS;
+
+DEALLOCATE PREPARE stmt;
+DROP TABLE t1, t2;
+--echo #
--echo # End of 10.2 tests
--echo #
@@ -4979,6 +4999,46 @@ DEALLOCATE PREPARE stmt;
DROP VIEW v1;
DROP TABLE t1;
+--echo # MDEV-25413 FIXME: enable the MDEV-25197 test
+--exit
+
+--echo #
+--echo # MDEV-25197: The statement set password=password('') executed in PS mode
+--echo # fails in case it is run by a user with expired password
+--echo #
+CREATE USER user1@localhost PASSWORD EXPIRE;
+
+SET @disconnect_on_expired_password_save=@@global.disconnect_on_expired_password;
+SET GLOBAL disconnect_on_expired_password=OFF;
+
+connect(con1,localhost,user1);
+connection con1;
+--echo # Check that no regular statement like SELECT can be prepared
+--echo # by a user with an expired password
+--error ER_MUST_CHANGE_PASSWORD
+PREPARE stmt FROM "SELECT 1";
+
+--echo # Check that the DEALLOCATE PREPARE statement can be run by a user
+--echo # with an expired password
+PREPARE stmt FROM "SET password=password('')";
+DEALLOCATE PREPARE stmt;
+
+--echo # Check that the SET PASSWORD statement can be executed in PS mode by
+--echo # a user with an expired password
+PREPARE stmt FROM "SET password=password('')";
+EXECUTE stmt;
+PREPARE stmt FROM "SELECT 1";
+--echo # Check that user's password is not expired anymore
+EXECUTE stmt;
+DEALLOCATE PREPARE stmt;
+
+--echo # Clean up
+disconnect con1;
+connection default;
+
+SET GLOBAL disconnect_on_expired_password=@disconnect_on_expired_password_save;
+DROP USER user1@localhost;
+
--echo #
--echo # End of 10.4 tests
--echo #
diff --git a/mysql-test/main/range.result b/mysql-test/main/range.result
index 8e9b9596e1e..d97cfb2b587 100644
--- a/mysql-test/main/range.result
+++ b/mysql-test/main/range.result
@@ -3252,6 +3252,17 @@ SELECT * FROM t1 JOIN t2 ON (t2.code = t1.b) WHERE t1.a NOT IN ('baz', 'qux') OR
id a b code num
DROP TABLE t1, t2;
#
+# MDEV-23634: Select query hanged the server and leads to OOM ...
+# (The fix is to add the same handling for "col!=const" as MDEV-21958 did for NOT IN)
+#
+create table t1 (pk int primary key, a int);
+insert into t1 (pk) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+# must not use range:
+explain select * from t1 force index (primary) where pk != 1 and pk!=2 ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 10 Using where
+drop table t1;
+#
# MDEV-22251: get_key_scans_params: Conditional jump or move depends on uninitialised value
#
create table t1 (pk int, i int, v int, primary key (pk), key(v));
diff --git a/mysql-test/main/range.test b/mysql-test/main/range.test
index 8e8161cde25..6d43ad9090d 100644
--- a/mysql-test/main/range.test
+++ b/mysql-test/main/range.test
@@ -2216,6 +2216,17 @@ DROP TABLE t1, t2;
--echo #
+--echo # MDEV-23634: Select query hanged the server and leads to OOM ...
+--echo # (The fix is to add the same handling for "col!=const" as MDEV-21958 did for NOT IN)
+--echo #
+create table t1 (pk int primary key, a int);
+insert into t1 (pk) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+
+--echo # must not use range:
+explain select * from t1 force index (primary) where pk != 1 and pk!=2 ;
+drop table t1;
+
+--echo #
--echo # MDEV-22251: get_key_scans_params: Conditional jump or move depends on uninitialised value
--echo #
diff --git a/mysql-test/main/range_mrr_icp.result b/mysql-test/main/range_mrr_icp.result
index e24e3bc3903..9fa7bd29851 100644
--- a/mysql-test/main/range_mrr_icp.result
+++ b/mysql-test/main/range_mrr_icp.result
@@ -3241,6 +3241,17 @@ SELECT * FROM t1 JOIN t2 ON (t2.code = t1.b) WHERE t1.a NOT IN ('baz', 'qux') OR
id a b code num
DROP TABLE t1, t2;
#
+# MDEV-23634: Select query hanged the server and leads to OOM ...
+# (The fix is to add the same handling for "col!=const" as MDEV-21958 did for NOT IN)
+#
+create table t1 (pk int primary key, a int);
+insert into t1 (pk) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+# must not use range:
+explain select * from t1 force index (primary) where pk != 1 and pk!=2 ;
+id select_type table type possible_keys key key_len ref rows Extra
+1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 10 Using where
+drop table t1;
+#
# MDEV-22251: get_key_scans_params: Conditional jump or move depends on uninitialised value
#
create table t1 (pk int, i int, v int, primary key (pk), key(v));
diff --git a/mysql-test/main/range_vs_index_merge.result b/mysql-test/main/range_vs_index_merge.result
index 6b2c9a2f0bc..207e012b825 100644
--- a/mysql-test/main/range_vs_index_merge.result
+++ b/mysql-test/main/range_vs_index_merge.result
@@ -1810,11 +1810,11 @@ CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX idx(b));
INSERT INTO t1 VALUES (167,9999), (168,10000);
EXPLAIN
SELECT * FROM t1
-WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
+WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR (a<2 or a>2);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY,idx PRIMARY 0 NULL 2 Using index condition; Using where
SELECT * FROM t1
-WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
+WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR (a<2 or a>2);
a b
167 9999
168 10000
@@ -1846,12 +1846,12 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
EXPLAIN
SELECT * FROM t1 FORCE KEY (state,capital)
-WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
+WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND (id<9 or id>9)
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range state,capital state 71 NULL 8 Using index condition; Using where
SELECT * FROM t1 FORCE KEY (state,capital)
-WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
+WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND (id<9 or id>9)
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
id state capital
4 Florida Tallahassee
diff --git a/mysql-test/main/range_vs_index_merge.test b/mysql-test/main/range_vs_index_merge.test
index 5ed5f621ab6..94210ce5dd3 100644
--- a/mysql-test/main/range_vs_index_merge.test
+++ b/mysql-test/main/range_vs_index_merge.test
@@ -1231,9 +1231,9 @@ INSERT INTO t1 VALUES (167,9999), (168,10000);
EXPLAIN
SELECT * FROM t1
- WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
+ WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR (a<2 or a>2);
SELECT * FROM t1
- WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
+ WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR (a<2 or a>2);
DROP TABLE t1;
@@ -1266,10 +1266,10 @@ ANALYZE TABLE t1;
EXPLAIN
SELECT * FROM t1 FORCE KEY (state,capital)
-WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
+WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND (id<9 or id>9)
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
SELECT * FROM t1 FORCE KEY (state,capital)
-WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
+WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND (id<9 or id>9)
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
DROP TABLE t1;
diff --git a/mysql-test/main/range_vs_index_merge_innodb.result b/mysql-test/main/range_vs_index_merge_innodb.result
index 497aa3d94dc..4ac62e24940 100644
--- a/mysql-test/main/range_vs_index_merge_innodb.result
+++ b/mysql-test/main/range_vs_index_merge_innodb.result
@@ -1816,11 +1816,11 @@ CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX idx(b));
INSERT INTO t1 VALUES (167,9999), (168,10000);
EXPLAIN
SELECT * FROM t1
-WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
+WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR (a<2 or a>2);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index PRIMARY,idx idx 5 NULL 2 Using where; Using index
SELECT * FROM t1
-WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR a!=2;
+WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR (a<2 or a>2);
a b
167 9999
168 10000
@@ -1852,12 +1852,12 @@ test.t1 analyze status Engine-independent statistics collected
test.t1 analyze status OK
EXPLAIN
SELECT * FROM t1 FORCE KEY (state,capital)
-WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
+WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND (id<9 or id>9)
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range state,capital state 71 NULL 8 Using index condition; Using where
SELECT * FROM t1 FORCE KEY (state,capital)
-WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND id != 9
+WHERE ( state = 'Alabama' OR state >= 'Colorado' ) AND (id<9 or id>9)
OR ( capital >= 'Topeka' OR state = 'Kansas' ) AND state != 'Texas';
id state capital
4 Florida Tallahassee
diff --git a/mysql-test/main/selectivity_innodb.result b/mysql-test/main/selectivity_innodb.result
index 46723410b75..dc377aa5b6c 100644
--- a/mysql-test/main/selectivity_innodb.result
+++ b/mysql-test/main/selectivity_innodb.result
@@ -1443,7 +1443,7 @@ EXPLAIN EXTENDED
SELECT * FROM t1, t2
WHERE a <> 'USARussian' AND b IS NULL;
id select_type table type possible_keys key key_len ref rows filtered Extra
-1 SIMPLE t1 range PRIMARY,b b 23 NULL 2 100.00 Using where; Using index
+1 SIMPLE t1 ref PRIMARY,b b 5 const 1 100.00 Using where; Using index
1 SIMPLE t2 ALL NULL NULL NULL NULL 14 100.00 Using join buffer (flat, BNL join)
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`i` AS `i` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` <> 'USARussian' and `test`.`t1`.`b` is null
diff --git a/mysql-test/main/subselect_mat_cost_bugs.result b/mysql-test/main/subselect_mat_cost_bugs.result
index 34c0ccab620..6a218ed5e04 100644
--- a/mysql-test/main/subselect_mat_cost_bugs.result
+++ b/mysql-test/main/subselect_mat_cost_bugs.result
@@ -189,8 +189,8 @@ SELECT alias2.f2 AS field1
FROM t1 AS alias1 JOIN ( SELECT * FROM t2 ) AS alias2 ON alias2.f3 = alias1.f1
WHERE (
SELECT t2.f2
-FROM t2 JOIN t1 ON t1.f1
-WHERE t1.f1 AND alias2.f10
+FROM t2 JOIN t1 ON (t1.f1>0 or t1.f1<0)
+WHERE (t1.f1>0 or t1.f1<0) AND alias2.f10
)
ORDER BY field1 ;
id select_type table type possible_keys key key_len ref rows Extra
@@ -203,8 +203,8 @@ SELECT alias2.f2 AS field1
FROM t1 AS alias1 JOIN ( SELECT * FROM t2 ) AS alias2 ON alias2.f3 = alias1.f1
WHERE (
SELECT t2.f2
-FROM t2 JOIN t1 ON t1.f1
-WHERE t1.f1 AND alias2.f10
+FROM t2 JOIN t1 ON (t1.f1>0 or t1.f1<0)
+WHERE (t1.f1>0 or t1.f1<0) AND alias2.f10
)
ORDER BY field1 ;
field1
diff --git a/mysql-test/main/subselect_mat_cost_bugs.test b/mysql-test/main/subselect_mat_cost_bugs.test
index 028cdced560..ba1aad06a15 100644
--- a/mysql-test/main/subselect_mat_cost_bugs.test
+++ b/mysql-test/main/subselect_mat_cost_bugs.test
@@ -217,8 +217,8 @@ SELECT alias2.f2 AS field1
FROM t1 AS alias1 JOIN ( SELECT * FROM t2 ) AS alias2 ON alias2.f3 = alias1.f1
WHERE (
SELECT t2.f2
- FROM t2 JOIN t1 ON t1.f1
- WHERE t1.f1 AND alias2.f10
+ FROM t2 JOIN t1 ON (t1.f1>0 or t1.f1<0)
+ WHERE (t1.f1>0 or t1.f1<0) AND alias2.f10
)
ORDER BY field1 ;
@@ -226,8 +226,8 @@ SELECT alias2.f2 AS field1
FROM t1 AS alias1 JOIN ( SELECT * FROM t2 ) AS alias2 ON alias2.f3 = alias1.f1
WHERE (
SELECT t2.f2
- FROM t2 JOIN t1 ON t1.f1
- WHERE t1.f1 AND alias2.f10
+ FROM t2 JOIN t1 ON (t1.f1>0 or t1.f1<0)
+ WHERE (t1.f1>0 or t1.f1<0) AND alias2.f10
)
ORDER BY field1 ;
diff --git a/mysql-test/main/userstat.result b/mysql-test/main/userstat.result
index 6d9cd491de6..9152f602304 100644
--- a/mysql-test/main/userstat.result
+++ b/mysql-test/main/userstat.result
@@ -243,6 +243,8 @@ create function f() returns int return (select 1 from performance_schema.threads
set global userstat= 1;
select f() from information_schema.table_statistics;
ERROR 21000: Subquery returns more than 1 row
+select f() from information_schema.index_statistics;
+ERROR 21000: Subquery returns more than 1 row
set global userstat= 0;
drop function f;
#
diff --git a/mysql-test/main/userstat.test b/mysql-test/main/userstat.test
index cc7ddd58e11..6d486810db1 100644
--- a/mysql-test/main/userstat.test
+++ b/mysql-test/main/userstat.test
@@ -121,6 +121,8 @@ create function f() returns int return (select 1 from performance_schema.threads
set global userstat= 1;
--error ER_SUBQUERY_NO_1_ROW
select f() from information_schema.table_statistics;
+--error ER_SUBQUERY_NO_1_ROW
+select f() from information_schema.index_statistics;
set global userstat= 0;
drop function f;
diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl
index 5a4873f9c01..7569dd7b053 100755
--- a/mysql-test/mysql-test-run.pl
+++ b/mysql-test/mysql-test-run.pl
@@ -733,9 +733,13 @@ sub run_test_server ($$$) {
rename $log_file_name, $log_file_name.".failed";
}
- delete($result->{result});
- $result->{retries}= $retries+1;
- $result->write_test($sock, 'TESTCASE');
+ {
+ local @$result{'retries', 'result'};
+ delete $result->{result};
+ $result->{retries}= $retries+1;
+ $result->write_test($sock, 'TESTCASE');
+ }
+ push(@$completed, $result);
next;
}
}
diff --git a/mysql-test/suite/galera/disabled.def b/mysql-test/suite/galera/disabled.def
index 05eee166a0f..a562f8b0ae7 100644
--- a/mysql-test/suite/galera/disabled.def
+++ b/mysql-test/suite/galera/disabled.def
@@ -22,7 +22,6 @@ galera_bf_abort_at_after_statement : MDEV-21557: galera_bf_abort_at_after_statem
galera_bf_abort_group_commit : MDEV-18282 Galera test failure on galera.galera_bf_abort_group_commit
galera_bf_kill_debug : MDEV-24485 wsrep::client_state::do_acquire_ownership(): Assertion `state_ == s_idle || mode_ != m_local' failed
galera_bf_lock_wait : MDEV-21597 wsrep::transaction::start_transaction(): Assertion `active() == false' failed
-galera_binlog_stmt_autoinc : MDEV-19959 Galera test failure on galera_binlog_stmt_autoinc
galera_encrypt_tmp_files : Get error failed to enable encryption of temporary files
galera_ftwrl : MDEV-21525 galera.galera_ftwrl
galera_gcache_recover_manytrx : MDEV-18834 Galera test failure
@@ -34,7 +33,6 @@ galera_pc_ignore_sb : MDEV-20888 galera.galera_pc_ignore_sb
galera_pc_recovery : MDEV-25199 cluster fails to start up
galera_shutdown_nonprim : MDEV-21493 galera.galera_shutdown_nonprim
galera_ssl_upgrade : MDEV-19950 Galera test failure on galera_ssl_upgrade
-galera_sst_mariabackup_encrypt_with_key : MDEV-21484 galera_sst_mariabackup_encrypt_with_key
galera_toi_ddl_nonconflicting : MDEV-21518 galera.galera_toi_ddl_nonconflicting
galera_toi_truncate : MDEV-22996 Hang on galera_toi_truncate test case
galera_trigger : MDEV-24048 galera.galera_trigger MTR fails: Result content mismatch
diff --git a/mysql-test/suite/galera/r/galera_var_sst_auth.result b/mysql-test/suite/galera/r/galera_var_sst_auth.result
index 53b8443705a..98d683c3b2d 100644
--- a/mysql-test/suite/galera/r/galera_var_sst_auth.result
+++ b/mysql-test/suite/galera/r/galera_var_sst_auth.result
@@ -1,5 +1,7 @@
connection node_2;
connection node_1;
+connection node_1;
+connection node_2;
SELECT @@global.wsrep_sst_auth;
@@global.wsrep_sst_auth
********
diff --git a/mysql-test/suite/galera/r/galera_virtual_blob.result b/mysql-test/suite/galera/r/galera_virtual_blob.result
new file mode 100644
index 00000000000..fd1c84f7083
--- /dev/null
+++ b/mysql-test/suite/galera/r/galera_virtual_blob.result
@@ -0,0 +1,21 @@
+connection node_2;
+connection node_1;
+CREATE TABLE t (f INT GENERATED ALWAYS AS (a+b)VIRTUAL,a INT,b INT,h BLOB);
+INSERT INTO t (a,b)VALUES(0,0), (0,0), (0,0), (0,0), (0,0);
+SELECT * from t;
+f a b h
+0 0 0 NULL
+0 0 0 NULL
+0 0 0 NULL
+0 0 0 NULL
+0 0 0 NULL
+connection node_2;
+SELECT * from t;
+f a b h
+0 0 0 NULL
+0 0 0 NULL
+0 0 0 NULL
+0 0 0 NULL
+0 0 0 NULL
+connection node_1;
+DROP TABLE t;
diff --git a/mysql-test/suite/galera/t/galera_binlog_stmt_autoinc.cnf b/mysql-test/suite/galera/t/galera_binlog_stmt_autoinc.cnf
new file mode 100644
index 00000000000..889c81b4a0a
--- /dev/null
+++ b/mysql-test/suite/galera/t/galera_binlog_stmt_autoinc.cnf
@@ -0,0 +1,7 @@
+!include ../galera_2nodes.cnf
+
+[mysqld.1]
+auto_increment_offset=1
+
+[mysqld.2]
+auto_increment_offset=2
diff --git a/mysql-test/suite/galera/t/galera_var_sst_auth.cnf b/mysql-test/suite/galera/t/galera_var_sst_auth.cnf
index ff29db2306b..114815d446a 100644
--- a/mysql-test/suite/galera/t/galera_var_sst_auth.cnf
+++ b/mysql-test/suite/galera/t/galera_var_sst_auth.cnf
@@ -5,8 +5,3 @@ wsrep_sst_auth=root:
[mysqld.2]
wsrep_sst_auth=root:
-
-
-
-
-
diff --git a/mysql-test/suite/galera/t/galera_var_sst_auth.test b/mysql-test/suite/galera/t/galera_var_sst_auth.test
index ad7f46620ad..ebeaddc0e63 100644
--- a/mysql-test/suite/galera/t/galera_var_sst_auth.test
+++ b/mysql-test/suite/galera/t/galera_var_sst_auth.test
@@ -1,6 +1,11 @@
--source include/galera_cluster.inc
--source include/have_innodb.inc
+# Save original auto_increment_offset values.
+--let $node_1=node_1
+--let $node_2=node_2
+--source include/auto_increment_offset_save.inc
+
#
# MDEV-10492: Assertion failure on shutdown when wsrep_sst_auth set in config
#
@@ -30,4 +35,5 @@ SELECT @@global.wsrep_sst_auth;
--source include/wait_condition.inc
SELECT @@global.wsrep_sst_auth;
-
+# Restore original auto_increment_offset values.
+--source include/auto_increment_offset_restore.inc
diff --git a/mysql-test/suite/galera/t/galera_virtual_blob.test b/mysql-test/suite/galera/t/galera_virtual_blob.test
new file mode 100644
index 00000000000..a10e3025668
--- /dev/null
+++ b/mysql-test/suite/galera/t/galera_virtual_blob.test
@@ -0,0 +1,10 @@
+--source include/galera_cluster.inc
+
+CREATE TABLE t (f INT GENERATED ALWAYS AS (a+b)VIRTUAL,a INT,b INT,h BLOB);
+INSERT INTO t (a,b)VALUES(0,0), (0,0), (0,0), (0,0), (0,0);
+SELECT * from t;
+
+--connection node_2
+SELECT * from t;
+--connection node_1
+DROP TABLE t;
diff --git a/mysql-test/suite/galera/t/galera_vote_rejoin_ddl.cnf b/mysql-test/suite/galera/t/galera_vote_rejoin_ddl.cnf
index b2cba42c0bd..022cfcdc0b0 100644
--- a/mysql-test/suite/galera/t/galera_vote_rejoin_ddl.cnf
+++ b/mysql-test/suite/galera/t/galera_vote_rejoin_ddl.cnf
@@ -2,3 +2,9 @@
[mysqld]
wsrep-ignore-apply-errors=0
+
+[mysqld.3]
+auto_increment_offset=3
+
+[mysqld.4]
+auto_increment_offset=4
diff --git a/mysql-test/suite/gcol/r/virtual_index_drop.result b/mysql-test/suite/gcol/r/virtual_index_drop.result
new file mode 100644
index 00000000000..012e61be459
--- /dev/null
+++ b/mysql-test/suite/gcol/r/virtual_index_drop.result
@@ -0,0 +1,69 @@
+#
+# MDEV-24971 InnoDB access freed virtual column
+# after rollback of secondary index
+#
+CREATE TABLE t1(f1 INT, f2 INT AS (f1 + 2) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1), (1);
+ALTER TABLE t1 ADD UNIQUE INDEX(f2), ALGORITHM=INPLACE, LOCK=EXCLUSIVE;
+ERROR 23000: Duplicate entry '3' for key 'f2'
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `f1` int(11) DEFAULT NULL,
+ `f2` int(11) GENERATED ALWAYS AS (`f1` + 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1(f1 INT, f2 INT AS (f1 + 2) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1), (1);
+ALTER TABLE t1 ADD UNIQUE INDEX(f2), ALGORITHM=INPLACE, LOCK=SHARED;
+ERROR 23000: Duplicate entry '3' for key 'f2'
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `f1` int(11) DEFAULT NULL,
+ `f2` int(11) GENERATED ALWAYS AS (`f1` + 2) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB;
+SET DEBUG_DBUG="+d,create_index_fail";
+SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal";
+ALTER TABLE t1 ADD COLUMN f3 INT AS (f1) VIRTUAL, ADD INDEX(f2, f3);
+connect con1,localhost,root,,,;
+SET DEBUG_SYNC="now WAIT_FOR con1_go";
+BEGIN;
+SELECT * FROM t1;
+f1 f2
+SET DEBUG_SYNC="now SIGNAL alter_signal";
+connection default;
+ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
+connection con1;
+rollback;
+connection default;
+SHOW CREATE TABLE t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `f1` int(11) DEFAULT NULL,
+ `f2` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+DROP TABLE t1;
+CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB;
+SET DEBUG_DBUG="+d,create_index_fail";
+SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal";
+ALTER TABLE t1 ADD INDEX(f2);
+connection con1;
+SET DEBUG_SYNC="now WAIT_FOR con1_go";
+BEGIN;
+INSERT INTO t1(f1) VALUES(1);
+SET DEBUG_SYNC="now SIGNAL alter_signal";
+connection default;
+ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
+connection con1;
+rollback;
+connection default;
+disconnect con1;
+DROP TABLE t1;
+CREATE TABLE t1(f1 CHAR(100), f2 CHAR(100) as (f1) VIRTUAL)ENGINE=InnoDB;
+ALTER TABLE t1 ADD COLUMN f3 CHAR(100) AS (f2) VIRTUAL, ADD INDEX(f3(10), f1, f3(12));
+ERROR 42S21: Duplicate column name 'f3'
+DROP TABLE t1;
+SET DEBUG_SYNC=RESET;
diff --git a/mysql-test/suite/gcol/t/virtual_index_drop.test b/mysql-test/suite/gcol/t/virtual_index_drop.test
new file mode 100644
index 00000000000..016832b9e6d
--- /dev/null
+++ b/mysql-test/suite/gcol/t/virtual_index_drop.test
@@ -0,0 +1,71 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+
+--echo #
+--echo # MDEV-24971 InnoDB access freed virtual column
+--echo # after rollback of secondary index
+--echo #
+
+# Exclusive lock must not defer the index removal
+
+CREATE TABLE t1(f1 INT, f2 INT AS (f1 + 2) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1), (1);
+--error ER_DUP_ENTRY
+ALTER TABLE t1 ADD UNIQUE INDEX(f2), ALGORITHM=INPLACE, LOCK=EXCLUSIVE;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# If Shared lock and table doesn't have any other open handle
+# then InnoDB must not defer the index removal
+
+CREATE TABLE t1(f1 INT, f2 INT AS (f1 + 2) VIRTUAL)ENGINE=InnoDB;
+INSERT INTO t1(f1) VALUES(1), (1);
+--error ER_DUP_ENTRY
+ALTER TABLE t1 ADD UNIQUE INDEX(f2), ALGORITHM=INPLACE, LOCK=SHARED;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+# InnoDB should store the newly dropped virtual column into
+# new_vcol_info in index when rollback of alter happens
+
+CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB;
+SET DEBUG_DBUG="+d,create_index_fail";
+SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal";
+SEND ALTER TABLE t1 ADD COLUMN f3 INT AS (f1) VIRTUAL, ADD INDEX(f2, f3);
+connect(con1,localhost,root,,,);
+SET DEBUG_SYNC="now WAIT_FOR con1_go";
+BEGIN;
+SELECT * FROM t1;
+SET DEBUG_SYNC="now SIGNAL alter_signal";
+connection default;
+--error ER_DUP_ENTRY
+reap;
+connection con1;
+rollback;
+connection default;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 INT, f2 INT AS (f1) VIRTUAL)ENGINE=InnoDB;
+SET DEBUG_DBUG="+d,create_index_fail";
+SET DEBUG_SYNC="innodb_inplace_alter_table_enter SIGNAL con1_go WAIT_FOR alter_signal";
+send ALTER TABLE t1 ADD INDEX(f2);
+connection con1;
+SET DEBUG_SYNC="now WAIT_FOR con1_go";
+BEGIN;
+INSERT INTO t1(f1) VALUES(1);
+SET DEBUG_SYNC="now SIGNAL alter_signal";
+connection default;
+--error ER_DUP_ENTRY
+reap;
+connection con1;
+rollback;
+connection default;
+disconnect con1;
+DROP TABLE t1;
+
+CREATE TABLE t1(f1 CHAR(100), f2 CHAR(100) as (f1) VIRTUAL)ENGINE=InnoDB;
+--error ER_DUP_FIELDNAME
+ALTER TABLE t1 ADD COLUMN f3 CHAR(100) AS (f2) VIRTUAL, ADD INDEX(f3(10), f1, f3(12));
+DROP TABLE t1;
+SET DEBUG_SYNC=RESET;
diff --git a/mysql-test/suite/innodb/r/innodb_buffer_pool_fail.result b/mysql-test/suite/innodb/r/innodb_buffer_pool_fail.result
new file mode 100644
index 00000000000..9879ef206f2
--- /dev/null
+++ b/mysql-test/suite/innodb/r/innodb_buffer_pool_fail.result
@@ -0,0 +1,8 @@
+call mtr.add_suppression("InnoDB: Cannot allocate memory for the buffer pool");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted at srv0start.cc.*");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error.");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed.");
+#
+# MDEV-25019 memory allocation failures during startup cause server failure in different, confusing ways
+#
+# restart: --debug_dbug=+d,ib_buf_chunk_init_fails
diff --git a/mysql-test/suite/innodb/r/instant_alter_debug.result b/mysql-test/suite/innodb/r/instant_alter_debug.result
index bf1204724a4..72b47bc6e20 100644
--- a/mysql-test/suite/innodb/r/instant_alter_debug.result
+++ b/mysql-test/suite/innodb/r/instant_alter_debug.result
@@ -368,6 +368,34 @@ SELECT * FROM t1 WHERE c<>1 ORDER BY c DESC;
c d
DROP TABLE t1;
SET GLOBAL innodb_limit_optimistic_insert_debug = @saved_limit;
+#
+# MDEV-24620 ASAN heap-buffer-overflow in btr_pcur_restore_position()
+#
+CREATE TABLE t1 (a VARCHAR(1) PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+connect stop_purge,localhost,root,,;
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+connection default;
+ALTER TABLE t1 ADD c INT;
+BEGIN;
+DELETE FROM t1;
+connect dml,localhost,root,,test;
+SET DEBUG_SYNC='row_mysql_handle_errors SIGNAL s1 WAIT_FOR s2';
+UPDATE t1 SET c=1;
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR s1';
+COMMIT;
+connection stop_purge;
+COMMIT;
+disconnect stop_purge;
+connection default;
+InnoDB 0 transactions not purged
+SET DEBUG_SYNC='now SIGNAL s2';
+connection dml;
+disconnect dml;
+connection default;
+SET DEBUG_SYNC=RESET;
+DROP TABLE t1;
# End of 10.3 tests
#
# MDEV-17899 Assertion failures on rollback of instant ADD/DROP
@@ -460,4 +488,4 @@ SELECT variable_value-@old_instant instants
FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column';
instants
-34
+35
diff --git a/mysql-test/suite/innodb/t/innodb_buffer_pool_fail.test b/mysql-test/suite/innodb/t/innodb_buffer_pool_fail.test
new file mode 100644
index 00000000000..1d938e12e78
--- /dev/null
+++ b/mysql-test/suite/innodb/t/innodb_buffer_pool_fail.test
@@ -0,0 +1,11 @@
+--source include/have_innodb.inc
+--source include/have_debug.inc
+call mtr.add_suppression("InnoDB: Cannot allocate memory for the buffer pool");
+call mtr.add_suppression("InnoDB: Plugin initialization aborted at srv0start.cc.*");
+call mtr.add_suppression("Plugin 'InnoDB' init function returned error.");
+call mtr.add_suppression("Plugin 'InnoDB' registration as a STORAGE ENGINE failed.");
+--echo #
+--echo # MDEV-25019 memory allocation failures during startup cause server failure in different, confusing ways
+--echo #
+let restart_parameters=--debug_dbug="+d,ib_buf_chunk_init_fails";
+--source include/restart_mysqld.inc
diff --git a/mysql-test/suite/innodb/t/instant_alter_debug.test b/mysql-test/suite/innodb/t/instant_alter_debug.test
index da0692990c4..dcce4b29119 100644
--- a/mysql-test/suite/innodb/t/instant_alter_debug.test
+++ b/mysql-test/suite/innodb/t/instant_alter_debug.test
@@ -424,6 +424,44 @@ DROP TABLE t1;
SET GLOBAL innodb_limit_optimistic_insert_debug = @saved_limit;
+--echo #
+--echo # MDEV-24620 ASAN heap-buffer-overflow in btr_pcur_restore_position()
+--echo #
+
+CREATE TABLE t1 (a VARCHAR(1) PRIMARY KEY) ENGINE=InnoDB;
+INSERT INTO t1 VALUES (1);
+connect (stop_purge,localhost,root,,);
+START TRANSACTION WITH CONSISTENT SNAPSHOT;
+
+connection default;
+ALTER TABLE t1 ADD c INT;
+BEGIN;
+DELETE FROM t1;
+
+connect (dml,localhost,root,,test);
+SET DEBUG_SYNC='row_mysql_handle_errors SIGNAL s1 WAIT_FOR s2';
+send UPDATE t1 SET c=1;
+
+connection default;
+SET DEBUG_SYNC='now WAIT_FOR s1';
+COMMIT;
+
+connection stop_purge;
+COMMIT;
+disconnect stop_purge;
+
+connection default;
+--source include/wait_all_purged.inc
+SET DEBUG_SYNC='now SIGNAL s2';
+
+connection dml;
+reap;
+disconnect dml;
+
+connection default;
+SET DEBUG_SYNC=RESET;
+DROP TABLE t1;
+
--echo # End of 10.3 tests
--echo #
diff --git a/mysql-test/suite/innodb_fts/r/fulltext.result b/mysql-test/suite/innodb_fts/r/fulltext.result
index 2c604f9b5fe..aba1d51c25a 100644
--- a/mysql-test/suite/innodb_fts/r/fulltext.result
+++ b/mysql-test/suite/innodb_fts/r/fulltext.result
@@ -690,6 +690,19 @@ FTS_DOC_ID t
3 foo
DROP TABLE t;
#
+# MDEV-25295 Aborted FTS_DOC_ID_INDEX considered as
+# existing FTS_DOC_ID_INDEX during DDL
+#
+SET sql_mode='';
+CREATE TABLE t1 (FTS_DOC_ID BIGINT UNSIGNED NOT NULL,title CHAR(1),body TEXT)engine=innodb;
+INSERT INTO t1 (FTS_DOC_ID,title,body)VALUES(1,0,0), (1,0,0);
+CREATE FULLTEXT INDEX idx1 ON t1 (title,body);
+ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
+CREATE FULLTEXT INDEX idx1 ON t1 (title,body);
+ERROR 23000: Duplicate entry '' for key '*UNKNOWN*'
+DROP TABLE t1;
+SET sql_mode = DEFAULT;
+#
# MDEV-25070 SIGSEGV in fts_create_in_mem_aux_table
#
CREATE TABLE t1 (a CHAR, FULLTEXT KEY(a)) ENGINE=InnoDB;
@@ -703,3 +716,4 @@ t1 CREATE TABLE `t1` (
FULLTEXT KEY `a_2` (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
DROP TABLE t1;
+# End of 10.3 tests
diff --git a/mysql-test/suite/innodb_fts/t/fulltext.test b/mysql-test/suite/innodb_fts/t/fulltext.test
index fa9cace19cf..18baf56281f 100644
--- a/mysql-test/suite/innodb_fts/t/fulltext.test
+++ b/mysql-test/suite/innodb_fts/t/fulltext.test
@@ -719,6 +719,20 @@ while ($N)
DROP TABLE t;
--echo #
+--echo # MDEV-25295 Aborted FTS_DOC_ID_INDEX considered as
+--echo # existing FTS_DOC_ID_INDEX during DDL
+--echo #
+SET sql_mode='';
+CREATE TABLE t1 (FTS_DOC_ID BIGINT UNSIGNED NOT NULL,title CHAR(1),body TEXT)engine=innodb;
+INSERT INTO t1 (FTS_DOC_ID,title,body)VALUES(1,0,0), (1,0,0);
+--error ER_DUP_ENTRY
+CREATE FULLTEXT INDEX idx1 ON t1 (title,body);
+--error ER_DUP_ENTRY
+CREATE FULLTEXT INDEX idx1 ON t1 (title,body);
+DROP TABLE t1;
+SET sql_mode = DEFAULT;
+
+--echo #
--echo # MDEV-25070 SIGSEGV in fts_create_in_mem_aux_table
--echo #
CREATE TABLE t1 (a CHAR, FULLTEXT KEY(a)) ENGINE=InnoDB;
@@ -728,3 +742,5 @@ ALTER TABLE t1 ADD FULLTEXT INDEX (a);
SHOW CREATE TABLE t1;
DROP TABLE t1;
--enable_warnings
+
+--echo # End of 10.3 tests
diff --git a/mysql-test/suite/maria/icp.result b/mysql-test/suite/maria/icp.result
index 149258de918..43ec6439144 100644
--- a/mysql-test/suite/maria/icp.result
+++ b/mysql-test/suite/maria/icp.result
@@ -450,11 +450,11 @@ c1 INT NOT NULL,
PRIMARY KEY (pk)
);
INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1);
-EXPLAIN SELECT pk, c1 FROM t1 WHERE pk <> 3;
+EXPLAIN SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 Using where
SET SESSION optimizer_switch='index_condition_pushdown=off';
-SELECT pk, c1 FROM t1 WHERE pk <> 3;
+SELECT pk, c1 FROM t1 WHERE (pk<3 or pk>3);
pk c1
1 9
2 7
@@ -684,23 +684,23 @@ INSERT INTO t2 VALUES
insert into t2 select seq from seq_1_to_100;
SET SESSION optimizer_switch='index_condition_pushdown=off';
EXPLAIN
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL # Using where; Using filesort
1 SIMPLE t2 ref a a 515 test.t1.a # Using where
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
SET SESSION optimizer_switch='index_condition_pushdown=on';
EXPLAIN
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL PRIMARY NULL NULL NULL # Using where; Using filesort
1 SIMPLE t2 ref a a 515 test.t1.a # Using where
-SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0
+SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND (t1.b<0 OR t1.b>0)
HAVING t1.c != 5 ORDER BY t1.c;
b c
1 4
diff --git a/mysql-test/suite/mariabackup/error_during_copyback.result b/mysql-test/suite/mariabackup/error_during_copyback.result
new file mode 100644
index 00000000000..ba27f0f83e6
--- /dev/null
+++ b/mysql-test/suite/mariabackup/error_during_copyback.result
@@ -0,0 +1,10 @@
+CREATE TABLE t(i INT) ENGINE INNODB;
+INSERT INTO t VALUES(1);
+# xtrabackup backup
+# xtrabackup prepare
+# restart server
+# restart
+SELECT * FROM t;
+i
+1
+DROP TABLE t;
diff --git a/mysql-test/suite/mariabackup/error_during_copyback.test b/mysql-test/suite/mariabackup/error_during_copyback.test
new file mode 100644
index 00000000000..3ec9fbfc3c3
--- /dev/null
+++ b/mysql-test/suite/mariabackup/error_during_copyback.test
@@ -0,0 +1,25 @@
+--source include/have_debug.inc
+CREATE TABLE t(i INT) ENGINE INNODB;
+INSERT INTO t VALUES(1);
+echo # xtrabackup backup;
+let $targetdir=$MYSQLTEST_VARDIR/tmp/backup;
+--disable_result_log
+exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir;
+--enable_result_log
+echo # xtrabackup prepare;
+--disable_result_log
+exec $XTRABACKUP --prepare --target-dir=$targetdir;
+let $_datadir= `SELECT @@datadir`;
+--source include/shutdown_mysqld.inc
+rmdir $_datadir;
+error 1;
+exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --copy-back --datadir=$_datadir --target-dir=$targetdir --dbug=+d,copy_file_error;
+list_files $_datadir;
+rmdir $_datadir;
+exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --copy-back --datadir=$_datadir --target-dir=$targetdir;
+echo # restart server;
+--source include/start_mysqld.inc
+SELECT * FROM t;
+DROP TABLE t;
+rmdir $targetdir;
+
diff --git a/mysql-test/suite/mariabackup/innodb_force_recovery.result b/mysql-test/suite/mariabackup/innodb_force_recovery.result
new file mode 100644
index 00000000000..6626bb0bc55
--- /dev/null
+++ b/mysql-test/suite/mariabackup/innodb_force_recovery.result
@@ -0,0 +1,26 @@
+CREATE TABLE t(i INT) ENGINE INNODB;
+INSERT INTO t VALUES(1);
+# "innodb_force_recovery=1" should be allowed with "--prepare" only (mariabackup)
+FOUND 1 /should only be used with "--prepare"/ in backup.log
+# "innodb_force_recovery=1" should be allowed with "--apply-log" only (innobackupex)
+FOUND 1 /should only be used with "--apply-log"/ in backup.log
+# "innodb_force_recovery" should be limited to "SRV_FORCE_IGNORE_CORRUPT" (mariabackup)
+FOUND 1 /innodb_force_recovery = 1/ in backup.log
+# "innodb_force_recovery" should be limited to "SRV_FORCE_IGNORE_CORRUPT" (innobackupex)
+FOUND 1 /innodb_force_recovery = 1/ in backup.log
+# "innodb_force_recovery" should be read from "backup-my.cnf" (mariabackup)
+FOUND 1 /innodb_force_recovery = 1/ in backup.log
+# "innodb_force_recovery=1" should be read from "backup-my.cnf" (innobackupex)
+FOUND 1 /innodb_force_recovery = 1/ in backup.log
+# "innodb_force_recovery" from the command line should override "backup-my.cnf" (mariabackup)
+NOT FOUND /innodb_force_recovery = 1/ in backup.log
+# "innodb_force_recovery" from the command line should override "backup-my.cnf" (innobackupex)
+NOT FOUND /innodb_force_recovery = 1/ in backup.log
+# shutdown server
+# remove datadir
+# xtrabackup move back
+# restart
+SELECT * FROM t;
+i
+1
+DROP TABLE t;
diff --git a/mysql-test/suite/mariabackup/innodb_force_recovery.test b/mysql-test/suite/mariabackup/innodb_force_recovery.test
new file mode 100644
index 00000000000..3a7b3c6106c
--- /dev/null
+++ b/mysql-test/suite/mariabackup/innodb_force_recovery.test
@@ -0,0 +1,138 @@
+# This test checks if "innodb_force_recovery" is only allowed with "--prepare"
+# (for mariabackup) and "--apply-log" (for innobackupex), and is limited to
+# "SRV_FORCE_IGNORE_CORRUPT" only.
+
+# Setup.
+--source include/have_innodb.inc
+
+--let targetdir=$MYSQLTEST_VARDIR/tmp/backup
+--let backuplog=$MYSQLTEST_VARDIR/tmp/backup.log
+
+CREATE TABLE t(i INT) ENGINE INNODB;
+INSERT INTO t VALUES(1);
+
+# Check for command line arguments.
+--echo # "innodb_force_recovery=1" should be allowed with "--prepare" only (mariabackup)
+--disable_result_log
+--error 1
+exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --innodb-force-recovery=1 --target-dir=$targetdir >$backuplog;
+--enable_result_log
+--let SEARCH_PATTERN=should only be used with "--prepare"
+--let SEARCH_FILE=$backuplog
+--source include/search_pattern_in_file.inc
+
+--echo # "innodb_force_recovery=1" should be allowed with "--apply-log" only (innobackupex)
+--disable_result_log
+--error 1
+exec $XTRABACKUP --innobackupex --defaults-file=$MYSQLTEST_VARDIR/my.cnf --no-timestamp --innodb-force-recovery=1 $targetdir >$backuplog;
+--enable_result_log
+--let SEARCH_PATTERN=should only be used with "--apply-log"
+--let SEARCH_FILE=$backuplog
+--source include/search_pattern_in_file.inc
+
+--disable_result_log
+exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir;
+--enable_result_log
+--echo # "innodb_force_recovery" should be limited to "SRV_FORCE_IGNORE_CORRUPT" (mariabackup)
+--disable_result_log
+exec $XTRABACKUP --prepare --innodb-force-recovery=2 --target-dir=$targetdir >$backuplog;
+--enable_result_log
+--let SEARCH_PATTERN=innodb_force_recovery = 1
+--let SEARCH_FILE=$backuplog
+--source include/search_pattern_in_file.inc
+rmdir $targetdir;
+
+--disable_result_log
+exec $XTRABACKUP --innobackupex --defaults-file=$MYSQLTEST_VARDIR/my.cnf --no-timestamp $targetdir;
+--enable_result_log
+--echo # "innodb_force_recovery" should be limited to "SRV_FORCE_IGNORE_CORRUPT" (innobackupex)
+--disable_result_log
+exec $XTRABACKUP --innobackupex --apply-log --innodb-force-recovery=2 $targetdir >$backuplog;
+--enable_result_log
+--let SEARCH_PATTERN=innodb_force_recovery = 1
+--let SEARCH_FILE=$backuplog
+--source include/search_pattern_in_file.inc
+rmdir $targetdir;
+
+# Check for default file ("backup-my.cnf").
+--disable_result_log
+exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir;
+--enable_result_log
+perl;
+my $cfg_path="$ENV{'targetdir'}/backup-my.cnf";
+open(my $fd, '>>', "$cfg_path");
+print $fd "innodb_force_recovery=1\n";
+close $fd;
+EOF
+--echo # "innodb_force_recovery" should be read from "backup-my.cnf" (mariabackup)
+--disable_result_log
+exec $XTRABACKUP --defaults-file=$targetdir/backup-my.cnf --prepare --export --target-dir=$targetdir >$backuplog;
+--enable_result_log
+--let SEARCH_PATTERN=innodb_force_recovery = 1
+--let SEARCH_FILE=$backuplog
+--source include/search_pattern_in_file.inc
+rmdir $targetdir;
+
+--disable_result_log
+exec $XTRABACKUP --innobackupex --defaults-file=$MYSQLTEST_VARDIR/my.cnf --no-timestamp $targetdir;
+--enable_result_log
+perl;
+my $cfg_path="$ENV{'targetdir'}/backup-my.cnf";
+open(my $fd, '>>', "$cfg_path");
+print $fd "innodb_force_recovery=2\n";
+close $fd;
+EOF
+--echo # "innodb_force_recovery=1" should be read from "backup-my.cnf" (innobackupex)
+--disable_result_log
+exec $XTRABACKUP --innobackupex --defaults-file=$targetdir/backup-my.cnf --apply-log --export $targetdir >$backuplog;
+--enable_result_log
+--let SEARCH_PATTERN=innodb_force_recovery = 1
+--let SEARCH_FILE=$backuplog
+--source include/search_pattern_in_file.inc
+rmdir $targetdir;
+
+# Check for command line argument precedence.
+--disable_result_log
+exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir;
+--enable_result_log
+perl;
+my $cfg_path="$ENV{'targetdir'}/backup-my.cnf";
+open(my $fd, '>>', "$cfg_path");
+print $fd "innodb_force_recovery=1\n";
+close $fd;
+EOF
+--echo # "innodb_force_recovery" from the command line should override "backup-my.cnf" (mariabackup)
+--disable_result_log
+exec $XTRABACKUP --defaults-file=$targetdir/backup-my.cnf --prepare --innodb-force-recovery=0 --target-dir=$targetdir >$backuplog;
+--enable_result_log
+--let SEARCH_PATTERN=innodb_force_recovery = 1
+--let SEARCH_FILE=$backuplog
+--source include/search_pattern_in_file.inc
+rmdir $targetdir;
+
+--disable_result_log
+exec $XTRABACKUP --innobackupex --defaults-file=$MYSQLTEST_VARDIR/my.cnf --no-timestamp $targetdir;
+--enable_result_log
+perl;
+my $cfg_path="$ENV{'targetdir'}/backup-my.cnf";
+open(my $fd, '>>', "$cfg_path");
+print $fd "innodb_force_recovery=2\n";
+close $fd;
+EOF
+--echo # "innodb_force_recovery" from the command line should override "backup-my.cnf" (innobackupex)
+--disable_result_log
+exec $XTRABACKUP --innobackupex --defaults-file=$targetdir/backup-my.cnf --apply-log --innodb-force-recovery=0 --export $targetdir >$backuplog;
+--enable_result_log
+--let SEARCH_PATTERN=innodb_force_recovery = 1
+--let SEARCH_FILE=$backuplog
+--source include/search_pattern_in_file.inc
+
+--source include/restart_and_restore.inc
+
+# Check for restore.
+SELECT * FROM t;
+
+# Clean-up.
+DROP TABLE t;
+--rmdir $targetdir
+--remove_file $backuplog
diff --git a/mysql-test/suite/optimizer_unfixed_bugs/r/bug42991.result b/mysql-test/suite/optimizer_unfixed_bugs/r/bug42991.result
index f5554563a18..40f505d8260 100644
--- a/mysql-test/suite/optimizer_unfixed_bugs/r/bug42991.result
+++ b/mysql-test/suite/optimizer_unfixed_bugs/r/bug42991.result
@@ -245,7 +245,7 @@ UNLOCK TABLES;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-select * from `table5` where (col2 <= '6566-06-15' AND col24 <> 'd') group by `col83` order by `col83` desc ;
+select * from `table5` where (col2 <= '6566-06-15' AND (col24 < 'd' or col24 > 'd')) group by `col83` order by `col83` desc ;
col0 col1 col2 col3 col4 col5 col6 col7 col8 col9 col10 col11 col12 col13 col14 col15 col16 col17 col18 col19 col20 col21 col22 col23 col24 col25 col26 col27 col28 col29 col30 col31 col32 col33 col34 col35 col36 col37 col38 col39 col40 col41 col42 col43 col44 col45 col46 col47 col48 col49 col50 col51 col52 col53 col54 col55 col56 col57 col58 col59 col60 col61 col62 col63 col64 col65 col66 col67 col68 col69 col70 col71 col72 col73 col74 col75 col76 col77 col78 col79 col80 col81 col82 col83 col84 col85 col86 col87 col88 col89 col90 col91 col92 col93 col94 col95 col96 col97 col98 col99 col100 col101 col102 col103 col104 col105 col106 col107 col108 col109 col110 col111 col112 col113 col114 col115 col116 col117 col118 col119 col120 col121 col122 col123 col124 col125 col126 col127 col128 col129 col130 col131 col132 col133 col134 col135 col136 col137 col138 col139 col140 col141 col142 col143 col144 col145 col146 col147 col148 col149 col150 col151 col152 col153 col154 col155 col156 col157 col158 col159 col160 col161 col162 col163 col164 col165 col166 col167 col168 col169 col170 col171 col172 col173 col174 col175
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'd'
diff --git a/mysql-test/suite/optimizer_unfixed_bugs/t/bug42991.test b/mysql-test/suite/optimizer_unfixed_bugs/t/bug42991.test
index d59e9e1fbeb..9e8e5c4b3cd 100644
--- a/mysql-test/suite/optimizer_unfixed_bugs/t/bug42991.test
+++ b/mysql-test/suite/optimizer_unfixed_bugs/t/bug42991.test
@@ -242,9 +242,9 @@ UNLOCK TABLES;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-#explain select * from `table5` where (col2 <= '6566-06-15' AND col24 <> 'd') group by `col83` order by `col83` desc ;
+#explain select * from `table5` where (col2 <= '6566-06-15' AND (col24 < 'd' or col24 > 'd') group by `col83` order by `col83` desc ;
-select * from `table5` where (col2 <= '6566-06-15' AND col24 <> 'd') group by `col83` order by `col83` desc ;
+select * from `table5` where (col2 <= '6566-06-15' AND (col24 < 'd' or col24 > 'd')) group by `col83` order by `col83` desc ;
drop table `table5`;
SET debug_dbug= @saved_dbug;
diff --git a/mysql-test/suite/rpl/t/rpl_row_tbl_metadata.test b/mysql-test/suite/rpl/t/rpl_row_tbl_metadata.test
index b0588cb2d58..d3a115e986a 100644
--- a/mysql-test/suite/rpl/t/rpl_row_tbl_metadata.test
+++ b/mysql-test/suite/rpl/t/rpl_row_tbl_metadata.test
@@ -329,7 +329,7 @@ while($ntables)
-- echo ### detect failure. Before the patch mysqlbinlog would find
-- echo ### a corrupted event, thence would fail.
-- let $MYSQLD_DATADIR= `SELECT @@datadir`
--- exec $MYSQL_BINLOG -v --hex $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug50018.binlog
+-- exec $MYSQL_BINLOG -v --hexdump $MYSQLD_DATADIR/master-bin.000001 > $MYSQLTEST_VARDIR/tmp/mysqlbinlog_bug50018.binlog
## clean up
## For debugging purposes you might want not to remove these
diff --git a/mysql-test/suite/versioning/r/alter.result b/mysql-test/suite/versioning/r/alter.result
index 3cdba78b973..d0aa49f2fde 100644
--- a/mysql-test/suite/versioning/r/alter.result
+++ b/mysql-test/suite/versioning/r/alter.result
@@ -80,7 +80,7 @@ t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
alter table t add column trx_start timestamp(6) as row start;
-ERROR HY000: Duplicate ROW START column `trx_start`
+ERROR HY000: Table `t` is not system-versioned
alter table t add system versioning;
show create table t;
Table Create Table
@@ -697,6 +697,55 @@ set statement system_versioning_alter_history=keep for
alter table t1 drop system versioning, modify column a tinyint;
drop table t1;
#
+# MDEV-24690 Dropping primary key column from versioned table always fails with 1072
+#
+create table t1 (a int, b int primary key) with system versioning;
+alter table t1 drop column b;
+create or replace table t1 (
+a int, b int primary key,
+row_start timestamp(6) as row start,
+row_end timestamp(6) as row end,
+period for system_time(row_start, row_end)
+) with system versioning;
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) NOT NULL,
+ `row_start` timestamp(6) GENERATED ALWAYS AS ROW START,
+ `row_end` timestamp(6) GENERATED ALWAYS AS ROW END,
+ PRIMARY KEY (`b`,`row_end`),
+ PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
+alter table t1 drop column b;
+ERROR 42000: Key column 'b' doesn't exist in table
+create or replace table t1 (
+a int, b int primary key,
+row_start timestamp(6) as row start invisible,
+row_end timestamp(6) as row end invisible,
+period for system_time(row_start, row_end)
+) with system versioning;
+show create table t1;
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `a` int(11) DEFAULT NULL,
+ `b` int(11) NOT NULL,
+ `row_start` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE,
+ `row_end` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE,
+ PRIMARY KEY (`b`,`row_end`),
+ PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
+alter table t1 drop column b;
+ERROR 42000: Key column 'b' doesn't exist in table
+drop table t1;
+#
+# MDEV-25172 Wrong error message for ADD COLUMN .. AS ROW START
+#
+create or replace table t1 (x int);
+alter table t1 add column y timestamp(6) as row start;
+ERROR HY000: Table `t1` is not system-versioned
+drop table t1;
+#
# MDEV-21941 RENAME doesn't work for system time or period fields
#
create or replace table t1 (a int) with system versioning;
diff --git a/mysql-test/suite/versioning/r/auto_increment.result b/mysql-test/suite/versioning/r/autoinc.result
index 8ff1bed8fe3..e785c5d300e 100644
--- a/mysql-test/suite/versioning/r/auto_increment.result
+++ b/mysql-test/suite/versioning/r/autoinc.result
@@ -63,3 +63,13 @@ A x y x y
1 7 17 7 17
drop table t1;
drop table t2;
+#
+# MDEV-22562 Assertion `next_insert_id == 0' upon UPDATE on system-versioned table
+#
+create table t1 (pk integer auto_increment primary key) engine=myisam with system versioning;
+insert delayed into t1 (pk) values (1);
+lock tables t1 write;
+update t1 set pk= 0;
+update t1 set pk= 0;
+unlock tables;
+drop table t1;
diff --git a/mysql-test/suite/versioning/t/alter.test b/mysql-test/suite/versioning/t/alter.test
index 9e0ed7cabb9..786627da35e 100644
--- a/mysql-test/suite/versioning/t/alter.test
+++ b/mysql-test/suite/versioning/t/alter.test
@@ -68,7 +68,7 @@ select row_start from t;
alter table t drop system versioning;
show create table t;
---error ER_VERS_DUPLICATE_ROW_START_END
+--error ER_VERS_NOT_VERSIONED
alter table t add column trx_start timestamp(6) as row start;
alter table t add system versioning;
@@ -595,6 +595,44 @@ alter table t1 drop system versioning, modify column a tinyint;
drop table t1;
--echo #
+--echo # MDEV-24690 Dropping primary key column from versioned table always fails with 1072
+--echo #
+create table t1 (a int, b int primary key) with system versioning;
+alter table t1 drop column b;
+
+create or replace table t1 (
+ a int, b int primary key,
+ row_start timestamp(6) as row start,
+ row_end timestamp(6) as row end,
+ period for system_time(row_start, row_end)
+) with system versioning;
+show create table t1;
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 drop column b;
+
+create or replace table t1 (
+a int, b int primary key,
+ row_start timestamp(6) as row start invisible,
+ row_end timestamp(6) as row end invisible,
+ period for system_time(row_start, row_end)
+) with system versioning;
+show create table t1;
+--error ER_KEY_COLUMN_DOES_NOT_EXITS
+alter table t1 drop column b;
+
+# cleanup
+drop table t1;
+
+--echo #
+--echo # MDEV-25172 Wrong error message for ADD COLUMN .. AS ROW START
+--echo #
+create or replace table t1 (x int);
+--error ER_VERS_NOT_VERSIONED
+alter table t1 add column y timestamp(6) as row start;
+# cleanup
+drop table t1;
+
+--echo #
--echo # MDEV-21941 RENAME doesn't work for system time or period fields
--echo #
create or replace table t1 (a int) with system versioning;
diff --git a/mysql-test/suite/versioning/t/auto_increment.test b/mysql-test/suite/versioning/t/autoinc.test
index 804c0424179..7c87c17301a 100644
--- a/mysql-test/suite/versioning/t/auto_increment.test
+++ b/mysql-test/suite/versioning/t/autoinc.test
@@ -47,4 +47,17 @@ select t1.x = t2.x and t1.y = t2.y as A, t1.x, t1.y, t2.x, t2.y from t1 inner jo
drop table t1;
drop table t2;
+--echo #
+--echo # MDEV-22562 Assertion `next_insert_id == 0' upon UPDATE on system-versioned table
+--echo #
+create table t1 (pk integer auto_increment primary key) engine=myisam with system versioning;
+insert delayed into t1 (pk) values (1);
+lock tables t1 write;
+update t1 set pk= 0;
+update t1 set pk= 0;
+unlock tables;
+
+# cleanup
+drop table t1;
+
-- source suite/versioning/common_finish.inc
diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt
index d2d740aba17..5a4eeeba603 100644
--- a/mysys/CMakeLists.txt
+++ b/mysys/CMakeLists.txt
@@ -16,7 +16,7 @@
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/mysys)
-SET(MYSYS_SOURCES array.c charset-def.c charset.c crc32ieee.cc my_default.c
+SET(MYSYS_SOURCES array.c charset-def.c charset.c my_default.c
get_password.c
errors.c hash.c list.c
mf_cache.c mf_dirname.c mf_fn_ext.c
@@ -60,19 +60,29 @@ ENDIF()
IF(MSVC)
SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c)
+ IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ SET (MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32c_amd64.cc)
+ ENDIF()
ADD_DEFINITIONS(-DHAVE_SSE42 -DHAVE_PCLMUL)
IF(CLANG_CL)
- SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.cc crc32/crc32c.c PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul")
+ SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul")
ENDIF()
ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64|i386|i686")
- MY_CHECK_C_COMPILER_FLAG(-msse4.2)
- MY_CHECK_C_COMPILER_FLAG(-mpclmul)
+ MY_CHECK_CXX_COMPILER_FLAG(-msse4.2)
+ MY_CHECK_CXX_COMPILER_FLAG(-mpclmul)
CHECK_INCLUDE_FILE(cpuid.h HAVE_CPUID_H)
CHECK_INCLUDE_FILE(x86intrin.h HAVE_X86INTRIN_H)
- IF(have_C__msse4.2 AND have_C__mpclmul AND HAVE_CPUID_H AND HAVE_X86INTRIN_H)
- SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c)
- SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c crc32/crc32c.cc PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul")
- ADD_DEFINITIONS(-DHAVE_SSE42 -DHAVE_PCLMUL)
+ IF(have_CXX__msse4.2 AND HAVE_CPUID_H)
+ ADD_DEFINITIONS(-DHAVE_SSE42)
+ IF (have_CXX__mpclmul AND HAVE_X86INTRIN_H)
+ ADD_DEFINITIONS(-DHAVE_PCLMUL)
+ SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_x86.c)
+ SET_SOURCE_FILES_PROPERTIES(crc32/crc32_x86.c PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul")
+ IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
+ SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32c_amd64.cc)
+ SET_SOURCE_FILES_PROPERTIES(crc32/crc32c_amd64.cc PROPERTIES COMPILE_FLAGS "-msse4.2 -mpclmul")
+ ENDIF()
+ ENDIF()
ENDIF()
ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
IF(CMAKE_COMPILER_IS_GNUCC)
@@ -129,11 +139,15 @@ ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|AARCH64")
COMPILE_FLAGS "-march=armv8-a+crc+crypto")
ENDIF()
ENDIF()
-ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64|powerpc64" OR CMAKE_SYSTEM_NAME MATCHES AIX)
+ENDIF()
+
+IF(CMAKE_SYSTEM_PROCESSOR MATCHES "ppc64|powerpc64" OR CMAKE_SYSTEM_NAME MATCHES AIX)
SET(MYSYS_SOURCES ${MYSYS_SOURCES} crc32/crc32_ppc64.c crc32/crc32c_ppc.c)
SET_SOURCE_FILES_PROPERTIES(crc32/crc32_ppc64.c crc32/crc32c_ppc.c PROPERTIES
COMPILE_FLAGS "${COMPILE_FLAGS} -maltivec -mvsx -mpower8-vector -mcrypto -mpower8-vector")
ADD_DEFINITIONS(-DHAVE_POWER8 -DHAS_ALTIVEC)
+ELSE()
+ SET (MYSYS_SOURCES ${MYSYS_SOURCES} crc32ieee.cc)
ENDIF()
IF(UNIX)
diff --git a/mysys/crc32/crc32_x86.c b/mysys/crc32/crc32_x86.c
index 1e5d2a0a089..f077399caca 100644
--- a/mysys/crc32/crc32_x86.c
+++ b/mysys/crc32/crc32_x86.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2020 MariaDB
+/* Copyright (c) 2020, 2021, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -55,38 +55,14 @@
#include <stdint.h>
#include <stddef.h>
-#if defined(__GNUC__)
+#ifdef __GNUC__
#include <x86intrin.h>
-#include <cpuid.h>
#elif defined(_MSC_VER)
#include <intrin.h>
#else
#error "unknown compiler"
#endif
-static int has_sse42_and_pclmul(uint32_t recx)
-{
- /* 1 << 20 is SSE42, 1 << 1 is PCLMULQDQ */
-#define bits_SSE42_AND_PCLMUL (1 << 20 | 1 << 1)
- return (recx & bits_SSE42_AND_PCLMUL) == bits_SSE42_AND_PCLMUL;
-}
-
-#ifdef __GNUC__
-int crc32_pclmul_enabled(void)
-{
- uint32_t reax= 0, rebx= 0, recx= 0, redx= 0;
- __cpuid(1, reax, rebx, recx, redx);
- return has_sse42_and_pclmul(recx);
-}
-#elif defined(_MSC_VER)
-int crc32_pclmul_enabled(void)
-{
- int regs[4];
- __cpuid(regs, 1);
- return has_sse42_and_pclmul(regs[2]);
-}
-#endif
-
/**
* @brief Shifts left 128 bit register by specified number of bytes
*
diff --git a/mysys/crc32/crc32c.cc b/mysys/crc32/crc32c.cc
index b6c80886ec1..082d467e7da 100644
--- a/mysys/crc32/crc32c.cc
+++ b/mysys/crc32/crc32c.cc
@@ -32,11 +32,20 @@ static inline uint32_t DecodeFixed32(const char *ptr)
#endif
#ifdef HAVE_SSE42
-#include <nmmintrin.h>
-#include <wmmintrin.h>
-#ifdef __GNUC__
-#include <cpuid.h>
-#endif
+# ifdef __GNUC__
+# include <cpuid.h>
+# if __GNUC__ < 5 && !defined __clang__
+/* the headers do not really work in GCC before version 5 */
+# define _mm_crc32_u8(crc,data) __builtin_ia32_crc32qi(crc,data)
+# define _mm_crc32_u32(crc,data) __builtin_ia32_crc32si(crc,data)
+# define _mm_crc32_u64(crc,data) __builtin_ia32_crc32di(crc,data)
+# else
+# include <nmmintrin.h>
+# endif
+# define USE_SSE42 __attribute__((target("sse4.2")))
+# else
+# define USE_SSE42 /* nothing */
+# endif
#endif
@@ -337,19 +346,8 @@ static inline uint32_t LE_LOAD32(const uint8_t *p) {
return DecodeFixed32(reinterpret_cast<const char*>(p));
}
-#if defined(HAVE_SSE42) && (SIZEOF_SIZE_T == 8)
-
-static inline uint64_t DecodeFixed64(const char *ptr)
+static inline void Slow_CRC32(uint64_t* l, uint8_t const **p)
{
- return uint8korr(ptr);
-}
-
-static inline uint64_t LE_LOAD64(const uint8_t *p) {
- return DecodeFixed64(reinterpret_cast<const char*>(p));
-}
-#endif
-
-static inline void Slow_CRC32(uint64_t* l, uint8_t const **p) {
uint32_t c = static_cast<uint32_t>(*l ^ LE_LOAD32(*p));
*p += 4;
*l = table3_[c & 0xff] ^
@@ -365,27 +363,6 @@ static inline void Slow_CRC32(uint64_t* l, uint8_t const **p) {
table0_[c >> 24];
}
-__attribute__((unused)) static inline void Fast_CRC32(uint64_t* l, uint8_t const **p) {
-#ifndef HAVE_SSE42
- Slow_CRC32(l, p);
-#elif (SIZEOF_SIZE_T == 8)
- *l = _mm_crc32_u64(*l, LE_LOAD64(*p));
- *p += 8;
-#else
- *l = _mm_crc32_u32(static_cast<unsigned int>(*l), LE_LOAD32(*p));
- *p += 4;
- *l = _mm_crc32_u32(static_cast<unsigned int>(*l), LE_LOAD32(*p));
- *p += 4;
-#endif
-}
-
-template<void (*CRC32)(uint64_t*, uint8_t const**)>
-uint32_t ExtendImpl(uint32_t crc, const char* buf, size_t size) {
-
- const uint8_t *p = reinterpret_cast<const uint8_t *>(buf);
- const uint8_t *e = p + size;
- uint64_t l = crc ^ 0xffffffffu;
-
#ifdef ALIGN
#undef ALIGN
#endif
@@ -398,70 +375,115 @@ uint32_t ExtendImpl(uint32_t crc, const char* buf, size_t size) {
l = table0_[c] ^ (l >> 8); \
} while (0)
+static uint32_t crc32c_slow(uint32_t crc, const char* buf, size_t size)
+{
+ const uint8_t *p = reinterpret_cast<const uint8_t *>(buf);
+ const uint8_t *e = p + size;
+ uint64_t l = crc ^ 0xffffffffu;
// Point x at first 16-byte aligned byte in string. This might be
// just past the end of the string.
const uintptr_t pval = reinterpret_cast<uintptr_t>(p);
const uint8_t* x = reinterpret_cast<const uint8_t*>(ALIGN(pval, 4));
- if (x <= e) {
+ if (x <= e)
// Process bytes until finished or p is 16-byte aligned
- while (p != x) {
+ while (p != x)
STEP1;
- }
- }
// Process bytes 16 at a time
- while ((e-p) >= 16) {
- CRC32(&l, &p);
- CRC32(&l, &p);
+ while ((e-p) >= 16)
+ {
+ Slow_CRC32(&l, &p);
+ Slow_CRC32(&l, &p);
}
// Process bytes 8 at a time
- while ((e-p) >= 8) {
- CRC32(&l, &p);
- }
+ while ((e-p) >= 8)
+ Slow_CRC32(&l, &p);
// Process the last few bytes
- while (p != e) {
+ while (p != e)
STEP1;
- }
-#undef STEP1
-#undef ALIGN
return static_cast<uint32_t>(l ^ 0xffffffffu);
}
-// Detect if ARM64 CRC or not.
-#ifndef HAVE_ARMV8_CRC
-// Detect if SS42 or not.
-#ifndef HAVE_POWER8
+#if defined HAVE_POWER8
+#elif defined HAVE_ARMV8_CRC
+#elif defined HAVE_SSE42
+constexpr uint32_t cpuid_ecx_SSE42= 1U << 20;
+constexpr uint32_t cpuid_ecx_SSE42_AND_PCLMUL= cpuid_ecx_SSE42 | 1U<<1;
-static bool isSSE42() {
-#ifndef HAVE_SSE42
- return false;
-#elif defined(__GNUC__)
+static uint32_t cpuid_ecx()
+{
+#ifdef __GNUC__
uint32_t reax= 0, rebx= 0, recx= 0, redx= 0;
__cpuid(1, reax, rebx, recx, redx);
- return (recx & ((int)1 << 20)) != 0;
-#elif defined(_MSC_VER)
- int info[4];
- __cpuid(info, 0x00000001);
- return (info[2] & ((int)1 << 20)) != 0;
+ return recx;
+#elif defined _MSC_VER
+ int regs[4];
+ __cpuid(regs, 1);
+ return regs[2];
#else
- return false;
+# error "unknown compiler"
#endif
}
-#ifdef HAVE_SSE42
-extern "C" int crc32_pclmul_enabled();
-#endif
+extern "C" int crc32_pclmul_enabled(void)
+{
+ return !(~cpuid_ecx() & cpuid_ecx_SSE42_AND_PCLMUL);
+}
-static bool isPCLMULQDQ() {
-#ifdef HAVE_SSE42
- return crc32_pclmul_enabled();
-#else
- return false;
+#if SIZEOF_SIZE_T == 8
+extern "C" uint32_t crc32c_3way(uint32_t crc, const char *buf, size_t len);
+
+USE_SSE42
+static inline uint64_t LE_LOAD64(const uint8_t *ptr)
+{
+ return uint8korr(reinterpret_cast<const char*>(ptr));
+}
#endif
+
+USE_SSE42
+static inline void Fast_CRC32(uint64_t* l, uint8_t const **p)
+{
+# if (SIZEOF_SIZE_T == 8)
+ *l = _mm_crc32_u64(*l, LE_LOAD64(*p));
+ *p += 8;
+# else
+ *l = _mm_crc32_u32(static_cast<unsigned int>(*l), LE_LOAD32(*p));
+ *p += 4;
+ *l = _mm_crc32_u32(static_cast<unsigned int>(*l), LE_LOAD32(*p));
+ *p += 4;
+# endif
}
-#endif // HAVE_POWER8
-#endif // HAVE_ARMV8_CRC
+USE_SSE42
+static uint32_t crc32c_sse42(uint32_t crc, const char* buf, size_t size)
+{
+ const uint8_t *p = reinterpret_cast<const uint8_t *>(buf);
+ const uint8_t *e = p + size;
+ uint64_t l = crc ^ 0xffffffffu;
+
+ // Point x at first 16-byte aligned byte in string. This might be
+ // just past the end of the string.
+ const uintptr_t pval = reinterpret_cast<uintptr_t>(p);
+ const uint8_t* x = reinterpret_cast<const uint8_t*>(ALIGN(pval, 4));
+ if (x <= e)
+ // Process bytes until finished or p is 16-byte aligned
+ while (p != x)
+ STEP1;
+ // Process bytes 16 at a time
+ while ((e-p) >= 16)
+ {
+ Fast_CRC32(&l, &p);
+ Fast_CRC32(&l, &p);
+ }
+ // Process bytes 8 at a time
+ while ((e-p) >= 8)
+ Fast_CRC32(&l, &p);
+ // Process the last few bytes
+ while (p != e)
+ STEP1;
+ return static_cast<uint32_t>(l ^ 0xffffffffu);
+}
+#endif
typedef uint32_t (*Function)(uint32_t, const char*, size_t);
@@ -507,14 +529,6 @@ static int arch_ppc_probe(void) {
return arch_ppc_crc32;
}
#endif // __linux__
-
-static bool isAltiVec() {
- if (arch_ppc_probe()) {
- return true;
- } else {
- return false;
- }
-}
#endif
#if defined(HAVE_ARMV8_CRC)
@@ -526,760 +540,59 @@ static uint32_t ExtendARMImpl(uint32_t crc, const char *buf, size_t size) {
}
#endif
-extern "C" const char * my_crc32c_implementation()
+static inline Function Choose_Extend()
{
-#if defined(HAVE_POWER8) && defined(HAS_ALTIVEC)
+#if defined HAVE_POWER8 && defined HAS_ALTIVEC
if (arch_ppc_probe())
- return "Using POWER8 crc32 instructions";
+ return ExtendPPCImpl;
#elif defined(HAVE_ARMV8_CRC)
- const char *ret = crc32c_aarch64_available();
- if (ret)
- return ret ;
+ if (crc32c_aarch64_available())
+ return ExtendARMImpl;
#elif HAVE_SSE42
- if (isSSE42())
- {
- if (SIZEOF_SIZE_T == 8 && isPCLMULQDQ())
- return "Using crc32 + pclmulqdq instructions";
- return "Using SSE4.2 crc32 instructions";
+# if defined HAVE_PCLMUL && SIZEOF_SIZE_T == 8
+ switch (cpuid_ecx() & cpuid_ecx_SSE42_AND_PCLMUL) {
+ case cpuid_ecx_SSE42_AND_PCLMUL:
+ return crc32c_3way;
+ case cpuid_ecx_SSE42:
+ return crc32c_sse42;
}
+# else
+ if (cpuid_ecx() & cpuid_ecx_SSE42)
+ return crc32c_sse42;
+# endif
#endif
- return "Using generic crc32 instructions";
-}
-
-
-/*
- * Copyright 2016 Ferry Toth, Exalon Delft BV, The Netherlands
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event will the author be held liable for any damages
- * arising from the use of this software.
- * Permission is granted to anyone to use this software for any purpose,
- * including commercial applications, and to alter it and redistribute it
- * freely, subject to the following restrictions:
- * 1. The origin of this software must not be misrepresented; you must not
- * claim that you wrote the original software. If you use this software
- * in a product, an acknowledgment in the product documentation would be
- * appreciated but is not required.
- * 2. Altered source versions must be plainly marked as such, and must not be
- * misrepresented as being the original software.
- * 3. This notice may not be removed or altered from any source distribution.
- * Ferry Toth
- * ftoth@exalondelft.nl
- *
- * https://github.com/htot/crc32c
- *
- * Modified by Facebook
- *
- * Original intel whitepaper:
- * "Fast CRC Computation for iSCSI Polynomial Using CRC32 Instruction"
- * https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/crc-iscsi-polynomial-crc32-instruction-paper.pdf
- *
- * This version is from the folly library, created by Dave Watson <davejwatson@fb.com>
- *
-*/
-#if defined HAVE_SSE42 && defined HAVE_PCLMUL && SIZEOF_SIZE_T == 8
-
-
-#define CRCtriplet(crc, buf, offset) \
- crc##0 = _mm_crc32_u64(crc##0, *(buf##0 + offset)); \
- crc##1 = _mm_crc32_u64(crc##1, *(buf##1 + offset)); \
- crc##2 = _mm_crc32_u64(crc##2, *(buf##2 + offset));
-
-#define CRCduplet(crc, buf, offset) \
- crc##0 = _mm_crc32_u64(crc##0, *(buf##0 + offset)); \
- crc##1 = _mm_crc32_u64(crc##1, *(buf##1 + offset));
-
-#define CRCsinglet(crc, buf, offset) \
- crc = _mm_crc32_u64(crc, *(uint64_t*)(buf + offset));
-
-
-// Numbers taken directly from intel whitepaper.
-// clang-format off
-static const uint64_t clmul_constants[] = {
- 0x14cd00bd6, 0x105ec76f0, 0x0ba4fc28e, 0x14cd00bd6,
- 0x1d82c63da, 0x0f20c0dfe, 0x09e4addf8, 0x0ba4fc28e,
- 0x039d3b296, 0x1384aa63a, 0x102f9b8a2, 0x1d82c63da,
- 0x14237f5e6, 0x01c291d04, 0x00d3b6092, 0x09e4addf8,
- 0x0c96cfdc0, 0x0740eef02, 0x18266e456, 0x039d3b296,
- 0x0daece73e, 0x0083a6eec, 0x0ab7aff2a, 0x102f9b8a2,
- 0x1248ea574, 0x1c1733996, 0x083348832, 0x14237f5e6,
- 0x12c743124, 0x02ad91c30, 0x0b9e02b86, 0x00d3b6092,
- 0x018b33a4e, 0x06992cea2, 0x1b331e26a, 0x0c96cfdc0,
- 0x17d35ba46, 0x07e908048, 0x1bf2e8b8a, 0x18266e456,
- 0x1a3e0968a, 0x11ed1f9d8, 0x0ce7f39f4, 0x0daece73e,
- 0x061d82e56, 0x0f1d0f55e, 0x0d270f1a2, 0x0ab7aff2a,
- 0x1c3f5f66c, 0x0a87ab8a8, 0x12ed0daac, 0x1248ea574,
- 0x065863b64, 0x08462d800, 0x11eef4f8e, 0x083348832,
- 0x1ee54f54c, 0x071d111a8, 0x0b3e32c28, 0x12c743124,
- 0x0064f7f26, 0x0ffd852c6, 0x0dd7e3b0c, 0x0b9e02b86,
- 0x0f285651c, 0x0dcb17aa4, 0x010746f3c, 0x018b33a4e,
- 0x1c24afea4, 0x0f37c5aee, 0x0271d9844, 0x1b331e26a,
- 0x08e766a0c, 0x06051d5a2, 0x093a5f730, 0x17d35ba46,
- 0x06cb08e5c, 0x11d5ca20e, 0x06b749fb2, 0x1bf2e8b8a,
- 0x1167f94f2, 0x021f3d99c, 0x0cec3662e, 0x1a3e0968a,
- 0x19329634a, 0x08f158014, 0x0e6fc4e6a, 0x0ce7f39f4,
- 0x08227bb8a, 0x1a5e82106, 0x0b0cd4768, 0x061d82e56,
- 0x13c2b89c4, 0x188815ab2, 0x0d7a4825c, 0x0d270f1a2,
- 0x10f5ff2ba, 0x105405f3e, 0x00167d312, 0x1c3f5f66c,
- 0x0f6076544, 0x0e9adf796, 0x026f6a60a, 0x12ed0daac,
- 0x1a2adb74e, 0x096638b34, 0x19d34af3a, 0x065863b64,
- 0x049c3cc9c, 0x1e50585a0, 0x068bce87a, 0x11eef4f8e,
- 0x1524fa6c6, 0x19f1c69dc, 0x16cba8aca, 0x1ee54f54c,
- 0x042d98888, 0x12913343e, 0x1329d9f7e, 0x0b3e32c28,
- 0x1b1c69528, 0x088f25a3a, 0x02178513a, 0x0064f7f26,
- 0x0e0ac139e, 0x04e36f0b0, 0x0170076fa, 0x0dd7e3b0c,
- 0x141a1a2e2, 0x0bd6f81f8, 0x16ad828b4, 0x0f285651c,
- 0x041d17b64, 0x19425cbba, 0x1fae1cc66, 0x010746f3c,
- 0x1a75b4b00, 0x18db37e8a, 0x0f872e54c, 0x1c24afea4,
- 0x01e41e9fc, 0x04c144932, 0x086d8e4d2, 0x0271d9844,
- 0x160f7af7a, 0x052148f02, 0x05bb8f1bc, 0x08e766a0c,
- 0x0a90fd27a, 0x0a3c6f37a, 0x0b3af077a, 0x093a5f730,
- 0x04984d782, 0x1d22c238e, 0x0ca6ef3ac, 0x06cb08e5c,
- 0x0234e0b26, 0x063ded06a, 0x1d88abd4a, 0x06b749fb2,
- 0x04597456a, 0x04d56973c, 0x0e9e28eb4, 0x1167f94f2,
- 0x07b3ff57a, 0x19385bf2e, 0x0c9c8b782, 0x0cec3662e,
- 0x13a9cba9e, 0x0e417f38a, 0x093e106a4, 0x19329634a,
- 0x167001a9c, 0x14e727980, 0x1ddffc5d4, 0x0e6fc4e6a,
- 0x00df04680, 0x0d104b8fc, 0x02342001e, 0x08227bb8a,
- 0x00a2a8d7e, 0x05b397730, 0x168763fa6, 0x0b0cd4768,
- 0x1ed5a407a, 0x0e78eb416, 0x0d2c3ed1a, 0x13c2b89c4,
- 0x0995a5724, 0x1641378f0, 0x19b1afbc4, 0x0d7a4825c,
- 0x109ffedc0, 0x08d96551c, 0x0f2271e60, 0x10f5ff2ba,
- 0x00b0bf8ca, 0x00bf80dd2, 0x123888b7a, 0x00167d312,
- 0x1e888f7dc, 0x18dcddd1c, 0x002ee03b2, 0x0f6076544,
- 0x183e8d8fe, 0x06a45d2b2, 0x133d7a042, 0x026f6a60a,
- 0x116b0f50c, 0x1dd3e10e8, 0x05fabe670, 0x1a2adb74e,
- 0x130004488, 0x0de87806c, 0x000bcf5f6, 0x19d34af3a,
- 0x18f0c7078, 0x014338754, 0x017f27698, 0x049c3cc9c,
- 0x058ca5f00, 0x15e3e77ee, 0x1af900c24, 0x068bce87a,
- 0x0b5cfca28, 0x0dd07448e, 0x0ded288f8, 0x1524fa6c6,
- 0x059f229bc, 0x1d8048348, 0x06d390dec, 0x16cba8aca,
- 0x037170390, 0x0a3e3e02c, 0x06353c1cc, 0x042d98888,
- 0x0c4584f5c, 0x0d73c7bea, 0x1f16a3418, 0x1329d9f7e,
- 0x0531377e2, 0x185137662, 0x1d8d9ca7c, 0x1b1c69528,
- 0x0b25b29f2, 0x18a08b5bc, 0x19fb2a8b0, 0x02178513a,
- 0x1a08fe6ac, 0x1da758ae0, 0x045cddf4e, 0x0e0ac139e,
- 0x1a91647f2, 0x169cf9eb0, 0x1a0f717c4, 0x0170076fa,
-};
-
-// Compute the crc32c value for buffer smaller than 8
-static inline void align_to_8(
- size_t len,
- uint64_t& crc0, // crc so far, updated on return
- const unsigned char*& next) { // next data pointer, updated on return
- uint32_t crc32bit = static_cast<uint32_t>(crc0);
- if (len & 0x04) {
- crc32bit = _mm_crc32_u32(crc32bit, *(uint32_t*)next);
- next += sizeof(uint32_t);
- }
- if (len & 0x02) {
- crc32bit = _mm_crc32_u16(crc32bit, *(uint16_t*)next);
- next += sizeof(uint16_t);
- }
- if (len & 0x01) {
- crc32bit = _mm_crc32_u8(crc32bit, *(next));
- next++;
- }
- crc0 = crc32bit;
-}
-
-//
-// CombineCRC performs pclmulqdq multiplication of 2 partial CRC's and a well
-// chosen constant and xor's these with the remaining CRC.
-//
-static inline uint64_t CombineCRC(
- size_t block_size,
- uint64_t crc0,
- uint64_t crc1,
- uint64_t crc2,
- const uint64_t* next2) {
- const auto multiplier =
- *(reinterpret_cast<const __m128i*>(clmul_constants) + block_size - 1);
- const auto crc0_xmm = _mm_set_epi64x(0, crc0);
- const auto res0 = _mm_clmulepi64_si128(crc0_xmm, multiplier, 0x00);
- const auto crc1_xmm = _mm_set_epi64x(0, crc1);
- const auto res1 = _mm_clmulepi64_si128(crc1_xmm, multiplier, 0x10);
- const auto res = _mm_xor_si128(res0, res1);
- crc0 = _mm_cvtsi128_si64(res);
- crc0 = crc0 ^ *((uint64_t*)next2 - 1);
- crc2 = _mm_crc32_u64(crc2, crc0);
- return crc2;
+ return crc32c_slow;
}
-// Compute CRC-32C using the Intel hardware instruction.
-static inline uint32_t crc32c_3way(uint32_t crc, const char* buf, size_t len) {
- const unsigned char* next = (const unsigned char*)buf;
- uint64_t count;
- uint64_t crc0, crc1, crc2;
- crc0 = crc ^ 0xffffffffu;
-
-
- if (len >= 8) {
- // if len > 216 then align and use triplets
- if (len > 216) {
- {
- // Work on the bytes (< 8) before the first 8-byte alignment addr starts
- auto align_bytes = (8 - (uintptr_t)next) & 7;
- len -= align_bytes;
- align_to_8(align_bytes, crc0, next);
- }
-
- // Now work on the remaining blocks
- count = len / 24; // number of triplets
- len %= 24; // bytes remaining
- uint64_t n = count >> 7; // #blocks = first block + full blocks
- uint64_t block_size = count & 127;
- if (block_size == 0) {
- block_size = 128;
- } else {
- n++;
- }
- // points to the first byte of the next block
- const uint64_t* next0 = (uint64_t*)next + block_size;
- const uint64_t* next1 = next0 + block_size;
- const uint64_t* next2 = next1 + block_size;
+static const Function ChosenExtend= Choose_Extend();
- crc1 = crc2 = 0;
- // Use Duff's device, a for() loop inside a switch()
- // statement. This needs to execute at least once, round len
- // down to nearest triplet multiple
- switch (block_size) {
- case 128:
- do {
- // jumps here for a full block of len 128
- CRCtriplet(crc, next, -128);
- /* fallthrough */
- case 127:
- // jumps here or below for the first block smaller
- CRCtriplet(crc, next, -127);
- /* fallthrough */
- case 126:
- CRCtriplet(crc, next, -126); // than 128
- /* fallthrough */
- case 125:
- CRCtriplet(crc, next, -125);
- /* fallthrough */
- case 124:
- CRCtriplet(crc, next, -124);
- /* fallthrough */
- case 123:
- CRCtriplet(crc, next, -123);
- /* fallthrough */
- case 122:
- CRCtriplet(crc, next, -122);
- /* fallthrough */
- case 121:
- CRCtriplet(crc, next, -121);
- /* fallthrough */
- case 120:
- CRCtriplet(crc, next, -120);
- /* fallthrough */
- case 119:
- CRCtriplet(crc, next, -119);
- /* fallthrough */
- case 118:
- CRCtriplet(crc, next, -118);
- /* fallthrough */
- case 117:
- CRCtriplet(crc, next, -117);
- /* fallthrough */
- case 116:
- CRCtriplet(crc, next, -116);
- /* fallthrough */
- case 115:
- CRCtriplet(crc, next, -115);
- /* fallthrough */
- case 114:
- CRCtriplet(crc, next, -114);
- /* fallthrough */
- case 113:
- CRCtriplet(crc, next, -113);
- /* fallthrough */
- case 112:
- CRCtriplet(crc, next, -112);
- /* fallthrough */
- case 111:
- CRCtriplet(crc, next, -111);
- /* fallthrough */
- case 110:
- CRCtriplet(crc, next, -110);
- /* fallthrough */
- case 109:
- CRCtriplet(crc, next, -109);
- /* fallthrough */
- case 108:
- CRCtriplet(crc, next, -108);
- /* fallthrough */
- case 107:
- CRCtriplet(crc, next, -107);
- /* fallthrough */
- case 106:
- CRCtriplet(crc, next, -106);
- /* fallthrough */
- case 105:
- CRCtriplet(crc, next, -105);
- /* fallthrough */
- case 104:
- CRCtriplet(crc, next, -104);
- /* fallthrough */
- case 103:
- CRCtriplet(crc, next, -103);
- /* fallthrough */
- case 102:
- CRCtriplet(crc, next, -102);
- /* fallthrough */
- case 101:
- CRCtriplet(crc, next, -101);
- /* fallthrough */
- case 100:
- CRCtriplet(crc, next, -100);
- /* fallthrough */
- case 99:
- CRCtriplet(crc, next, -99);
- /* fallthrough */
- case 98:
- CRCtriplet(crc, next, -98);
- /* fallthrough */
- case 97:
- CRCtriplet(crc, next, -97);
- /* fallthrough */
- case 96:
- CRCtriplet(crc, next, -96);
- /* fallthrough */
- case 95:
- CRCtriplet(crc, next, -95);
- /* fallthrough */
- case 94:
- CRCtriplet(crc, next, -94);
- /* fallthrough */
- case 93:
- CRCtriplet(crc, next, -93);
- /* fallthrough */
- case 92:
- CRCtriplet(crc, next, -92);
- /* fallthrough */
- case 91:
- CRCtriplet(crc, next, -91);
- /* fallthrough */
- case 90:
- CRCtriplet(crc, next, -90);
- /* fallthrough */
- case 89:
- CRCtriplet(crc, next, -89);
- /* fallthrough */
- case 88:
- CRCtriplet(crc, next, -88);
- /* fallthrough */
- case 87:
- CRCtriplet(crc, next, -87);
- /* fallthrough */
- case 86:
- CRCtriplet(crc, next, -86);
- /* fallthrough */
- case 85:
- CRCtriplet(crc, next, -85);
- /* fallthrough */
- case 84:
- CRCtriplet(crc, next, -84);
- /* fallthrough */
- case 83:
- CRCtriplet(crc, next, -83);
- /* fallthrough */
- case 82:
- CRCtriplet(crc, next, -82);
- /* fallthrough */
- case 81:
- CRCtriplet(crc, next, -81);
- /* fallthrough */
- case 80:
- CRCtriplet(crc, next, -80);
- /* fallthrough */
- case 79:
- CRCtriplet(crc, next, -79);
- /* fallthrough */
- case 78:
- CRCtriplet(crc, next, -78);
- /* fallthrough */
- case 77:
- CRCtriplet(crc, next, -77);
- /* fallthrough */
- case 76:
- CRCtriplet(crc, next, -76);
- /* fallthrough */
- case 75:
- CRCtriplet(crc, next, -75);
- /* fallthrough */
- case 74:
- CRCtriplet(crc, next, -74);
- /* fallthrough */
- case 73:
- CRCtriplet(crc, next, -73);
- /* fallthrough */
- case 72:
- CRCtriplet(crc, next, -72);
- /* fallthrough */
- case 71:
- CRCtriplet(crc, next, -71);
- /* fallthrough */
- case 70:
- CRCtriplet(crc, next, -70);
- /* fallthrough */
- case 69:
- CRCtriplet(crc, next, -69);
- /* fallthrough */
- case 68:
- CRCtriplet(crc, next, -68);
- /* fallthrough */
- case 67:
- CRCtriplet(crc, next, -67);
- /* fallthrough */
- case 66:
- CRCtriplet(crc, next, -66);
- /* fallthrough */
- case 65:
- CRCtriplet(crc, next, -65);
- /* fallthrough */
- case 64:
- CRCtriplet(crc, next, -64);
- /* fallthrough */
- case 63:
- CRCtriplet(crc, next, -63);
- /* fallthrough */
- case 62:
- CRCtriplet(crc, next, -62);
- /* fallthrough */
- case 61:
- CRCtriplet(crc, next, -61);
- /* fallthrough */
- case 60:
- CRCtriplet(crc, next, -60);
- /* fallthrough */
- case 59:
- CRCtriplet(crc, next, -59);
- /* fallthrough */
- case 58:
- CRCtriplet(crc, next, -58);
- /* fallthrough */
- case 57:
- CRCtriplet(crc, next, -57);
- /* fallthrough */
- case 56:
- CRCtriplet(crc, next, -56);
- /* fallthrough */
- case 55:
- CRCtriplet(crc, next, -55);
- /* fallthrough */
- case 54:
- CRCtriplet(crc, next, -54);
- /* fallthrough */
- case 53:
- CRCtriplet(crc, next, -53);
- /* fallthrough */
- case 52:
- CRCtriplet(crc, next, -52);
- /* fallthrough */
- case 51:
- CRCtriplet(crc, next, -51);
- /* fallthrough */
- case 50:
- CRCtriplet(crc, next, -50);
- /* fallthrough */
- case 49:
- CRCtriplet(crc, next, -49);
- /* fallthrough */
- case 48:
- CRCtriplet(crc, next, -48);
- /* fallthrough */
- case 47:
- CRCtriplet(crc, next, -47);
- /* fallthrough */
- case 46:
- CRCtriplet(crc, next, -46);
- /* fallthrough */
- case 45:
- CRCtriplet(crc, next, -45);
- /* fallthrough */
- case 44:
- CRCtriplet(crc, next, -44);
- /* fallthrough */
- case 43:
- CRCtriplet(crc, next, -43);
- /* fallthrough */
- case 42:
- CRCtriplet(crc, next, -42);
- /* fallthrough */
- case 41:
- CRCtriplet(crc, next, -41);
- /* fallthrough */
- case 40:
- CRCtriplet(crc, next, -40);
- /* fallthrough */
- case 39:
- CRCtriplet(crc, next, -39);
- /* fallthrough */
- case 38:
- CRCtriplet(crc, next, -38);
- /* fallthrough */
- case 37:
- CRCtriplet(crc, next, -37);
- /* fallthrough */
- case 36:
- CRCtriplet(crc, next, -36);
- /* fallthrough */
- case 35:
- CRCtriplet(crc, next, -35);
- /* fallthrough */
- case 34:
- CRCtriplet(crc, next, -34);
- /* fallthrough */
- case 33:
- CRCtriplet(crc, next, -33);
- /* fallthrough */
- case 32:
- CRCtriplet(crc, next, -32);
- /* fallthrough */
- case 31:
- CRCtriplet(crc, next, -31);
- /* fallthrough */
- case 30:
- CRCtriplet(crc, next, -30);
- /* fallthrough */
- case 29:
- CRCtriplet(crc, next, -29);
- /* fallthrough */
- case 28:
- CRCtriplet(crc, next, -28);
- /* fallthrough */
- case 27:
- CRCtriplet(crc, next, -27);
- /* fallthrough */
- case 26:
- CRCtriplet(crc, next, -26);
- /* fallthrough */
- case 25:
- CRCtriplet(crc, next, -25);
- /* fallthrough */
- case 24:
- CRCtriplet(crc, next, -24);
- /* fallthrough */
- case 23:
- CRCtriplet(crc, next, -23);
- /* fallthrough */
- case 22:
- CRCtriplet(crc, next, -22);
- /* fallthrough */
- case 21:
- CRCtriplet(crc, next, -21);
- /* fallthrough */
- case 20:
- CRCtriplet(crc, next, -20);
- /* fallthrough */
- case 19:
- CRCtriplet(crc, next, -19);
- /* fallthrough */
- case 18:
- CRCtriplet(crc, next, -18);
- /* fallthrough */
- case 17:
- CRCtriplet(crc, next, -17);
- /* fallthrough */
- case 16:
- CRCtriplet(crc, next, -16);
- /* fallthrough */
- case 15:
- CRCtriplet(crc, next, -15);
- /* fallthrough */
- case 14:
- CRCtriplet(crc, next, -14);
- /* fallthrough */
- case 13:
- CRCtriplet(crc, next, -13);
- /* fallthrough */
- case 12:
- CRCtriplet(crc, next, -12);
- /* fallthrough */
- case 11:
- CRCtriplet(crc, next, -11);
- /* fallthrough */
- case 10:
- CRCtriplet(crc, next, -10);
- /* fallthrough */
- case 9:
- CRCtriplet(crc, next, -9);
- /* fallthrough */
- case 8:
- CRCtriplet(crc, next, -8);
- /* fallthrough */
- case 7:
- CRCtriplet(crc, next, -7);
- /* fallthrough */
- case 6:
- CRCtriplet(crc, next, -6);
- /* fallthrough */
- case 5:
- CRCtriplet(crc, next, -5);
- /* fallthrough */
- case 4:
- CRCtriplet(crc, next, -4);
- /* fallthrough */
- case 3:
- CRCtriplet(crc, next, -3);
- /* fallthrough */
- case 2:
- CRCtriplet(crc, next, -2);
- /* fallthrough */
- case 1:
- CRCduplet(crc, next, -1); // the final triplet is actually only 2
- //{ CombineCRC(); }
- crc0 = CombineCRC(block_size, crc0, crc1, crc2, next2);
- if (--n > 0) {
- crc1 = crc2 = 0;
- block_size = 128;
- // points to the first byte of the next block
- next0 = next2 + 128;
- next1 = next0 + 128; // from here on all blocks are 128 long
- next2 = next1 + 128;
- }
- /* fallthrough */
- case 0:;
- } while (n > 0);
- }
- next = (const unsigned char*)next2;
- }
- uint64_t count2 = len >> 3; // 216 of less bytes is 27 or less singlets
- len = len & 7;
- next += (count2 * 8);
- switch (count2) {
- case 27:
- CRCsinglet(crc0, next, -27 * 8);
- /* fallthrough */
- case 26:
- CRCsinglet(crc0, next, -26 * 8);
- /* fallthrough */
- case 25:
- CRCsinglet(crc0, next, -25 * 8);
- /* fallthrough */
- case 24:
- CRCsinglet(crc0, next, -24 * 8);
- /* fallthrough */
- case 23:
- CRCsinglet(crc0, next, -23 * 8);
- /* fallthrough */
- case 22:
- CRCsinglet(crc0, next, -22 * 8);
- /* fallthrough */
- case 21:
- CRCsinglet(crc0, next, -21 * 8);
- /* fallthrough */
- case 20:
- CRCsinglet(crc0, next, -20 * 8);
- /* fallthrough */
- case 19:
- CRCsinglet(crc0, next, -19 * 8);
- /* fallthrough */
- case 18:
- CRCsinglet(crc0, next, -18 * 8);
- /* fallthrough */
- case 17:
- CRCsinglet(crc0, next, -17 * 8);
- /* fallthrough */
- case 16:
- CRCsinglet(crc0, next, -16 * 8);
- /* fallthrough */
- case 15:
- CRCsinglet(crc0, next, -15 * 8);
- /* fallthrough */
- case 14:
- CRCsinglet(crc0, next, -14 * 8);
- /* fallthrough */
- case 13:
- CRCsinglet(crc0, next, -13 * 8);
- /* fallthrough */
- case 12:
- CRCsinglet(crc0, next, -12 * 8);
- /* fallthrough */
- case 11:
- CRCsinglet(crc0, next, -11 * 8);
- /* fallthrough */
- case 10:
- CRCsinglet(crc0, next, -10 * 8);
- /* fallthrough */
- case 9:
- CRCsinglet(crc0, next, -9 * 8);
- /* fallthrough */
- case 8:
- CRCsinglet(crc0, next, -8 * 8);
- /* fallthrough */
- case 7:
- CRCsinglet(crc0, next, -7 * 8);
- /* fallthrough */
- case 6:
- CRCsinglet(crc0, next, -6 * 8);
- /* fallthrough */
- case 5:
- CRCsinglet(crc0, next, -5 * 8);
- /* fallthrough */
- case 4:
- CRCsinglet(crc0, next, -4 * 8);
- /* fallthrough */
- case 3:
- CRCsinglet(crc0, next, -3 * 8);
- /* fallthrough */
- case 2:
- CRCsinglet(crc0, next, -2 * 8);
- /* fallthrough */
- case 1:
- CRCsinglet(crc0, next, -1 * 8);
- /* fallthrough */
- case 0:;
- }
- }
- {
- align_to_8(len, crc0, next);
- return (uint32_t)crc0 ^ 0xffffffffu;
- }
+static inline uint32_t Extend(uint32_t crc, const char* buf, size_t size)
+{
+ return ChosenExtend(crc, buf, size);
}
-#else
-#define NO_THREEWAY_CRC32C
-#endif //HAVE_SSE42 && HAVE_PCLMUL
-
-static inline Function Choose_Extend() {
-#ifdef HAVE_POWER8
- return isAltiVec() ? ExtendPPCImpl : ExtendImpl<Slow_CRC32>;
+extern "C" const char *my_crc32c_implementation()
+{
+#if defined(HAVE_POWER8) && defined(HAS_ALTIVEC)
+ if (ChosenExtend == ExtendPPCImpl)
+ return "Using POWER8 crc32 instructions";
#elif defined(HAVE_ARMV8_CRC)
- if(crc32c_aarch64_available()) {
- return ExtendARMImpl;
- } else {
- return ExtendImpl<Slow_CRC32>;
- }
-#else
- if (isSSE42()) {
- if (isPCLMULQDQ()) {
-#if defined HAVE_SSE42 && defined HAVE_PCLMUL && !defined NO_THREEWAY_CRC32C
- return crc32c_3way;
-#else
- return ExtendImpl<Fast_CRC32>; // Fast_CRC32 will check HAVE_SSE42 itself
-#endif
- }
- else { // no runtime PCLMULQDQ support but has SSE42 support
- return ExtendImpl<Fast_CRC32>;
- }
- } // end of isSSE42()
- else {
- return ExtendImpl<Slow_CRC32>;
- }
+ if (const char *ret= crc32c_aarch64_available())
+ return ret;
+#elif HAVE_SSE42
+# if defined HAVE_PCLMUL && SIZEOF_SIZE_T == 8
+ if (ChosenExtend == crc32c_3way)
+ return "Using crc32 + pclmulqdq instructions";
+# endif
+ if (ChosenExtend == crc32c_sse42)
+ return "Using SSE4.2 crc32 instructions";
#endif
-}
-
-static const Function ChosenExtend = Choose_Extend();
-
-static inline uint32_t Extend(uint32_t crc, const char* buf, size_t size) {
- return ChosenExtend(crc, buf, size);
+ return "Using generic crc32 instructions";
}
} // namespace crc32c
} // namespace mysys_namespace
-extern "C" unsigned int my_crc32c(unsigned int crc, const char *buf, size_t size)
+extern "C" unsigned my_crc32c(unsigned int crc, const char *buf, size_t size)
{
return mysys_namespace::crc32c::Extend(crc,buf, size);
}
diff --git a/mysys/crc32/crc32c_amd64.cc b/mysys/crc32/crc32c_amd64.cc
new file mode 100644
index 00000000000..22c492b457f
--- /dev/null
+++ b/mysys/crc32/crc32c_amd64.cc
@@ -0,0 +1,711 @@
+/* Copyright (c) 2020, 2021, MariaDB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
+
+/*
+ * Copyright 2016 Ferry Toth, Exalon Delft BV, The Netherlands
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the author be held liable for any damages
+ * arising from the use of this software.
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would be
+ * appreciated but is not required.
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ * misrepresented as being the original software.
+ * 3. This notice may not be removed or altered from any source distribution.
+ * Ferry Toth
+ * ftoth@exalondelft.nl
+ *
+ * https://github.com/htot/crc32c
+ *
+ * Modified by Facebook
+ *
+ * Original intel whitepaper:
+ * "Fast CRC Computation for iSCSI Polynomial Using CRC32 Instruction"
+ * https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/crc-iscsi-polynomial-crc32-instruction-paper.pdf
+ *
+ * This version is from the folly library, created by Dave Watson <davejwatson@fb.com>
+ *
+*/
+
+#include <stdint.h>
+#include <nmmintrin.h>
+#include <wmmintrin.h>
+
+
+#define CRCtriplet(crc, buf, offset) \
+ crc##0 = _mm_crc32_u64(crc##0, *(buf##0 + offset)); \
+ crc##1 = _mm_crc32_u64(crc##1, *(buf##1 + offset)); \
+ crc##2 = _mm_crc32_u64(crc##2, *(buf##2 + offset));
+
+#define CRCduplet(crc, buf, offset) \
+ crc##0 = _mm_crc32_u64(crc##0, *(buf##0 + offset)); \
+ crc##1 = _mm_crc32_u64(crc##1, *(buf##1 + offset));
+
+#define CRCsinglet(crc, buf, offset) \
+ crc = _mm_crc32_u64(crc, *(uint64_t*)(buf + offset));
+
+
+// Numbers taken directly from intel whitepaper.
+// clang-format off
+static const uint64_t clmul_constants alignas(16) [] = {
+ 0x14cd00bd6, 0x105ec76f0, 0x0ba4fc28e, 0x14cd00bd6,
+ 0x1d82c63da, 0x0f20c0dfe, 0x09e4addf8, 0x0ba4fc28e,
+ 0x039d3b296, 0x1384aa63a, 0x102f9b8a2, 0x1d82c63da,
+ 0x14237f5e6, 0x01c291d04, 0x00d3b6092, 0x09e4addf8,
+ 0x0c96cfdc0, 0x0740eef02, 0x18266e456, 0x039d3b296,
+ 0x0daece73e, 0x0083a6eec, 0x0ab7aff2a, 0x102f9b8a2,
+ 0x1248ea574, 0x1c1733996, 0x083348832, 0x14237f5e6,
+ 0x12c743124, 0x02ad91c30, 0x0b9e02b86, 0x00d3b6092,
+ 0x018b33a4e, 0x06992cea2, 0x1b331e26a, 0x0c96cfdc0,
+ 0x17d35ba46, 0x07e908048, 0x1bf2e8b8a, 0x18266e456,
+ 0x1a3e0968a, 0x11ed1f9d8, 0x0ce7f39f4, 0x0daece73e,
+ 0x061d82e56, 0x0f1d0f55e, 0x0d270f1a2, 0x0ab7aff2a,
+ 0x1c3f5f66c, 0x0a87ab8a8, 0x12ed0daac, 0x1248ea574,
+ 0x065863b64, 0x08462d800, 0x11eef4f8e, 0x083348832,
+ 0x1ee54f54c, 0x071d111a8, 0x0b3e32c28, 0x12c743124,
+ 0x0064f7f26, 0x0ffd852c6, 0x0dd7e3b0c, 0x0b9e02b86,
+ 0x0f285651c, 0x0dcb17aa4, 0x010746f3c, 0x018b33a4e,
+ 0x1c24afea4, 0x0f37c5aee, 0x0271d9844, 0x1b331e26a,
+ 0x08e766a0c, 0x06051d5a2, 0x093a5f730, 0x17d35ba46,
+ 0x06cb08e5c, 0x11d5ca20e, 0x06b749fb2, 0x1bf2e8b8a,
+ 0x1167f94f2, 0x021f3d99c, 0x0cec3662e, 0x1a3e0968a,
+ 0x19329634a, 0x08f158014, 0x0e6fc4e6a, 0x0ce7f39f4,
+ 0x08227bb8a, 0x1a5e82106, 0x0b0cd4768, 0x061d82e56,
+ 0x13c2b89c4, 0x188815ab2, 0x0d7a4825c, 0x0d270f1a2,
+ 0x10f5ff2ba, 0x105405f3e, 0x00167d312, 0x1c3f5f66c,
+ 0x0f6076544, 0x0e9adf796, 0x026f6a60a, 0x12ed0daac,
+ 0x1a2adb74e, 0x096638b34, 0x19d34af3a, 0x065863b64,
+ 0x049c3cc9c, 0x1e50585a0, 0x068bce87a, 0x11eef4f8e,
+ 0x1524fa6c6, 0x19f1c69dc, 0x16cba8aca, 0x1ee54f54c,
+ 0x042d98888, 0x12913343e, 0x1329d9f7e, 0x0b3e32c28,
+ 0x1b1c69528, 0x088f25a3a, 0x02178513a, 0x0064f7f26,
+ 0x0e0ac139e, 0x04e36f0b0, 0x0170076fa, 0x0dd7e3b0c,
+ 0x141a1a2e2, 0x0bd6f81f8, 0x16ad828b4, 0x0f285651c,
+ 0x041d17b64, 0x19425cbba, 0x1fae1cc66, 0x010746f3c,
+ 0x1a75b4b00, 0x18db37e8a, 0x0f872e54c, 0x1c24afea4,
+ 0x01e41e9fc, 0x04c144932, 0x086d8e4d2, 0x0271d9844,
+ 0x160f7af7a, 0x052148f02, 0x05bb8f1bc, 0x08e766a0c,
+ 0x0a90fd27a, 0x0a3c6f37a, 0x0b3af077a, 0x093a5f730,
+ 0x04984d782, 0x1d22c238e, 0x0ca6ef3ac, 0x06cb08e5c,
+ 0x0234e0b26, 0x063ded06a, 0x1d88abd4a, 0x06b749fb2,
+ 0x04597456a, 0x04d56973c, 0x0e9e28eb4, 0x1167f94f2,
+ 0x07b3ff57a, 0x19385bf2e, 0x0c9c8b782, 0x0cec3662e,
+ 0x13a9cba9e, 0x0e417f38a, 0x093e106a4, 0x19329634a,
+ 0x167001a9c, 0x14e727980, 0x1ddffc5d4, 0x0e6fc4e6a,
+ 0x00df04680, 0x0d104b8fc, 0x02342001e, 0x08227bb8a,
+ 0x00a2a8d7e, 0x05b397730, 0x168763fa6, 0x0b0cd4768,
+ 0x1ed5a407a, 0x0e78eb416, 0x0d2c3ed1a, 0x13c2b89c4,
+ 0x0995a5724, 0x1641378f0, 0x19b1afbc4, 0x0d7a4825c,
+ 0x109ffedc0, 0x08d96551c, 0x0f2271e60, 0x10f5ff2ba,
+ 0x00b0bf8ca, 0x00bf80dd2, 0x123888b7a, 0x00167d312,
+ 0x1e888f7dc, 0x18dcddd1c, 0x002ee03b2, 0x0f6076544,
+ 0x183e8d8fe, 0x06a45d2b2, 0x133d7a042, 0x026f6a60a,
+ 0x116b0f50c, 0x1dd3e10e8, 0x05fabe670, 0x1a2adb74e,
+ 0x130004488, 0x0de87806c, 0x000bcf5f6, 0x19d34af3a,
+ 0x18f0c7078, 0x014338754, 0x017f27698, 0x049c3cc9c,
+ 0x058ca5f00, 0x15e3e77ee, 0x1af900c24, 0x068bce87a,
+ 0x0b5cfca28, 0x0dd07448e, 0x0ded288f8, 0x1524fa6c6,
+ 0x059f229bc, 0x1d8048348, 0x06d390dec, 0x16cba8aca,
+ 0x037170390, 0x0a3e3e02c, 0x06353c1cc, 0x042d98888,
+ 0x0c4584f5c, 0x0d73c7bea, 0x1f16a3418, 0x1329d9f7e,
+ 0x0531377e2, 0x185137662, 0x1d8d9ca7c, 0x1b1c69528,
+ 0x0b25b29f2, 0x18a08b5bc, 0x19fb2a8b0, 0x02178513a,
+ 0x1a08fe6ac, 0x1da758ae0, 0x045cddf4e, 0x0e0ac139e,
+ 0x1a91647f2, 0x169cf9eb0, 0x1a0f717c4, 0x0170076fa,
+};
+
+// Compute the crc32c value for buffer smaller than 8
+static inline void align_to_8(
+ size_t len,
+ uint64_t& crc0, // crc so far, updated on return
+ const unsigned char*& next) { // next data pointer, updated on return
+ uint32_t crc32bit = static_cast<uint32_t>(crc0);
+ if (len & 0x04) {
+ crc32bit = _mm_crc32_u32(crc32bit, *(uint32_t*)next);
+ next += sizeof(uint32_t);
+ }
+ if (len & 0x02) {
+ crc32bit = _mm_crc32_u16(crc32bit, *(uint16_t*)next);
+ next += sizeof(uint16_t);
+ }
+ if (len & 0x01) {
+ crc32bit = _mm_crc32_u8(crc32bit, *(next));
+ next++;
+ }
+ crc0 = crc32bit;
+}
+
+//
+// CombineCRC performs pclmulqdq multiplication of 2 partial CRC's and a well
+// chosen constant and xor's these with the remaining CRC.
+//
+static inline uint64_t CombineCRC(
+ size_t block_size,
+ uint64_t crc0,
+ uint64_t crc1,
+ uint64_t crc2,
+ const uint64_t* next2) {
+ const auto multiplier =
+ *(reinterpret_cast<const __m128i*>(clmul_constants) + block_size - 1);
+ const auto crc0_xmm = _mm_set_epi64x(0, crc0);
+ const auto res0 = _mm_clmulepi64_si128(crc0_xmm, multiplier, 0x00);
+ const auto crc1_xmm = _mm_set_epi64x(0, crc1);
+ const auto res1 = _mm_clmulepi64_si128(crc1_xmm, multiplier, 0x10);
+ const auto res = _mm_xor_si128(res0, res1);
+ crc0 = _mm_cvtsi128_si64(res);
+ crc0 = crc0 ^ *((uint64_t*)next2 - 1);
+ crc2 = _mm_crc32_u64(crc2, crc0);
+ return crc2;
+}
+
+// Compute CRC-32C using the Intel hardware instruction.
+extern "C"
+uint32_t crc32c_3way(uint32_t crc, const char *buf, size_t len)
+{
+ const unsigned char* next = (const unsigned char*)buf;
+ uint64_t count;
+ uint64_t crc0, crc1, crc2;
+ crc0 = crc ^ 0xffffffffu;
+
+
+ if (len >= 8) {
+ // if len > 216 then align and use triplets
+ if (len > 216) {
+ {
+ // Work on the bytes (< 8) before the first 8-byte alignment addr starts
+ auto align_bytes = (8 - (uintptr_t)next) & 7;
+ len -= align_bytes;
+ align_to_8(align_bytes, crc0, next);
+ }
+
+ // Now work on the remaining blocks
+ count = len / 24; // number of triplets
+ len %= 24; // bytes remaining
+ uint64_t n = count >> 7; // #blocks = first block + full blocks
+ uint64_t block_size = count & 127;
+ if (block_size == 0) {
+ block_size = 128;
+ } else {
+ n++;
+ }
+ // points to the first byte of the next block
+ const uint64_t* next0 = (uint64_t*)next + block_size;
+ const uint64_t* next1 = next0 + block_size;
+ const uint64_t* next2 = next1 + block_size;
+
+ crc1 = crc2 = 0;
+ // Use Duff's device, a for() loop inside a switch()
+ // statement. This needs to execute at least once, round len
+ // down to nearest triplet multiple
+ switch (block_size) {
+ case 128:
+ do {
+ // jumps here for a full block of len 128
+ CRCtriplet(crc, next, -128);
+ /* fallthrough */
+ case 127:
+ // jumps here or below for the first block smaller
+ CRCtriplet(crc, next, -127);
+ /* fallthrough */
+ case 126:
+ CRCtriplet(crc, next, -126); // than 128
+ /* fallthrough */
+ case 125:
+ CRCtriplet(crc, next, -125);
+ /* fallthrough */
+ case 124:
+ CRCtriplet(crc, next, -124);
+ /* fallthrough */
+ case 123:
+ CRCtriplet(crc, next, -123);
+ /* fallthrough */
+ case 122:
+ CRCtriplet(crc, next, -122);
+ /* fallthrough */
+ case 121:
+ CRCtriplet(crc, next, -121);
+ /* fallthrough */
+ case 120:
+ CRCtriplet(crc, next, -120);
+ /* fallthrough */
+ case 119:
+ CRCtriplet(crc, next, -119);
+ /* fallthrough */
+ case 118:
+ CRCtriplet(crc, next, -118);
+ /* fallthrough */
+ case 117:
+ CRCtriplet(crc, next, -117);
+ /* fallthrough */
+ case 116:
+ CRCtriplet(crc, next, -116);
+ /* fallthrough */
+ case 115:
+ CRCtriplet(crc, next, -115);
+ /* fallthrough */
+ case 114:
+ CRCtriplet(crc, next, -114);
+ /* fallthrough */
+ case 113:
+ CRCtriplet(crc, next, -113);
+ /* fallthrough */
+ case 112:
+ CRCtriplet(crc, next, -112);
+ /* fallthrough */
+ case 111:
+ CRCtriplet(crc, next, -111);
+ /* fallthrough */
+ case 110:
+ CRCtriplet(crc, next, -110);
+ /* fallthrough */
+ case 109:
+ CRCtriplet(crc, next, -109);
+ /* fallthrough */
+ case 108:
+ CRCtriplet(crc, next, -108);
+ /* fallthrough */
+ case 107:
+ CRCtriplet(crc, next, -107);
+ /* fallthrough */
+ case 106:
+ CRCtriplet(crc, next, -106);
+ /* fallthrough */
+ case 105:
+ CRCtriplet(crc, next, -105);
+ /* fallthrough */
+ case 104:
+ CRCtriplet(crc, next, -104);
+ /* fallthrough */
+ case 103:
+ CRCtriplet(crc, next, -103);
+ /* fallthrough */
+ case 102:
+ CRCtriplet(crc, next, -102);
+ /* fallthrough */
+ case 101:
+ CRCtriplet(crc, next, -101);
+ /* fallthrough */
+ case 100:
+ CRCtriplet(crc, next, -100);
+ /* fallthrough */
+ case 99:
+ CRCtriplet(crc, next, -99);
+ /* fallthrough */
+ case 98:
+ CRCtriplet(crc, next, -98);
+ /* fallthrough */
+ case 97:
+ CRCtriplet(crc, next, -97);
+ /* fallthrough */
+ case 96:
+ CRCtriplet(crc, next, -96);
+ /* fallthrough */
+ case 95:
+ CRCtriplet(crc, next, -95);
+ /* fallthrough */
+ case 94:
+ CRCtriplet(crc, next, -94);
+ /* fallthrough */
+ case 93:
+ CRCtriplet(crc, next, -93);
+ /* fallthrough */
+ case 92:
+ CRCtriplet(crc, next, -92);
+ /* fallthrough */
+ case 91:
+ CRCtriplet(crc, next, -91);
+ /* fallthrough */
+ case 90:
+ CRCtriplet(crc, next, -90);
+ /* fallthrough */
+ case 89:
+ CRCtriplet(crc, next, -89);
+ /* fallthrough */
+ case 88:
+ CRCtriplet(crc, next, -88);
+ /* fallthrough */
+ case 87:
+ CRCtriplet(crc, next, -87);
+ /* fallthrough */
+ case 86:
+ CRCtriplet(crc, next, -86);
+ /* fallthrough */
+ case 85:
+ CRCtriplet(crc, next, -85);
+ /* fallthrough */
+ case 84:
+ CRCtriplet(crc, next, -84);
+ /* fallthrough */
+ case 83:
+ CRCtriplet(crc, next, -83);
+ /* fallthrough */
+ case 82:
+ CRCtriplet(crc, next, -82);
+ /* fallthrough */
+ case 81:
+ CRCtriplet(crc, next, -81);
+ /* fallthrough */
+ case 80:
+ CRCtriplet(crc, next, -80);
+ /* fallthrough */
+ case 79:
+ CRCtriplet(crc, next, -79);
+ /* fallthrough */
+ case 78:
+ CRCtriplet(crc, next, -78);
+ /* fallthrough */
+ case 77:
+ CRCtriplet(crc, next, -77);
+ /* fallthrough */
+ case 76:
+ CRCtriplet(crc, next, -76);
+ /* fallthrough */
+ case 75:
+ CRCtriplet(crc, next, -75);
+ /* fallthrough */
+ case 74:
+ CRCtriplet(crc, next, -74);
+ /* fallthrough */
+ case 73:
+ CRCtriplet(crc, next, -73);
+ /* fallthrough */
+ case 72:
+ CRCtriplet(crc, next, -72);
+ /* fallthrough */
+ case 71:
+ CRCtriplet(crc, next, -71);
+ /* fallthrough */
+ case 70:
+ CRCtriplet(crc, next, -70);
+ /* fallthrough */
+ case 69:
+ CRCtriplet(crc, next, -69);
+ /* fallthrough */
+ case 68:
+ CRCtriplet(crc, next, -68);
+ /* fallthrough */
+ case 67:
+ CRCtriplet(crc, next, -67);
+ /* fallthrough */
+ case 66:
+ CRCtriplet(crc, next, -66);
+ /* fallthrough */
+ case 65:
+ CRCtriplet(crc, next, -65);
+ /* fallthrough */
+ case 64:
+ CRCtriplet(crc, next, -64);
+ /* fallthrough */
+ case 63:
+ CRCtriplet(crc, next, -63);
+ /* fallthrough */
+ case 62:
+ CRCtriplet(crc, next, -62);
+ /* fallthrough */
+ case 61:
+ CRCtriplet(crc, next, -61);
+ /* fallthrough */
+ case 60:
+ CRCtriplet(crc, next, -60);
+ /* fallthrough */
+ case 59:
+ CRCtriplet(crc, next, -59);
+ /* fallthrough */
+ case 58:
+ CRCtriplet(crc, next, -58);
+ /* fallthrough */
+ case 57:
+ CRCtriplet(crc, next, -57);
+ /* fallthrough */
+ case 56:
+ CRCtriplet(crc, next, -56);
+ /* fallthrough */
+ case 55:
+ CRCtriplet(crc, next, -55);
+ /* fallthrough */
+ case 54:
+ CRCtriplet(crc, next, -54);
+ /* fallthrough */
+ case 53:
+ CRCtriplet(crc, next, -53);
+ /* fallthrough */
+ case 52:
+ CRCtriplet(crc, next, -52);
+ /* fallthrough */
+ case 51:
+ CRCtriplet(crc, next, -51);
+ /* fallthrough */
+ case 50:
+ CRCtriplet(crc, next, -50);
+ /* fallthrough */
+ case 49:
+ CRCtriplet(crc, next, -49);
+ /* fallthrough */
+ case 48:
+ CRCtriplet(crc, next, -48);
+ /* fallthrough */
+ case 47:
+ CRCtriplet(crc, next, -47);
+ /* fallthrough */
+ case 46:
+ CRCtriplet(crc, next, -46);
+ /* fallthrough */
+ case 45:
+ CRCtriplet(crc, next, -45);
+ /* fallthrough */
+ case 44:
+ CRCtriplet(crc, next, -44);
+ /* fallthrough */
+ case 43:
+ CRCtriplet(crc, next, -43);
+ /* fallthrough */
+ case 42:
+ CRCtriplet(crc, next, -42);
+ /* fallthrough */
+ case 41:
+ CRCtriplet(crc, next, -41);
+ /* fallthrough */
+ case 40:
+ CRCtriplet(crc, next, -40);
+ /* fallthrough */
+ case 39:
+ CRCtriplet(crc, next, -39);
+ /* fallthrough */
+ case 38:
+ CRCtriplet(crc, next, -38);
+ /* fallthrough */
+ case 37:
+ CRCtriplet(crc, next, -37);
+ /* fallthrough */
+ case 36:
+ CRCtriplet(crc, next, -36);
+ /* fallthrough */
+ case 35:
+ CRCtriplet(crc, next, -35);
+ /* fallthrough */
+ case 34:
+ CRCtriplet(crc, next, -34);
+ /* fallthrough */
+ case 33:
+ CRCtriplet(crc, next, -33);
+ /* fallthrough */
+ case 32:
+ CRCtriplet(crc, next, -32);
+ /* fallthrough */
+ case 31:
+ CRCtriplet(crc, next, -31);
+ /* fallthrough */
+ case 30:
+ CRCtriplet(crc, next, -30);
+ /* fallthrough */
+ case 29:
+ CRCtriplet(crc, next, -29);
+ /* fallthrough */
+ case 28:
+ CRCtriplet(crc, next, -28);
+ /* fallthrough */
+ case 27:
+ CRCtriplet(crc, next, -27);
+ /* fallthrough */
+ case 26:
+ CRCtriplet(crc, next, -26);
+ /* fallthrough */
+ case 25:
+ CRCtriplet(crc, next, -25);
+ /* fallthrough */
+ case 24:
+ CRCtriplet(crc, next, -24);
+ /* fallthrough */
+ case 23:
+ CRCtriplet(crc, next, -23);
+ /* fallthrough */
+ case 22:
+ CRCtriplet(crc, next, -22);
+ /* fallthrough */
+ case 21:
+ CRCtriplet(crc, next, -21);
+ /* fallthrough */
+ case 20:
+ CRCtriplet(crc, next, -20);
+ /* fallthrough */
+ case 19:
+ CRCtriplet(crc, next, -19);
+ /* fallthrough */
+ case 18:
+ CRCtriplet(crc, next, -18);
+ /* fallthrough */
+ case 17:
+ CRCtriplet(crc, next, -17);
+ /* fallthrough */
+ case 16:
+ CRCtriplet(crc, next, -16);
+ /* fallthrough */
+ case 15:
+ CRCtriplet(crc, next, -15);
+ /* fallthrough */
+ case 14:
+ CRCtriplet(crc, next, -14);
+ /* fallthrough */
+ case 13:
+ CRCtriplet(crc, next, -13);
+ /* fallthrough */
+ case 12:
+ CRCtriplet(crc, next, -12);
+ /* fallthrough */
+ case 11:
+ CRCtriplet(crc, next, -11);
+ /* fallthrough */
+ case 10:
+ CRCtriplet(crc, next, -10);
+ /* fallthrough */
+ case 9:
+ CRCtriplet(crc, next, -9);
+ /* fallthrough */
+ case 8:
+ CRCtriplet(crc, next, -8);
+ /* fallthrough */
+ case 7:
+ CRCtriplet(crc, next, -7);
+ /* fallthrough */
+ case 6:
+ CRCtriplet(crc, next, -6);
+ /* fallthrough */
+ case 5:
+ CRCtriplet(crc, next, -5);
+ /* fallthrough */
+ case 4:
+ CRCtriplet(crc, next, -4);
+ /* fallthrough */
+ case 3:
+ CRCtriplet(crc, next, -3);
+ /* fallthrough */
+ case 2:
+ CRCtriplet(crc, next, -2);
+ /* fallthrough */
+ case 1:
+ CRCduplet(crc, next, -1); // the final triplet is actually only 2
+ //{ CombineCRC(); }
+ crc0 = CombineCRC(block_size, crc0, crc1, crc2, next2);
+ if (--n > 0) {
+ crc1 = crc2 = 0;
+ block_size = 128;
+ // points to the first byte of the next block
+ next0 = next2 + 128;
+ next1 = next0 + 128; // from here on all blocks are 128 long
+ next2 = next1 + 128;
+ }
+ /* fallthrough */
+ case 0:;
+ } while (n > 0);
+ }
+ next = (const unsigned char*)next2;
+ }
+ uint64_t count2 = len >> 3; // 216 of less bytes is 27 or less singlets
+ len = len & 7;
+ next += (count2 * 8);
+ switch (count2) {
+ case 27:
+ CRCsinglet(crc0, next, -27 * 8);
+ /* fallthrough */
+ case 26:
+ CRCsinglet(crc0, next, -26 * 8);
+ /* fallthrough */
+ case 25:
+ CRCsinglet(crc0, next, -25 * 8);
+ /* fallthrough */
+ case 24:
+ CRCsinglet(crc0, next, -24 * 8);
+ /* fallthrough */
+ case 23:
+ CRCsinglet(crc0, next, -23 * 8);
+ /* fallthrough */
+ case 22:
+ CRCsinglet(crc0, next, -22 * 8);
+ /* fallthrough */
+ case 21:
+ CRCsinglet(crc0, next, -21 * 8);
+ /* fallthrough */
+ case 20:
+ CRCsinglet(crc0, next, -20 * 8);
+ /* fallthrough */
+ case 19:
+ CRCsinglet(crc0, next, -19 * 8);
+ /* fallthrough */
+ case 18:
+ CRCsinglet(crc0, next, -18 * 8);
+ /* fallthrough */
+ case 17:
+ CRCsinglet(crc0, next, -17 * 8);
+ /* fallthrough */
+ case 16:
+ CRCsinglet(crc0, next, -16 * 8);
+ /* fallthrough */
+ case 15:
+ CRCsinglet(crc0, next, -15 * 8);
+ /* fallthrough */
+ case 14:
+ CRCsinglet(crc0, next, -14 * 8);
+ /* fallthrough */
+ case 13:
+ CRCsinglet(crc0, next, -13 * 8);
+ /* fallthrough */
+ case 12:
+ CRCsinglet(crc0, next, -12 * 8);
+ /* fallthrough */
+ case 11:
+ CRCsinglet(crc0, next, -11 * 8);
+ /* fallthrough */
+ case 10:
+ CRCsinglet(crc0, next, -10 * 8);
+ /* fallthrough */
+ case 9:
+ CRCsinglet(crc0, next, -9 * 8);
+ /* fallthrough */
+ case 8:
+ CRCsinglet(crc0, next, -8 * 8);
+ /* fallthrough */
+ case 7:
+ CRCsinglet(crc0, next, -7 * 8);
+ /* fallthrough */
+ case 6:
+ CRCsinglet(crc0, next, -6 * 8);
+ /* fallthrough */
+ case 5:
+ CRCsinglet(crc0, next, -5 * 8);
+ /* fallthrough */
+ case 4:
+ CRCsinglet(crc0, next, -4 * 8);
+ /* fallthrough */
+ case 3:
+ CRCsinglet(crc0, next, -3 * 8);
+ /* fallthrough */
+ case 2:
+ CRCsinglet(crc0, next, -2 * 8);
+ /* fallthrough */
+ case 1:
+ CRCsinglet(crc0, next, -1 * 8);
+ /* fallthrough */
+ case 0:;
+ }
+ }
+ {
+ align_to_8(len, crc0, next);
+ return (uint32_t)crc0 ^ 0xffffffffu;
+ }
+}
diff --git a/mysys/crc32ieee.cc b/mysys/crc32ieee.cc
index 5f8344b4f9d..bbafa1230f8 100644
--- a/mysys/crc32ieee.cc
+++ b/mysys/crc32ieee.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2020, 2021, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -39,25 +39,23 @@ typedef unsigned int (*my_crc32_t)(unsigned int, const void *, size_t);
static my_crc32_t init_crc32()
{
- my_crc32_t func= my_crc32_zlib;
#ifdef HAVE_PCLMUL
if (crc32_pclmul_enabled())
- func = crc32_pclmul;
+ return crc32_pclmul;
#elif defined(__GNUC__) && defined(HAVE_ARMV8_CRC)
if (crc32_aarch64_available())
- func= crc32_aarch64;
+ return crc32_aarch64;
#endif
- return func;
+ return my_crc32_zlib;
}
static const my_crc32_t my_checksum_func= init_crc32();
-#ifndef __powerpc64__
-/* For powerpc, my_checksum is defined elsewhere.*/
-extern "C" unsigned int my_checksum(unsigned int crc, const void *data, size_t len)
+#ifdef __powerpc64__
+# error "my_checksum() is defined in mysys/crc32/crc32_ppc64.c"
+#endif
+extern "C"
+unsigned int my_checksum(unsigned int crc, const void *data, size_t len)
{
return my_checksum_func(crc, data, len);
}
-#endif
-
-
diff --git a/plugin/userstat/index_stats.cc b/plugin/userstat/index_stats.cc
index 3ad5ef2e1ad..97305e894bb 100644
--- a/plugin/userstat/index_stats.cc
+++ b/plugin/userstat/index_stats.cc
@@ -32,7 +32,7 @@ static int index_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond)
tmp_table.grant.privilege= NO_ACL;
if (check_access(thd, SELECT_ACL, tmp_table.db.str,
&tmp_table.grant.privilege, NULL, 0, 1) ||
- check_grant(thd, SELECT_ACL, &tmp_table, 1, UINT_MAX, 1))
+ check_grant(thd, SELECT_ACL, &tmp_table, 1, 1, 1))
continue;
index_name= tmp_table.table_name.str + tmp_table.table_name.length + 1;
diff --git a/scripts/mysql_setpermission.sh b/scripts/mysql_setpermission.sh
index 66decbd69af..29311b9c101 100644
--- a/scripts/mysql_setpermission.sh
+++ b/scripts/mysql_setpermission.sh
@@ -56,7 +56,7 @@ my $sqlhost = "";
my $user = "";
$dbh=$host=$opt_user= $opt_password= $opt_help= $opt_host= $opt_socket= "";
-$opt_port=0;
+$opt_port=3306;
read_my_cnf(); # Read options from ~/.my.cnf
@@ -64,6 +64,13 @@ GetOptions("user=s","password=s","help","host=s","socket=s","port=i");
usage() if ($opt_help); # the help function
+## User may have put the port with the host.
+
+if ($opt_host =~ s/:(\d+)$//)
+{
+ $opt_port = $1;
+}
+
if ($opt_host eq '')
{
$sqlhost = "localhost";
@@ -84,10 +91,30 @@ if ($opt_password eq '')
print "\n";
}
+## Socket takes precedence.
+my $dsn;
+my $prefix= 'mysql';
+
+if (eval {DBI->install_driver("MariaDB")}) {
+ $dsn ="DBI:MariaDB:;";
+ $prefix= 'mariadb';
+}
+else {
+ $dsn = "DBI:mysql:;";
+}
+
+if ($opt_socket and -S $opt_socket)
+{
+ $dsn .= "${prefix}_socket=$opt_socket";
+}
+else
+{
+ $dsn .= "host=$sqlhost;port=$opt_port";
+}
# make the connection to MariaDB
-$dbh= DBI->connect("DBI:MariaDB:mysql:host=$sqlhost:port=$opt_port:mariadb_socket=$opt_socket",$opt_user,$opt_password, {PrintError => 0}) ||
- die("Can't make a connection to the mysql server.\n The error: $DBI::errstr");
+$dbh= DBI->connect($dsn,$opt_user,$opt_password, { RaiseError => 1, PrintError => 0}) ||
+ die("Can't make a connection to the MariaDB server.\n The error: $DBI::errstr");
# the start of the program
&q1();
@@ -195,7 +222,8 @@ sub setpwd
{
$pass = "PASSWORD(". $dbh->quote($pass) . ")";
}
- my $sth = $dbh->prepare("update user set Password=$pass where User = $user and Host = $host") || die $dbh->errstr;
+ my $uh= "$user@$host";
+ my $sth = $dbh->prepare("set password for $uh =$pass") || die $dbh->errstr;
$sth->execute || die $dbh->errstr;
$sth->finish;
print "The password is set for user $user.\n\n";
@@ -403,7 +431,7 @@ sub user
chomp($answer);
if ($answer)
{
- my $sth = $dbh->prepare("select User from user where User = '$answer'") || die $dbh->errstr;
+ my $sth = $dbh->prepare("select User from mysql.user where User = '$answer'") || die $dbh->errstr;
$sth->execute || die $dbh->errstr;
my @r = $sth->fetchrow_array;
if ($r[0])
@@ -538,7 +566,7 @@ sub hosts
print "We now need to know which host for $user we have to change.\n";
print "Choose from the following hosts: \n";
$user = $dbh->quote($user);
- my $sth = $dbh->prepare("select Host,User from user where User = $user") || die $dbh->errstr;
+ my $sth = $dbh->prepare("select Host,User from mysql.user where User = $user") || die $dbh->errstr;
$sth->execute || die $dbh->errstr;
while (my @r = $sth->fetchrow_array)
{
@@ -551,7 +579,7 @@ sub hosts
chomp($answer);
if ($answer)
{
- $sth = $dbh->prepare("select Host,User from user where Host = '$answer' and User = $user") || die $dbh->errstr;
+ $sth = $dbh->prepare("select Host,User from mysql.user where Host = '$answer' and User = $user") || die $dbh->errstr;
$sth->execute || die $dbh->errstr;
my @r = $sth->fetchrow_array;
if ($r[0])
@@ -597,8 +625,10 @@ sub read_my_cnf
{
if (/^\[(client|perl)\]/i)
{
+ print "Options read from mycnf:\n";
while ((defined($_=<TMP>)) && !/^\[\w+\]/)
{
+ next if /^\s*($|#)/; ## skip blanks and comments
print $_;
if (/^host\s*=\s*(\S+)/i)
{
@@ -621,6 +651,7 @@ sub read_my_cnf
$opt_socket = $1;
}
}
+ print "------------------------\n";
}
}
close(TMP);
diff --git a/scripts/wsrep_sst_mariabackup.sh b/scripts/wsrep_sst_mariabackup.sh
index bbd1bafbd41..2359cbc0ced 100644
--- a/scripts/wsrep_sst_mariabackup.sh
+++ b/scripts/wsrep_sst_mariabackup.sh
@@ -1,6 +1,6 @@
#!/bin/bash -ue
# Copyright (C) 2013 Percona Inc
-# Copyright (C) 2017-2020 MariaDB
+# Copyright (C) 2017-2021 MariaDB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -851,7 +851,7 @@ then
-z $(parse_cnf --mysqld tmpdir "") && \
-z $(parse_cnf xtrabackup tmpdir "") ]]; then
xtmpdir=$(mktemp -d)
- tmpopts=" --tmpdir=$xtmpdir"
+ tmpopts="--tmpdir=$xtmpdir"
wsrep_log_info "Using $xtmpdir as xtrabackup temporary directory"
fi
diff --git a/sql/handler.cc b/sql/handler.cc
index b312635c8ee..985d3c9cc83 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -3546,25 +3546,27 @@ int handler::update_auto_increment()
DBUG_RETURN(0);
}
- // ALTER TABLE ... ADD COLUMN ... AUTO_INCREMENT
- if (thd->lex->sql_command == SQLCOM_ALTER_TABLE)
+ if (table->versioned())
{
- if (table->versioned())
+ Field *end= table->vers_end_field();
+ DBUG_ASSERT(end);
+ bitmap_set_bit(table->read_set, end->field_index);
+ if (!end->is_max())
{
- Field *end= table->vers_end_field();
- DBUG_ASSERT(end);
- bitmap_set_bit(table->read_set, end->field_index);
- if (!end->is_max())
+ if (thd->lex->sql_command == SQLCOM_ALTER_TABLE)
{
if (!table->next_number_field->real_maybe_null())
DBUG_RETURN(HA_ERR_UNSUPPORTED);
table->next_number_field->set_null();
- DBUG_RETURN(0);
}
+ DBUG_RETURN(0);
}
- table->next_number_field->set_notnull();
}
+ // ALTER TABLE ... ADD COLUMN ... AUTO_INCREMENT
+ if (thd->lex->sql_command == SQLCOM_ALTER_TABLE)
+ table->next_number_field->set_notnull();
+
if ((nr= next_insert_id) >= auto_inc_interval_for_cur_row.maximum())
{
/* next_insert_id is beyond what is reserved, so we reserve more. */
@@ -8023,6 +8025,11 @@ bool Vers_parse_info::fix_alter_info(THD *thd, Alter_info *alter_info,
{
if (f->flags & VERS_SYSTEM_FIELD)
{
+ if (!table->versioned())
+ {
+ my_error(ER_VERS_NOT_VERSIONED, MYF(0), table->s->table_name.str);
+ return true;
+ }
my_error(ER_VERS_DUPLICATE_ROW_START_END, MYF(0),
f->flags & VERS_SYS_START_FLAG ? "START" : "END", f->field_name.str);
return true;
diff --git a/sql/item.cc b/sql/item.cc
index 3dbe3badadf..1d13fee58ed 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -5051,13 +5051,19 @@ bool Item_ref_null_helper::get_date(THD *thd, MYSQL_TIME *ltime,
@param resolved_item item which was resolved in outer SELECT(for warning)
@param mark_item item which should be marked (can be differ in case of
substitution)
+ @param suppress_warning_output flag specifying whether to suppress output of
+ a warning message
*/
static bool mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
Item_ident *resolved_item,
- Item_ident *mark_item)
+ Item_ident *mark_item,
+ bool suppress_warning_output)
{
DBUG_ENTER("mark_as_dependent");
+ DBUG_PRINT("info", ("current select: %d (%p) last: %d (%p)",
+ current->select_number, current,
+ (last ? last->select_number : 0), last));
/* store pointer on SELECT_LEX from which item is dependent */
if (mark_item && mark_item->can_be_depended)
@@ -5068,7 +5074,7 @@ static bool mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
if (current->mark_as_dependent(thd, last,
/** resolved_item psergey-thu **/ mark_item))
DBUG_RETURN(TRUE);
- if (thd->lex->describe & DESCRIBE_EXTENDED)
+ if ((thd->lex->describe & DESCRIBE_EXTENDED) && !suppress_warning_output)
{
const char *db_name= (resolved_item->db_name.str ?
resolved_item->db_name.str : "");
@@ -5097,6 +5103,8 @@ static bool mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
@param found_item Item which was found during resolving (if resolved
identifier belongs to VIEW)
@param resolved_item Identifier which was resolved
+ @param suppress_warning_output flag specifying whether to suppress output of
+ a warning message
@note
We have to mark all items between current_sel (including) and
@@ -5109,7 +5117,8 @@ static bool mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
void mark_select_range_as_dependent(THD *thd, SELECT_LEX *last_select,
SELECT_LEX *current_sel,
Field *found_field, Item *found_item,
- Item_ident *resolved_item)
+ Item_ident *resolved_item,
+ bool suppress_warning_output)
{
/*
Go from current SELECT to SELECT where field was resolved (it
@@ -5144,7 +5153,7 @@ void mark_select_range_as_dependent(THD *thd, SELECT_LEX *last_select,
found_field->table->map;
prev_subselect_item->const_item_cache= 0;
mark_as_dependent(thd, last_select, current_sel, resolved_item,
- dependent);
+ dependent, suppress_warning_output);
}
@@ -5610,7 +5619,7 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
context->select_lex, this,
((ref_type == REF_ITEM ||
ref_type == FIELD_ITEM) ?
- (Item_ident*) (*reference) : 0));
+ (Item_ident*) (*reference) : 0), false);
return 0;
}
}
@@ -5622,7 +5631,7 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
context->select_lex, this,
((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ?
(Item_ident*) (*reference) :
- 0));
+ 0), false);
if (thd->lex->in_sum_func &&
thd->lex->in_sum_func->nest_level >= select->nest_level)
{
@@ -5736,7 +5745,7 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
set_max_sum_func_level(thd, select);
mark_as_dependent(thd, last_checked_context->select_lex,
context->select_lex, rf,
- rf);
+ rf, false);
return 0;
}
@@ -5749,7 +5758,7 @@ Item_field::fix_outer_field(THD *thd, Field **from_field, Item **reference)
set_max_sum_func_level(thd, select);
mark_as_dependent(thd, last_checked_context->select_lex,
context->select_lex,
- this, (Item_ident*)*reference);
+ this, (Item_ident*)*reference, false);
if (last_checked_context->select_lex->having_fix_field)
{
Item_ref *rf;
@@ -7723,7 +7732,7 @@ public:
if (tbl->table == item->field->table)
{
if (sel != current_select)
- mark_as_dependent(thd, sel, current_select, item, item);
+ mark_as_dependent(thd, sel, current_select, item, item, false);
return;
}
}
@@ -7919,7 +7928,7 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
((refer_type == REF_ITEM ||
refer_type == FIELD_ITEM) ?
(Item_ident*) (*reference) :
- 0));
+ 0), false);
/*
view reference found, we substituted it instead of this
Item, so can quit
@@ -7969,7 +7978,7 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
goto error;
thd->change_item_tree(reference, fld);
mark_as_dependent(thd, last_checked_context->select_lex,
- current_sel, fld, fld);
+ current_sel, fld, fld, false);
/*
A reference is resolved to a nest level that's outer or the same as
the nest level of the enclosing set function : adjust the value of
@@ -7992,7 +8001,7 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
/* Should be checked in resolve_ref_in_select_and_group(). */
DBUG_ASSERT(*ref && (*ref)->is_fixed());
mark_as_dependent(thd, last_checked_context->select_lex,
- context->select_lex, this, this);
+ context->select_lex, this, this, false);
/*
A reference is resolved to a nest level that's outer or the same as
the nest level of the enclosing set function : adjust the value of
diff --git a/sql/item.h b/sql/item.h
index a1c288ab1f0..9b7f2cc68e9 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -7394,7 +7394,8 @@ void mark_select_range_as_dependent(THD *thd,
st_select_lex *last_select,
st_select_lex *current_sel,
Field *found_field, Item *found_item,
- Item_ident *resolved_item);
+ Item_ident *resolved_item,
+ bool suppress_warning_output);
extern Cached_item *new_Cached_item(THD *thd, Item *item,
bool pass_through_ref);
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index 46412fe8ad6..aa7269ab95a 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -838,11 +838,7 @@ class Item_func_ne :public Item_bool_rowready_func2
{
protected:
SEL_TREE *get_func_mm_tree(RANGE_OPT_PARAM *param,
- Field *field, Item *value)
- {
- DBUG_ENTER("Item_func_ne::get_func_mm_tree");
- DBUG_RETURN(get_ne_mm_tree(param, field, value, value));
- }
+ Field *field, Item *value);
public:
Item_func_ne(THD *thd, Item *a, Item *b):
Item_bool_rowready_func2(thd, a, b) {}
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 1089249c048..1f1c3454a55 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -291,7 +291,8 @@ public:
friend bool Item_ref::fix_fields(THD *, Item **);
friend void mark_select_range_as_dependent(THD*,
st_select_lex*, st_select_lex*,
- Field*, Item*, Item_ident*);
+ Field*, Item*, Item_ident*,
+ bool);
friend bool convert_join_subqueries_to_semijoins(JOIN *join);
};
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 2dc9b183623..0ecba16730b 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -461,6 +461,7 @@ void print_range_for_non_indexed_field(String *out, Field *field,
static void print_min_range_operator(String *out, const ha_rkey_function flag);
static void print_max_range_operator(String *out, const ha_rkey_function flag);
+static bool is_field_an_unique_index(RANGE_OPT_PARAM *param, Field *field);
/*
SEL_IMERGE is a list of possible ways to do index merge, i.e. it is
@@ -7721,6 +7722,21 @@ SEL_TREE *Item_bool_func::get_ne_mm_tree(RANGE_OPT_PARAM *param,
}
+SEL_TREE *Item_func_ne::get_func_mm_tree(RANGE_OPT_PARAM *param,
+ Field *field, Item *value)
+{
+ DBUG_ENTER("Item_func_ne::get_func_mm_tree");
+ /*
+ If this condition is a "col1<>...", where there is a UNIQUE KEY(col1),
+ do not construct a SEL_TREE from it. A condition that excludes just one
+ row in the table is not selective (unless there are only a few rows)
+ */
+ if (is_field_an_unique_index(param, field))
+ DBUG_RETURN(NULL);
+ DBUG_RETURN(get_ne_mm_tree(param, field, value, value));
+}
+
+
SEL_TREE *Item_func_between::get_func_mm_tree(RANGE_OPT_PARAM *param,
Field *field, Item *value)
{
@@ -7819,28 +7835,16 @@ SEL_TREE *Item_func_in::get_func_mm_tree(RANGE_OPT_PARAM *param,
DBUG_RETURN(0);
/*
- If this is "unique_key NOT IN (...)", do not consider it sargable (for
- any index, not just the unique one). The logic is as follows:
+ if this is a "col1 NOT IN (...)", and there is a UNIQUE KEY(col1), do
+ not constuct a SEL_TREE from it. The rationale is as follows:
- if there are only a few constants, this condition is not selective
(unless the table is also very small in which case we won't gain
anything)
- - If there are a lot of constants, the overhead of building and
+ - if there are a lot of constants, the overhead of building and
processing enormous range list is not worth it.
*/
- if (param->using_real_indexes)
- {
- key_map::Iterator it(field->key_start);
- uint key_no;
- while ((key_no= it++) != key_map::Iterator::BITMAP_END)
- {
- KEY *key_info= &field->table->key_info[key_no];
- if (key_info->user_defined_key_parts == 1 &&
- (key_info->flags & HA_NOSAME))
- {
- DBUG_RETURN(0);
- }
- }
- }
+ if (is_field_an_unique_index(param, field))
+ DBUG_RETURN(0);
/* Get a SEL_TREE for "(-inf|NULL) < X < c_0" interval. */
uint i=0;
@@ -8540,6 +8544,38 @@ SEL_TREE *Item_equal::get_mm_tree(RANGE_OPT_PARAM *param, Item **cond_ptr)
}
+/*
+ @brief
+ Check if there is an one-segment unique key that matches the field exactly
+
+ @detail
+ In the future we could also add "almost unique" indexes where any value is
+ present only in a few rows (but necessarily exactly one row)
+*/
+static bool is_field_an_unique_index(RANGE_OPT_PARAM *param, Field *field)
+{
+ DBUG_ENTER("is_field_an_unique_index");
+
+ // The check for using_real_indexes is there because of the heuristics
+ // this function is used for.
+ if (param->using_real_indexes)
+ {
+ key_map::Iterator it(field->key_start);
+ uint key_no;
+ while ((key_no= it++) != key_map::Iterator::BITMAP_END)
+ {
+ KEY *key_info= &field->table->key_info[key_no];
+ if (key_info->user_defined_key_parts == 1 &&
+ (key_info->flags & HA_NOSAME))
+ {
+ DBUG_RETURN(true);
+ }
+ }
+ }
+ DBUG_RETURN(false);
+}
+
+
SEL_TREE *
Item_bool_func::get_mm_parts(RANGE_OPT_PARAM *param, Field *field,
Item_func::Functype type, Item *value)
diff --git a/sql/spatial.cc b/sql/spatial.cc
index 7a3286dae1c..13fff34df21 100644
--- a/sql/spatial.cc
+++ b/sql/spatial.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2002, 2013, Oracle and/or its affiliates.
- Copyright (c) 2011, 2020, MariaDB Corporation.
+ Copyright (c) 2011, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -1075,7 +1075,7 @@ double Gis_point::calculate_haversine(const Geometry *g,
int *error)
{
DBUG_ASSERT(sphere_radius > 0);
- double x1r, x2r, y1r, y2r, dlong, dlat, res;
+ double x1r, x2r, y1r, y2r;
// This check is done only for optimization purposes where we know it will
// be one and only one point in Multipoint
@@ -1092,31 +1092,39 @@ double Gis_point::calculate_haversine(const Geometry *g,
Geometry *gg= Geometry::construct(&gbuff, point_temp, point_size-1);
DBUG_ASSERT(gg);
if (static_cast<Gis_point *>(gg)->get_xy_radian(&x2r, &y2r))
+ {
DBUG_ASSERT(0);
+ return -1;
+ }
}
else
{
if (static_cast<const Gis_point *>(g)->get_xy_radian(&x2r, &y2r))
+ {
DBUG_ASSERT(0);
+ return -1;
+ }
}
if (this->get_xy_radian(&x1r, &y1r))
+ {
DBUG_ASSERT(0);
+ return -1;
+ }
// Check boundary conditions: longitude[-180,180]
if (!((x2r >= -M_PI && x2r <= M_PI) && (x1r >= -M_PI && x1r <= M_PI)))
{
*error=1;
return -1;
}
- // Check boundary conditions: lattitude[-90,90]
+ // Check boundary conditions: latitude[-90,90]
if (!((y2r >= -M_PI/2 && y2r <= M_PI/2) && (y1r >= -M_PI/2 && y1r <= M_PI/2)))
{
*error=-1;
return -1;
}
- dlat= sin((y2r - y1r)/2)*sin((y2r - y1r)/2);
- dlong= sin((x2r - x1r)/2)*sin((x2r - x1r)/2);
- res= 2*sphere_radius*asin((sqrt(dlat + cos(y1r)*cos(y2r)*dlong)));
- return res;
+ double dlat= sin((y2r - y1r)/2)*sin((y2r - y1r)/2);
+ double dlong= sin((x2r - x1r)/2)*sin((x2r - x1r)/2);
+ return 2*sphere_radius*asin((sqrt(dlat + cos(y1r)*cos(y2r)*dlong)));
}
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 35f45cfed21..9a4dea3a216 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -6433,7 +6433,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
if (!all_merged && current_sel != last_select)
{
mark_select_range_as_dependent(thd, last_select, current_sel,
- found, *ref, item);
+ found, *ref, item, true);
}
}
return found;
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index a06aa4df988..1dbeff69cb5 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -3347,7 +3347,7 @@ void st_select_lex_unit::exclude_tree()
*/
bool st_select_lex::mark_as_dependent(THD *thd, st_select_lex *last,
- Item *dependency)
+ Item_ident *dependency)
{
DBUG_ASSERT(this != last);
@@ -3355,10 +3355,14 @@ bool st_select_lex::mark_as_dependent(THD *thd, st_select_lex *last,
/*
Mark all selects from resolved to 1 before select where was
found table as depended (of select where was found table)
+
+ We move by name resolution context, bacause during merge can some select
+ be excleded from SELECT tree
*/
- SELECT_LEX *s= this;
+ Name_resolution_context *c= &this->context;
do
{
+ SELECT_LEX *s= c->select_lex;
if (!(s->uncacheable & UNCACHEABLE_DEPENDENT_GENERATED))
{
// Select is dependent of outer select
@@ -3380,7 +3384,7 @@ bool st_select_lex::mark_as_dependent(THD *thd, st_select_lex *last,
if (subquery_expr && subquery_expr->mark_as_dependent(thd, last,
dependency))
return TRUE;
- } while ((s= s->outer_select()) != last && s != 0);
+ } while ((c= c->outer_context) != NULL && (c->select_lex != last));
is_correlated= TRUE;
master_unit()->item->is_correlated= TRUE;
return FALSE;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 02f5b357c50..7e3a1152d0b 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -1383,7 +1383,8 @@ public:
}
inline bool is_subquery_function() { return master_unit()->item != 0; }
- bool mark_as_dependent(THD *thd, st_select_lex *last, Item *dependency);
+ bool mark_as_dependent(THD *thd, st_select_lex *last,
+ Item_ident *dependency);
void set_braces(bool value)
{
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 9abd12761e5..3f0e71c747f 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1670,7 +1670,9 @@ dispatch_command_return dispatch_command(enum enum_server_command command, THD *
if (unlikely(thd->security_ctx->password_expired &&
command != COM_QUERY &&
command != COM_PING &&
- command != COM_QUIT))
+ command != COM_QUIT &&
+ command != COM_STMT_PREPARE &&
+ command != COM_STMT_EXECUTE))
{
my_error(ER_MUST_CHANGE_PASSWORD, MYF(0));
goto dispatch_end;
@@ -3456,7 +3458,10 @@ mysql_execute_command(THD *thd)
first_table->for_insert_data);
if (thd->security_ctx->password_expired &&
- lex->sql_command != SQLCOM_SET_OPTION)
+ lex->sql_command != SQLCOM_SET_OPTION &&
+ lex->sql_command != SQLCOM_PREPARE &&
+ lex->sql_command != SQLCOM_EXECUTE &&
+ lex->sql_command != SQLCOM_DEALLOCATE_PREPARE)
{
my_error(ER_MUST_CHANGE_PASSWORD, MYF(0));
DBUG_RETURN(1);
@@ -3748,7 +3753,8 @@ mysql_execute_command(THD *thd)
thd->transaction->stmt.mark_trans_did_ddl();
#ifdef WITH_WSREP
/* Clean up the previous transaction on implicit commit */
- if (wsrep_thd_is_local(thd) && wsrep_after_statement(thd))
+ if (WSREP_NNULL(thd) && wsrep_thd_is_local(thd) &&
+ wsrep_after_statement(thd))
{
goto error;
}
@@ -3827,7 +3833,7 @@ mysql_execute_command(THD *thd)
Do not start transaction for stored procedures, it will be handled
internally in SP processing.
*/
- if (WSREP(thd) &&
+ if (WSREP_NNULL(thd) &&
wsrep_thd_is_local(thd) &&
lex->sql_command != SQLCOM_BEGIN &&
lex->sql_command != SQLCOM_CALL &&
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 24e0d8abf27..f825a951de0 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -4251,6 +4251,15 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len)
thd->is_error() ||
init_param_array(this));
+ if (thd->security_ctx->password_expired &&
+ lex->sql_command != SQLCOM_SET_OPTION)
+ {
+ thd->restore_backup_statement(this, &stmt_backup);
+ thd->restore_active_arena(this, &stmt_backup);
+ thd->stmt_arena= old_stmt_arena;
+ my_error(ER_MUST_CHANGE_PASSWORD, MYF(0));
+ DBUG_RETURN(true);
+ }
lex->set_trg_event_type_for_tables();
/*
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 56a7ac6eb80..dacd636985a 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -13662,18 +13662,21 @@ ha_rows JOIN_TAB::get_examined_rows()
bool JOIN_TAB::preread_init()
{
TABLE_LIST *derived= table->pos_in_table_list;
+ DBUG_ENTER("JOIN_TAB::preread_init");
+
if (!derived || !derived->is_materialized_derived())
{
preread_init_done= TRUE;
- return FALSE;
+ DBUG_RETURN(FALSE);
}
/* Materialize derived table/view. */
if ((!derived->get_unit()->executed ||
derived->is_recursive_with_table() ||
derived->get_unit()->uncacheable) &&
- mysql_handle_single_derived(join->thd->lex, derived, DT_CREATE | DT_FILL))
- return TRUE;
+ mysql_handle_single_derived(join->thd->lex,
+ derived, DT_CREATE | DT_FILL))
+ DBUG_RETURN(TRUE);
if (!(derived->get_unit()->uncacheable & UNCACHEABLE_DEPENDENT) ||
derived->is_nonrecursive_derived_with_rec_ref())
@@ -13691,9 +13694,9 @@ bool JOIN_TAB::preread_init()
/* init ftfuns for just initialized derived table */
if (table->fulltext_searched)
if (init_ftfuncs(join->thd, join->select_lex, MY_TEST(join->order)))
- return TRUE;
+ DBUG_RETURN(TRUE);
- return FALSE;
+ DBUG_RETURN(FALSE);
}
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index ac9c39383c0..9869de4ba5e 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -8908,6 +8908,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
long_hash_key= true;
}
const char *dropped_key_part= NULL;
+ bool user_keyparts= false; // some user-defined keyparts left
KEY_PART_INFO *key_part= key_info->key_part;
key_parts.empty();
uint key_parts_nr= key_info->user_defined_key_parts;
@@ -8987,6 +8988,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
key_parts.push_back(new (thd->mem_root) Key_part_spec(&cfield->field_name,
key_part_length, true),
thd->mem_root);
+ if (cfield->invisible < INVISIBLE_SYSTEM)
+ user_keyparts= true;
}
if (table->s->tmp_table == NO_TMP_TABLE)
{
@@ -9033,7 +9036,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
key_type= Key::PRIMARY;
else
key_type= Key::UNIQUE;
- if (dropped_key_part)
+ if (dropped_key_part && user_keyparts)
{
my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), dropped_key_part);
if (long_hash_key)
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 35ceeeff43a..79b1166338a 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates.
- Copyright (c) 2011, 2020, MariaDB
+ Copyright (c) 2011, 2021, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -2490,10 +2490,10 @@ int multi_update::send_data(List<Item> &not_used_values)
{
TABLE_LIST *cur_table;
DBUG_ENTER("multi_update::send_data");
- int error= 0;
for (cur_table= update_tables; cur_table; cur_table= cur_table->next_local)
{
+ int error= 0;
TABLE *table= cur_table->table;
uint offset= cur_table->shared;
/*
@@ -2563,21 +2563,7 @@ int multi_update::send_data(List<Item> &not_used_values)
updated--;
if (!ignore ||
table->file->is_fatal_error(error, HA_CHECK_ALL))
- {
-error:
- /*
- If (ignore && error == is ignorable) we don't have to
- do anything; otherwise...
- */
- myf flags= 0;
-
- if (table->file->is_fatal_error(error, HA_CHECK_ALL))
- flags|= ME_FATAL; /* Other handler errors are fatal */
-
- prepare_record_for_error_message(error, table);
- table->file->print_error(error,MYF(flags));
- DBUG_RETURN(1);
- }
+ goto error;
}
else
{
@@ -2653,7 +2639,22 @@ error:
}
}
}
- }
+ continue;
+error:
+ DBUG_ASSERT(error > 0);
+ /*
+ If (ignore && error == is ignorable) we don't have to
+ do anything; otherwise...
+ */
+ myf flags= 0;
+
+ if (table->file->is_fatal_error(error, HA_CHECK_ALL))
+ flags|= ME_FATAL; /* Other handler errors are fatal */
+
+ prepare_record_for_error_message(error, table);
+ table->file->print_error(error,MYF(flags));
+ DBUG_RETURN(1);
+ } // for (cur_table)
DBUG_RETURN(0);
}
diff --git a/sql/wsrep_trans_observer.h b/sql/wsrep_trans_observer.h
index 1f6576093cb..942363d9886 100644
--- a/sql/wsrep_trans_observer.h
+++ b/sql/wsrep_trans_observer.h
@@ -439,8 +439,10 @@ static inline void wsrep_after_apply(THD* thd)
static inline void wsrep_open(THD* thd)
{
DBUG_ENTER("wsrep_open");
- if (WSREP_PROVIDER_EXISTS)
+ if (WSREP_ON_)
{
+ /* WSREP_PROVIDER_EXISTS_ cannot be set if WSREP_ON_ is not set */
+ DBUG_ASSERT(WSREP_PROVIDER_EXISTS_);
thd->wsrep_cs().open(wsrep::client_id(thd->thread_id));
thd->wsrep_cs().debug_log_level(wsrep_debug);
if (!thd->wsrep_applier && thd->variables.wsrep_trx_fragment_size)
diff --git a/storage/innobase/btr/btr0btr.cc b/storage/innobase/btr/btr0btr.cc
index fa7f2cfc6f8..19c280eea90 100644
--- a/storage/innobase/btr/btr0btr.cc
+++ b/storage/innobase/btr/btr0btr.cc
@@ -829,7 +829,7 @@ btr_page_get_father_node_ptr_func(
node_ptr = btr_cur_get_rec(cursor);
- offsets = rec_get_offsets(node_ptr, index, offsets, false,
+ offsets = rec_get_offsets(node_ptr, index, offsets, 0,
ULINT_UNDEFINED, &heap);
if (btr_node_ptr_get_child_page_no(node_ptr, offsets) != page_no) {
@@ -846,10 +846,11 @@ btr_page_get_father_node_ptr_func(
print_rec = page_rec_get_next(
page_get_infimum_rec(page_align(user_rec)));
offsets = rec_get_offsets(print_rec, index, offsets,
- page_rec_is_leaf(user_rec),
+ page_rec_is_leaf(user_rec)
+ ? index->n_core_fields : 0,
ULINT_UNDEFINED, &heap);
page_rec_print(print_rec, offsets);
- offsets = rec_get_offsets(node_ptr, index, offsets, false,
+ offsets = rec_get_offsets(node_ptr, index, offsets, 0,
ULINT_UNDEFINED, &heap);
page_rec_print(node_ptr, offsets);
@@ -2241,7 +2242,9 @@ btr_page_get_split_rec(
incl_data += insert_size;
} else {
offsets = rec_get_offsets(rec, cursor->index, offsets,
- page_is_leaf(page),
+ page_is_leaf(page)
+ ? cursor->index->n_core_fields
+ : 0,
ULINT_UNDEFINED, &heap);
incl_data += rec_offs_size(offsets);
}
@@ -2350,7 +2353,9 @@ btr_page_insert_fits(
space after rec is removed from page. */
*offsets = rec_get_offsets(rec, cursor->index, *offsets,
- page_is_leaf(page),
+ page_is_leaf(page)
+ ? cursor->index->n_core_fields
+ : 0,
ULINT_UNDEFINED, heap);
total_data -= rec_offs_size(*offsets);
@@ -2605,7 +2610,8 @@ btr_page_tuple_smaller(
first_rec = page_cur_get_rec(&pcur);
*offsets = rec_get_offsets(
- first_rec, cursor->index, *offsets, page_is_leaf(block->frame),
+ first_rec, cursor->index, *offsets,
+ page_is_leaf(block->frame) ? cursor->index->n_core_fields : 0,
n_uniq, heap);
return(cmp_dtuple_rec(tuple, first_rec, *offsets) < 0);
@@ -2893,7 +2899,9 @@ func_start:
first_rec = move_limit = split_rec;
*offsets = rec_get_offsets(split_rec, cursor->index, *offsets,
- page_is_leaf(page), n_uniq, heap);
+ page_is_leaf(page)
+ ? cursor->index->n_core_fields : 0,
+ n_uniq, heap);
insert_left = !tuple
|| cmp_dtuple_rec(tuple, split_rec, *offsets) < 0;
@@ -3537,7 +3545,7 @@ retry:
rec_offs* offsets2 = NULL;
/* For rtree, we need to update father's mbr. */
- if (dict_index_is_spatial(index)) {
+ if (index->is_spatial()) {
/* We only support merge pages with the same parent
page */
if (!rtr_check_same_block(
@@ -3555,7 +3563,8 @@ retry:
offsets2 = rec_get_offsets(
btr_cur_get_rec(&cursor2), index, NULL,
- page_is_leaf(cursor2.page_cur.block->frame),
+ page_is_leaf(cursor2.page_cur.block->frame)
+ ? index->n_fields : 0,
ULINT_UNDEFINED, &heap);
/* Check if parent entry needs to be updated */
@@ -3723,13 +3732,14 @@ retry:
#endif /* UNIV_DEBUG */
/* For rtree, we need to update father's mbr. */
- if (dict_index_is_spatial(index)) {
+ if (index->is_spatial()) {
rec_offs* offsets2;
ulint rec_info;
offsets2 = rec_get_offsets(
btr_cur_get_rec(&cursor2), index, NULL,
- page_is_leaf(cursor2.page_cur.block->frame),
+ page_is_leaf(cursor2.page_cur.block->frame)
+ ? index->n_fields : 0,
ULINT_UNDEFINED, &heap);
ut_ad(btr_node_ptr_get_child_page_no(
@@ -3941,16 +3951,16 @@ btr_discard_only_page_on_level(
}
#endif /* UNIV_BTR_DEBUG */
- mem_heap_t* heap = NULL;
- const rec_t* rec = NULL;
- rec_offs* offsets = NULL;
-
+ mem_heap_t* heap = nullptr;
+ const rec_t* rec = nullptr;
+ rec_offs* offsets = nullptr;
if (index->table->instant || index->must_avoid_clear_instant_add()) {
if (!rec_is_metadata(r, *index)) {
} else if (!index->table->instant
|| rec_is_alter_metadata(r, *index)) {
heap = mem_heap_create(srv_page_size);
- offsets = rec_get_offsets(r, index, NULL, true,
+ offsets = rec_get_offsets(r, index, nullptr,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
rec = rec_copy(mem_heap_alloc(heap,
rec_offs_size(offsets)),
@@ -4207,7 +4217,7 @@ btr_print_recursive(
node_ptr = page_cur_get_rec(&cursor);
*offsets = rec_get_offsets(
- node_ptr, index, *offsets, false,
+ node_ptr, index, *offsets, 0,
ULINT_UNDEFINED, heap);
btr_print_recursive(index,
btr_node_ptr_get_child(node_ptr,
@@ -4356,7 +4366,9 @@ btr_index_rec_validate(
page = page_align(rec);
- if (dict_index_is_ibuf(index)) {
+ ut_ad(index->n_core_fields);
+
+ if (index->is_ibuf()) {
/* The insert buffer index tree can contain records from any
other index: we cannot check the number of fields or
their length */
@@ -4420,7 +4432,8 @@ n_field_mismatch:
}
}
- offsets = rec_get_offsets(rec, index, offsets, page_is_leaf(page),
+ offsets = rec_get_offsets(rec, index, offsets, page_is_leaf(page)
+ ? index->n_core_fields : 0,
ULINT_UNDEFINED, &heap);
const dict_field_t* field = index->fields;
ut_ad(rec_offs_n_fields(offsets)
@@ -4673,7 +4686,7 @@ btr_validate_level(
page_cur_move_to_next(&cursor);
node_ptr = page_cur_get_rec(&cursor);
- offsets = rec_get_offsets(node_ptr, index, offsets, false,
+ offsets = rec_get_offsets(node_ptr, index, offsets, 0,
ULINT_UNDEFINED, &heap);
savepoint2 = mtr_set_savepoint(&mtr);
@@ -4792,10 +4805,12 @@ loop:
right_rec = page_rec_get_next(page_get_infimum_rec(
right_page));
offsets = rec_get_offsets(rec, index, offsets,
- page_is_leaf(page),
+ page_is_leaf(page)
+ ? index->n_core_fields : 0,
ULINT_UNDEFINED, &heap);
offsets2 = rec_get_offsets(right_rec, index, offsets2,
- page_is_leaf(right_page),
+ page_is_leaf(right_page)
+ ? index->n_core_fields : 0,
ULINT_UNDEFINED, &heap);
/* For spatial index, we cannot guarantee the key ordering
diff --git a/storage/innobase/btr/btr0bulk.cc b/storage/innobase/btr/btr0bulk.cc
index 0dbcfd7af25..13e0e3a0eff 100644
--- a/storage/innobase/btr/btr0bulk.cc
+++ b/storage/innobase/btr/btr0bulk.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2014, 2019, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2020, MariaDB Corporation.
+Copyright (c) 2017, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -170,7 +170,8 @@ inline void PageBulk::insertPage(rec_t *rec, rec_offs *offsets)
(fmt == REDUNDANT ? PAGE_OLD_INFIMUM : PAGE_NEW_INFIMUM))
{
const rec_t *old_rec = m_cur_rec;
- rec_offs *old_offsets= rec_get_offsets(old_rec, m_index, nullptr, is_leaf,
+ rec_offs *old_offsets= rec_get_offsets(old_rec, m_index, nullptr, is_leaf
+ ? m_index->n_core_fields : 0,
ULINT_UNDEFINED, &m_heap);
ut_ad(cmp_rec_rec(rec, old_rec, offsets, old_offsets, m_index) > 0);
}
@@ -604,6 +605,7 @@ PageBulk::getSplitRec()
ut_ad(m_page_zip != NULL);
ut_ad(m_rec_no >= 2);
+ ut_ad(!m_index->is_instant());
ut_ad(page_get_free_space_of_empty(m_is_comp) > m_free_space);
total_used_size = page_get_free_space_of_empty(m_is_comp)
@@ -613,13 +615,13 @@ PageBulk::getSplitRec()
n_recs = 0;
offsets = NULL;
rec = page_get_infimum_rec(m_page);
+ const ulint n_core = page_is_leaf(m_page) ? m_index->n_core_fields : 0;
do {
rec = page_rec_get_next(rec);
ut_ad(page_rec_is_user_rec(rec));
- offsets = rec_get_offsets(rec, m_index, offsets,
- page_is_leaf(m_page),
+ offsets = rec_get_offsets(rec, m_index, offsets, n_core,
ULINT_UNDEFINED, &m_heap);
total_recs_size += rec_offs_size(offsets);
n_recs++;
@@ -648,9 +650,11 @@ PageBulk::copyIn(
ut_ad(m_rec_no == 0);
ut_ad(page_rec_is_user_rec(rec));
+ const ulint n_core = page_rec_is_leaf(rec)
+ ? m_index->n_core_fields : 0;
+
do {
- offsets = rec_get_offsets(rec, m_index, offsets,
- page_rec_is_leaf(split_rec),
+ offsets = rec_get_offsets(rec, m_index, offsets, n_core,
ULINT_UNDEFINED, &m_heap);
insert(rec, offsets);
@@ -691,8 +695,10 @@ PageBulk::copyOut(
/* Set last record's next in page */
rec_offs* offsets = NULL;
rec = page_rec_get_prev(split_rec);
- offsets = rec_get_offsets(rec, m_index, offsets,
- page_rec_is_leaf(split_rec),
+ const ulint n_core = page_rec_is_leaf(split_rec)
+ ? m_index->n_core_fields : 0;
+
+ offsets = rec_get_offsets(rec, m_index, offsets, n_core,
ULINT_UNDEFINED, &m_heap);
mach_write_to_2(rec - REC_NEXT, m_is_comp
? static_cast<uint16_t>
@@ -703,8 +709,7 @@ PageBulk::copyOut(
m_cur_rec = rec;
m_heap_top = rec_get_end(rec, offsets);
- offsets = rec_get_offsets(last_rec, m_index, offsets,
- page_rec_is_leaf(split_rec),
+ offsets = rec_get_offsets(last_rec, m_index, offsets, n_core,
ULINT_UNDEFINED, &m_heap);
m_free_space += ulint(rec_get_end(last_rec, offsets) - m_heap_top)
@@ -1116,7 +1121,8 @@ BtrBulk::insert(
/* Convert tuple to rec. */
rec = rec_convert_dtuple_to_rec(static_cast<byte*>(mem_heap_alloc(
page_bulk->m_heap, rec_size)), m_index, tuple, n_ext);
- offsets = rec_get_offsets(rec, m_index, offsets, !level,
+ offsets = rec_get_offsets(rec, m_index, offsets, level
+ ? 0 : m_index->n_core_fields,
ULINT_UNDEFINED, &page_bulk->m_heap);
page_bulk->insert(rec, offsets);
diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc
index 0710aa640a0..158c017f1b0 100644
--- a/storage/innobase/btr/btr0cur.cc
+++ b/storage/innobase/btr/btr0cur.cc
@@ -592,7 +592,8 @@ incompatible:
}
mem_heap_t* heap = NULL;
- rec_offs* offsets = rec_get_offsets(rec, index, NULL, true,
+ rec_offs* offsets = rec_get_offsets(rec, index, NULL,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (rec_offs_any_default(offsets)) {
inconsistent:
@@ -2033,7 +2034,7 @@ retry_page_get:
node_ptr = page_cur_get_rec(page_cursor);
- offsets = rec_get_offsets(node_ptr, index, offsets, false,
+ offsets = rec_get_offsets(node_ptr, index, offsets, 0,
ULINT_UNDEFINED, &heap);
/* If the rec is the first or last in the page for
@@ -2163,7 +2164,7 @@ need_opposite_intention:
offsets2 = rec_get_offsets(
first_rec, index, offsets2,
- false, ULINT_UNDEFINED, &heap);
+ 0, ULINT_UNDEFINED, &heap);
cmp_rec_rec(node_ptr, first_rec,
offsets, offsets2, index, false,
&matched_fields);
@@ -2181,7 +2182,7 @@ need_opposite_intention:
offsets2 = rec_get_offsets(
last_rec, index, offsets2,
- false, ULINT_UNDEFINED, &heap);
+ 0, ULINT_UNDEFINED, &heap);
cmp_rec_rec(
node_ptr, last_rec,
offsets, offsets2, index,
@@ -2350,7 +2351,7 @@ need_opposite_intention:
offsets = rec_get_offsets(
my_node_ptr, index, offsets,
- false, ULINT_UNDEFINED, &heap);
+ 0, ULINT_UNDEFINED, &heap);
ulint my_page_no
= btr_node_ptr_get_child_page_no(
@@ -2772,7 +2773,7 @@ btr_cur_open_at_index_side(
node_ptr = page_cur_get_rec(page_cursor);
offsets = rec_get_offsets(node_ptr, cursor->index, offsets,
- false, ULINT_UNDEFINED, &heap);
+ 0, ULINT_UNDEFINED, &heap);
/* If the rec is the first or last in the page for
pessimistic delete intention, it might cause node_ptr insert
@@ -3061,7 +3062,7 @@ btr_cur_open_at_rnd_pos(
node_ptr = page_cur_get_rec(page_cursor);
offsets = rec_get_offsets(node_ptr, cursor->index, offsets,
- false, ULINT_UNDEFINED, &heap);
+ 0, ULINT_UNDEFINED, &heap);
/* If the rec is the first or last in the page for
pessimistic delete intention, it might cause node_ptr insert
@@ -4581,7 +4582,7 @@ btr_cur_optimistic_update(
ut_ad(fil_page_index_page_check(page));
ut_ad(btr_page_get_index_id(page) == index->id);
- *offsets = rec_get_offsets(rec, index, *offsets, true,
+ *offsets = rec_get_offsets(rec, index, *offsets, index->n_core_fields,
ULINT_UNDEFINED, heap);
#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
ut_a(!rec_offs_any_null_extern(rec, *offsets)
@@ -5501,7 +5502,8 @@ btr_cur_optimistic_delete_func(
rec = btr_cur_get_rec(cursor);
- offsets = rec_get_offsets(rec, cursor->index, offsets, true,
+ offsets = rec_get_offsets(rec, cursor->index, offsets,
+ cursor->index->n_core_fields,
ULINT_UNDEFINED, &heap);
const ibool no_compress_needed = !rec_offs_any_extern(offsets)
@@ -5710,7 +5712,8 @@ btr_cur_pessimistic_delete(
ut_a(!page_zip || page_zip_validate(page_zip, page, index));
#endif /* UNIV_ZIP_DEBUG */
- offsets = rec_get_offsets(rec, index, NULL, page_is_leaf(page),
+ offsets = rec_get_offsets(rec, index, NULL, page_is_leaf(page)
+ ? index->n_core_fields : 0,
ULINT_UNDEFINED, &heap);
if (rec_offs_any_extern(offsets)) {
@@ -5812,7 +5815,7 @@ discard_page:
pointer as the predefined minimum record */
min_mark_next_rec = true;
- } else if (dict_index_is_spatial(index)) {
+ } else if (index->is_spatial()) {
/* For rtree, if delete the leftmost node pointer,
we need to update parent page. */
rtr_mbr_t father_mbr;
@@ -5827,7 +5830,7 @@ discard_page:
&father_cursor);
offsets = rec_get_offsets(
btr_cur_get_rec(&father_cursor), index, NULL,
- false, ULINT_UNDEFINED, &heap);
+ 0, ULINT_UNDEFINED, &heap);
father_rec = btr_cur_get_rec(&father_cursor);
rtr_read_mbr(rec_get_nth_field(
@@ -6745,12 +6748,13 @@ btr_estimate_number_of_different_key_vals(dict_index_t* index)
page = btr_cur_get_page(&cursor);
rec = page_rec_get_next(page_get_infimum_rec(page));
- const bool is_leaf = page_is_leaf(page);
+ const ulint n_core = page_is_leaf(page)
+ ? index->n_core_fields : 0;
if (!page_rec_is_supremum(rec)) {
not_empty_flag = 1;
offsets_rec = rec_get_offsets(rec, index, offsets_rec,
- is_leaf,
+ n_core,
ULINT_UNDEFINED, &heap);
if (n_not_null != NULL) {
@@ -6771,7 +6775,7 @@ btr_estimate_number_of_different_key_vals(dict_index_t* index)
offsets_next_rec = rec_get_offsets(next_rec, index,
offsets_next_rec,
- is_leaf,
+ n_core,
ULINT_UNDEFINED,
&heap);
diff --git a/storage/innobase/btr/btr0defragment.cc b/storage/innobase/btr/btr0defragment.cc
index 4f23a4f88d3..6bd04253a86 100644
--- a/storage/innobase/btr/btr0defragment.cc
+++ b/storage/innobase/btr/btr0defragment.cc
@@ -258,12 +258,12 @@ btr_defragment_calc_n_recs_for_size(
ulint size = 0;
page_cur_t cur;
+ const ulint n_core = page_is_leaf(page) ? index->n_core_fields : 0;
page_cur_set_before_first(block, &cur);
page_cur_move_to_next(&cur);
while (page_cur_get_rec(&cur) != page_get_supremum_rec(page)) {
rec_t* cur_rec = page_cur_get_rec(&cur);
- offsets = rec_get_offsets(cur_rec, index, offsets,
- page_is_leaf(page),
+ offsets = rec_get_offsets(cur_rec, index, offsets, n_core,
ULINT_UNDEFINED, &heap);
ulint rec_size = rec_offs_size(offsets);
size += rec_size;
@@ -275,6 +275,9 @@ btr_defragment_calc_n_recs_for_size(
page_cur_move_to_next(&cur);
}
*n_recs_size = size;
+ if (UNIV_LIKELY_NULL(heap)) {
+ mem_heap_free(heap);
+ }
return n_recs;
}
diff --git a/storage/innobase/btr/btr0pcur.cc b/storage/innobase/btr/btr0pcur.cc
index 00600a5d791..e425ed7820e 100644
--- a/storage/innobase/btr/btr0pcur.cc
+++ b/storage/innobase/btr/btr0pcur.cc
@@ -61,6 +61,7 @@ btr_pcur_reset(
cursor->btr_cur.index = NULL;
cursor->btr_cur.page_cur.rec = NULL;
cursor->old_rec = NULL;
+ cursor->old_n_core_fields = 0;
cursor->old_n_fields = 0;
cursor->old_stored = false;
@@ -184,19 +185,21 @@ before_first:
if (index->is_ibuf()) {
ut_ad(!index->table->not_redundant());
- cursor->old_n_fields = rec_get_n_fields_old(rec);
- } else if (page_rec_is_leaf(rec)) {
- cursor->old_n_fields = dict_index_get_n_unique_in_tree(index);
- } else if (index->is_spatial()) {
- ut_ad(dict_index_get_n_unique_in_tree_nonleaf(index)
- == DICT_INDEX_SPATIAL_NODEPTR_SIZE);
- /* For R-tree, we have to compare
- the child page numbers as well. */
- cursor->old_n_fields = DICT_INDEX_SPATIAL_NODEPTR_SIZE + 1;
+ cursor->old_n_fields = uint16_t(rec_get_n_fields_old(rec));
} else {
- cursor->old_n_fields = dict_index_get_n_unique_in_tree(index);
+ cursor->old_n_fields = static_cast<uint16>(
+ dict_index_get_n_unique_in_tree(index));
+ if (index->is_spatial() && !page_rec_is_leaf(rec)) {
+ ut_ad(dict_index_get_n_unique_in_tree_nonleaf(index)
+ == DICT_INDEX_SPATIAL_NODEPTR_SIZE);
+ /* For R-tree, we have to compare
+ the child page numbers as well. */
+ cursor->old_n_fields
+ = DICT_INDEX_SPATIAL_NODEPTR_SIZE + 1;
+ }
}
+ cursor->old_n_core_fields = index->n_core_fields;
cursor->old_rec = rec_copy_prefix_to_buf(rec, index,
cursor->old_n_fields,
&cursor->old_rec_buf,
@@ -231,6 +234,7 @@ btr_pcur_copy_stored_position(
+ (pcur_donate->old_rec - pcur_donate->old_rec_buf);
}
+ pcur_receive->old_n_core_fields = pcur_donate->old_n_core_fields;
pcur_receive->old_n_fields = pcur_donate->old_n_fields;
}
@@ -317,6 +321,8 @@ btr_pcur_restore_position(
}
ut_a(cursor->old_rec);
+ ut_a(cursor->old_n_core_fields);
+ ut_a(cursor->old_n_core_fields <= index->n_core_fields);
ut_a(cursor->old_n_fields);
switch (latch_mode) {
@@ -345,11 +351,16 @@ btr_pcur_restore_position(
rec_offs_init(offsets2_);
heap = mem_heap_create(256);
+ ut_ad(cursor->old_n_core_fields
+ == index->n_core_fields);
+
offsets1 = rec_get_offsets(
- cursor->old_rec, index, offsets1, true,
+ cursor->old_rec, index, offsets1,
+ cursor->old_n_core_fields,
cursor->old_n_fields, &heap);
offsets2 = rec_get_offsets(
- rec, index, offsets2, true,
+ rec, index, offsets2,
+ index->n_core_fields,
cursor->old_n_fields, &heap);
ut_ad(!cmp_rec_rec(cursor->old_rec,
@@ -374,8 +385,14 @@ btr_pcur_restore_position(
heap = mem_heap_create(256);
- tuple = dict_index_build_data_tuple(cursor->old_rec, index, true,
- cursor->old_n_fields, heap);
+ tuple = dtuple_create(heap, cursor->old_n_fields);
+
+ dict_index_copy_types(tuple, index, cursor->old_n_fields);
+
+ rec_copy_prefix_to_dtuple(tuple, cursor->old_rec, index,
+ cursor->old_n_core_fields,
+ cursor->old_n_fields, heap);
+ ut_ad(dtuple_check_typed(tuple));
/* Save the old search mode of the cursor */
old_mode = cursor->search_mode;
@@ -414,7 +431,8 @@ btr_pcur_restore_position(
&& btr_pcur_is_on_user_rec(cursor)
&& !cmp_dtuple_rec(tuple, btr_pcur_get_rec(cursor),
rec_get_offsets(btr_pcur_get_rec(cursor),
- index, offsets, true,
+ index, offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap))) {
/* We have to store the NEW value for the modify clock,
diff --git a/storage/innobase/btr/btr0sea.cc b/storage/innobase/btr/btr0sea.cc
index d637d41dd13..ccf4992d335 100644
--- a/storage/innobase/btr/btr0sea.cc
+++ b/storage/innobase/btr/btr0sea.cc
@@ -735,7 +735,8 @@ btr_search_update_hash_ref(
ulint fold = rec_fold(
rec,
- rec_get_offsets(rec, index, offsets_, true,
+ rec_get_offsets(rec, index, offsets_,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap),
block->curr_n_fields,
block->curr_n_bytes, index->id);
@@ -793,7 +794,8 @@ btr_search_check_guess(
match = 0;
- offsets = rec_get_offsets(rec, cursor->index, offsets, true,
+ offsets = rec_get_offsets(rec, cursor->index, offsets,
+ cursor->index->n_core_fields,
n_unique, &heap);
cmp = cmp_dtuple_rec_with_match(tuple, rec, offsets, &match);
@@ -844,7 +846,8 @@ btr_search_check_guess(
}
offsets = rec_get_offsets(prev_rec, cursor->index, offsets,
- true, n_unique, &heap);
+ cursor->index->n_core_fields,
+ n_unique, &heap);
cmp = cmp_dtuple_rec_with_match(
tuple, prev_rec, offsets, &match);
if (mode == PAGE_CUR_GE) {
@@ -867,7 +870,8 @@ btr_search_check_guess(
}
offsets = rec_get_offsets(next_rec, cursor->index, offsets,
- true, n_unique, &heap);
+ cursor->index->n_core_fields,
+ n_unique, &heap);
cmp = cmp_dtuple_rec_with_match(
tuple, next_rec, offsets, &match);
if (mode == PAGE_CUR_LE) {
@@ -1330,7 +1334,7 @@ retry:
while (!page_rec_is_supremum(rec)) {
offsets = rec_get_offsets(
- rec, index, offsets, true,
+ rec, index, offsets, index->n_core_fields,
btr_search_get_n_fields(n_fields, n_bytes),
&heap);
fold = rec_fold(rec, offsets, n_fields, n_bytes, index_id);
@@ -1549,7 +1553,7 @@ btr_search_build_page_hash_index(
ut_a(index->id == btr_page_get_index_id(page));
offsets = rec_get_offsets(
- rec, index, offsets, true,
+ rec, index, offsets, index->n_core_fields,
btr_search_get_n_fields(n_fields, n_bytes),
&heap);
ut_ad(page_rec_is_supremum(rec)
@@ -1580,7 +1584,7 @@ btr_search_build_page_hash_index(
}
offsets = rec_get_offsets(
- next_rec, index, offsets, true,
+ next_rec, index, offsets, index->n_core_fields,
btr_search_get_n_fields(n_fields, n_bytes), &heap);
next_fold = rec_fold(next_rec, offsets, n_fields,
n_bytes, index->id);
@@ -1818,7 +1822,8 @@ void btr_search_update_hash_on_delete(btr_cur_t* cursor)
rec = btr_cur_get_rec(cursor);
- fold = rec_fold(rec, rec_get_offsets(rec, index, offsets_, true,
+ fold = rec_fold(rec, rec_get_offsets(rec, index, offsets_,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap),
block->curr_n_fields, block->curr_n_bytes, index->id);
if (UNIV_LIKELY_NULL(heap)) {
@@ -1987,13 +1992,14 @@ void btr_search_update_hash_on_insert(btr_cur_t *cursor,
ins_rec = page_rec_get_next_const(rec);
next_rec = page_rec_get_next_const(ins_rec);
- offsets = rec_get_offsets(ins_rec, index, offsets, true,
+ offsets = rec_get_offsets(ins_rec, index, offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
ins_fold = rec_fold(ins_rec, offsets, n_fields, n_bytes, index->id);
if (!page_rec_is_supremum(next_rec)) {
offsets = rec_get_offsets(
- next_rec, index, offsets, true,
+ next_rec, index, offsets, index->n_core_fields,
btr_search_get_n_fields(n_fields, n_bytes), &heap);
next_fold = rec_fold(next_rec, offsets, n_fields,
n_bytes, index->id);
@@ -2005,7 +2011,7 @@ void btr_search_update_hash_on_insert(btr_cur_t *cursor,
if (!page_rec_is_infimum(rec) && !rec_is_metadata(rec, *index)) {
offsets = rec_get_offsets(
- rec, index, offsets, true,
+ rec, index, offsets, index->n_core_fields,
btr_search_get_n_fields(n_fields, n_bytes), &heap);
fold = rec_fold(rec, offsets, n_fields, n_bytes, index->id);
} else {
@@ -2232,7 +2238,8 @@ state_ok:
page_index_id = btr_page_get_index_id(block->frame);
offsets = rec_get_offsets(
- node->data, block->index, offsets, true,
+ node->data, block->index, offsets,
+ block->index->n_core_fields,
btr_search_get_n_fields(block->curr_n_fields,
block->curr_n_bytes),
&heap);
diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc
index fd17f09148e..da8a2bce1ff 100644
--- a/storage/innobase/dict/dict0dict.cc
+++ b/storage/innobase/dict/dict0dict.cc
@@ -2,7 +2,7 @@
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc.
-Copyright (c) 2013, 2020, MariaDB Corporation.
+Copyright (c) 2013, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -260,7 +260,7 @@ dict_table_try_drop_aborted(
&& !UT_LIST_GET_FIRST(table->locks)) {
/* Silence a debug assertion in row_merge_drop_indexes(). */
ut_d(table->acquire());
- row_merge_drop_indexes(trx, table, TRUE);
+ row_merge_drop_indexes(trx, table, true);
ut_d(table->release());
ut_ad(table->get_ref_count() == ref_count);
trx_commit_for_mysql(trx);
@@ -3928,7 +3928,9 @@ dict_index_build_node_ptr(
dtype_set(dfield_get_type(field), DATA_SYS_CHILD, DATA_NOT_NULL, 4);
- rec_copy_prefix_to_dtuple(tuple, rec, index, !level, n_unique, heap);
+ rec_copy_prefix_to_dtuple(tuple, rec, index,
+ level ? 0 : index->n_core_fields,
+ n_unique, heap);
dtuple_set_info_bits(tuple, dtuple_get_info_bits(tuple)
| REC_STATUS_NODE_PTR);
@@ -3952,11 +3954,14 @@ dict_index_build_data_tuple(
ulint n_fields,
mem_heap_t* heap)
{
+ ut_ad(!index->is_clust());
+
dtuple_t* tuple = dtuple_create(heap, n_fields);
dict_index_copy_types(tuple, index, n_fields);
- rec_copy_prefix_to_dtuple(tuple, rec, index, leaf, n_fields, heap);
+ rec_copy_prefix_to_dtuple(tuple, rec, index,
+ leaf ? n_fields : 0, n_fields, heap);
ut_ad(dtuple_check_typed(tuple));
diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc
index f4a56faaf28..b489dfd17bd 100644
--- a/storage/innobase/dict/dict0mem.cc
+++ b/storage/innobase/dict/dict0mem.cc
@@ -937,7 +937,7 @@ dict_mem_fill_vcol_from_v_indexes(
Later virtual column set will be
refreshed during loading of table. */
if (!dict_index_has_virtual(index)
- || index->has_new_v_col) {
+ || index->has_new_v_col()) {
continue;
}
@@ -1376,7 +1376,8 @@ dict_index_t::vers_history_row(
rec_t* clust_rec =
row_get_clust_rec(BTR_SEARCH_LEAF, rec, this, &clust_index, &mtr);
if (clust_rec) {
- offsets = rec_get_offsets(clust_rec, clust_index, offsets, true,
+ offsets = rec_get_offsets(clust_rec, clust_index, offsets,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, &heap);
history_row = clust_index->vers_history_row(clust_rec, offsets);
diff --git a/storage/innobase/dict/dict0stats.cc b/storage/innobase/dict/dict0stats.cc
index b6528e5d26c..bdca018813b 100644
--- a/storage/innobase/dict/dict0stats.cc
+++ b/storage/innobase/dict/dict0stats.cc
@@ -1167,7 +1167,7 @@ dict_stats_analyze_index_level(
prev_rec_offsets = rec_get_offsets(
prev_rec, index, prev_rec_offsets,
- true,
+ index->n_core_fields,
n_uniq, &heap);
prev_rec = rec_copy_prefix_to_buf(
@@ -1179,8 +1179,9 @@ dict_stats_analyze_index_level(
continue;
}
- rec_offsets = rec_get_offsets(
- rec, index, rec_offsets, !level, n_uniq, &heap);
+ rec_offsets = rec_get_offsets(rec, index, rec_offsets,
+ level ? 0 : index->n_core_fields,
+ n_uniq, &heap);
(*total_recs)++;
@@ -1188,7 +1189,8 @@ dict_stats_analyze_index_level(
ulint matched_fields;
prev_rec_offsets = rec_get_offsets(
- prev_rec, index, prev_rec_offsets, !level,
+ prev_rec, index, prev_rec_offsets,
+ level ? 0 : index->n_core_fields,
n_uniq, &heap);
cmp_rec_rec(prev_rec, rec,
@@ -1342,7 +1344,7 @@ be big enough)
@param[in] index index of the page
@param[in] page the page to scan
@param[in] n_prefix look at the first n_prefix columns
-@param[in] is_leaf whether this is the leaf page
+@param[in] n_core 0, or index->n_core_fields for leaf
@param[out] n_diff number of distinct records encountered
@param[out] n_external_pages if this is non-NULL then it will be set
to the number of externally stored pages which were encountered
@@ -1357,7 +1359,7 @@ dict_stats_scan_page(
const dict_index_t* index,
const page_t* page,
ulint n_prefix,
- bool is_leaf,
+ ulint n_core,
ib_uint64_t* n_diff,
ib_uint64_t* n_external_pages)
{
@@ -1369,9 +1371,9 @@ dict_stats_scan_page(
Because offsets1,offsets2 should be big enough,
this memory heap should never be used. */
mem_heap_t* heap = NULL;
- ut_ad(is_leaf == page_is_leaf(page));
+ ut_ad(!!n_core == page_is_leaf(page));
const rec_t* (*get_next)(const rec_t*)
- = !is_leaf || srv_stats_include_delete_marked
+ = !n_core || srv_stats_include_delete_marked
? page_rec_get_next_const
: page_rec_get_next_non_del_marked;
@@ -1390,7 +1392,7 @@ dict_stats_scan_page(
return(NULL);
}
- offsets_rec = rec_get_offsets(rec, index, offsets_rec, is_leaf,
+ offsets_rec = rec_get_offsets(rec, index, offsets_rec, n_core,
ULINT_UNDEFINED, &heap);
if (should_count_external_pages) {
@@ -1407,7 +1409,7 @@ dict_stats_scan_page(
ulint matched_fields;
offsets_next_rec = rec_get_offsets(next_rec, index,
- offsets_next_rec, is_leaf,
+ offsets_next_rec, n_core,
ULINT_UNDEFINED,
&heap);
@@ -1421,7 +1423,7 @@ dict_stats_scan_page(
(*n_diff)++;
- if (!is_leaf) {
+ if (!n_core) {
break;
}
}
@@ -1508,7 +1510,7 @@ dict_stats_analyze_index_below_cur(
page = page_align(rec);
ut_ad(!page_rec_is_leaf(rec));
- offsets_rec = rec_get_offsets(rec, index, offsets1, false,
+ offsets_rec = rec_get_offsets(rec, index, offsets1, 0,
ULINT_UNDEFINED, &heap);
page_id_t page_id(index->table->space_id,
@@ -1544,7 +1546,7 @@ dict_stats_analyze_index_below_cur(
/* search for the first non-boring record on the page */
offsets_rec = dict_stats_scan_page(
&rec, offsets1, offsets2, index, page, n_prefix,
- false, n_diff, NULL);
+ 0, n_diff, NULL);
/* pages on level > 0 are not allowed to be empty */
ut_a(offsets_rec != NULL);
@@ -1589,7 +1591,7 @@ dict_stats_analyze_index_below_cur(
offsets_rec = dict_stats_scan_page(
&rec, offsets1, offsets2, index, page, n_prefix,
- true, n_diff,
+ index->n_core_fields, n_diff,
n_external_pages);
#if 0
diff --git a/storage/innobase/dict/dict0stats_bg.cc b/storage/innobase/dict/dict0stats_bg.cc
index 8b9cc02484c..52ff6d7bfe4 100644
--- a/storage/innobase/dict/dict0stats_bg.cc
+++ b/storage/innobase/dict/dict0stats_bg.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2012, 2017, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2020, MariaDB Corporation.
+Copyright (c) 2017, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -146,9 +146,24 @@ schedule new estimates for table and index statistics to be calculated.
void dict_stats_update_if_needed_func(dict_table_t *table)
#endif
{
- ut_ad(table->stat_initialized);
dict_sys.assert_not_locked();
+ if (UNIV_UNLIKELY(!table->stat_initialized)) {
+ /* The table may have been evicted from dict_sys
+ and reloaded internally by InnoDB for FOREIGN KEY
+ processing, but not reloaded by the SQL layer.
+
+ We can (re)compute the transient statistics when the
+ table is actually loaded by the SQL layer.
+
+ Note: If InnoDB persistent statistics are enabled,
+ we will skip the updates. We must do this, because
+ dict_table_get_n_rows() below assumes that the
+ statistics have been initialized. The DBA may have
+ to execute ANALYZE TABLE. */
+ return;
+ }
+
ulonglong counter = table->stat_modified_counter++;
ulonglong n_rows = dict_table_get_n_rows(table);
diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc
index cc7ffa4d8bc..ae88d0bd3c0 100644
--- a/storage/innobase/fts/fts0fts.cc
+++ b/storage/innobase/fts/fts0fts.cc
@@ -2507,7 +2507,8 @@ fts_get_max_cache_size(
}
} else {
ib::error() << "(" << error << ") reading max"
- " cache config value from config table";
+ " cache config value from config table "
+ << fts_table->table->name;
}
ut_free(value.f_str);
@@ -2680,7 +2681,8 @@ func_exit:
} else {
*doc_id = 0;
- ib::error() << "(" << error << ") while getting next doc id.";
+ ib::error() << "(" << error << ") while getting next doc id "
+ "for table " << table->name;
fts_sql_rollback(trx);
if (error == DB_DEADLOCK) {
@@ -2760,7 +2762,8 @@ fts_update_sync_doc_id(
cache->synced_doc_id = doc_id;
} else {
ib::error() << "(" << error << ") while"
- " updating last doc id.";
+ " updating last doc id for table"
+ << table->name;
fts_sql_rollback(trx);
}
@@ -3471,7 +3474,8 @@ fts_add_doc_by_id(
}
- offsets = rec_get_offsets(clust_rec, clust_index, NULL, true,
+ offsets = rec_get_offsets(clust_rec, clust_index, NULL,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, &heap);
for (ulint i = 0; i < num_idx; ++i) {
@@ -3993,7 +3997,8 @@ fts_sync_write_words(
if (UNIV_UNLIKELY(error != DB_SUCCESS) && !print_error) {
ib::error() << "(" << error << ") writing"
- " word node to FTS auxiliary index table.";
+ " word node to FTS auxiliary index table "
+ << table->name;
print_error = TRUE;
}
}
@@ -4148,7 +4153,8 @@ fts_sync_commit(
fts_sql_commit(trx);
} else {
fts_sql_rollback(trx);
- ib::error() << "(" << error << ") during SYNC.";
+ ib::error() << "(" << error << ") during SYNC of "
+ "table " << sync->table->name;
}
if (UNIV_UNLIKELY(fts_enable_diag_print) && elapsed_time) {
@@ -4910,7 +4916,8 @@ fts_get_rows_count(
trx->error_state = DB_SUCCESS;
} else {
ib::error() << "(" << error
- << ") while reading FTS table.";
+ << ") while reading FTS table "
+ << table_name;
break; /* Exit the loop. */
}
diff --git a/storage/innobase/gis/gis0rtree.cc b/storage/innobase/gis/gis0rtree.cc
index fef850d1ca7..a003100b3a2 100644
--- a/storage/innobase/gis/gis0rtree.cc
+++ b/storage/innobase/gis/gis0rtree.cc
@@ -87,8 +87,9 @@ rtr_page_split_initialize_nodes(
stop = task + n_recs;
rec = page_rec_get_next(page_get_infimum_rec(page));
- const bool is_leaf = page_is_leaf(page);
- *offsets = rec_get_offsets(rec, cursor->index, *offsets, is_leaf,
+ const ulint n_core = page_is_leaf(page)
+ ? cursor->index->n_core_fields : 0;
+ *offsets = rec_get_offsets(rec, cursor->index, *offsets, n_core,
n_uniq, &heap);
source_cur = rec_get_nth_field(rec, *offsets, 0, &len);
@@ -101,7 +102,7 @@ rtr_page_split_initialize_nodes(
rec = page_rec_get_next(rec);
*offsets = rec_get_offsets(rec, cursor->index, *offsets,
- is_leaf, n_uniq, &heap);
+ n_core, n_uniq, &heap);
source_cur = rec_get_nth_field(rec, *offsets, 0, &len);
}
@@ -230,7 +231,8 @@ rtr_update_mbr_field(
ut_ad(page == buf_block_get_frame(block));
child = btr_node_ptr_get_child_page_no(rec, offsets);
- const bool is_leaf = page_is_leaf(block->frame);
+ const ulint n_core = page_is_leaf(block->frame)
+ ? index->n_core_fields : 0;
if (new_rec) {
child_rec = new_rec;
@@ -246,7 +248,7 @@ rtr_update_mbr_field(
if (cursor2) {
rec_t* del_rec = btr_cur_get_rec(cursor2);
offsets2 = rec_get_offsets(btr_cur_get_rec(cursor2),
- index, NULL, false,
+ index, NULL, 0,
ULINT_UNDEFINED, &heap);
del_page_no = btr_node_ptr_get_child_page_no(del_rec, offsets2);
cur2_pos = page_rec_get_n_recs_before(btr_cur_get_rec(cursor2));
@@ -313,7 +315,7 @@ rtr_update_mbr_field(
= page_rec_get_nth(page, cur2_pos);
}
offsets2 = rec_get_offsets(btr_cur_get_rec(cursor2),
- index, NULL, false,
+ index, NULL, 0,
ULINT_UNDEFINED, &heap);
ut_ad(del_page_no == btr_node_ptr_get_child_page_no(
cursor2->page_cur.rec,
@@ -351,7 +353,7 @@ rtr_update_mbr_field(
ut_ad(old_rec != insert_rec);
page_cur_position(old_rec, block, &page_cur);
- offsets2 = rec_get_offsets(old_rec, index, NULL, is_leaf,
+ offsets2 = rec_get_offsets(old_rec, index, NULL, n_core,
ULINT_UNDEFINED, &heap);
page_cur_delete_rec(&page_cur, index, offsets2, mtr);
@@ -381,7 +383,7 @@ update_mbr:
cur2_rec = cursor2->page_cur.rec;
offsets2 = rec_get_offsets(cur2_rec, index, NULL,
- is_leaf,
+ n_core,
ULINT_UNDEFINED, &heap);
cur2_rec_info = rec_get_info_bits(cur2_rec,
@@ -441,7 +443,7 @@ update_mbr:
if (ins_suc) {
btr_cur_position(index, insert_rec, block, cursor);
offsets = rec_get_offsets(insert_rec,
- index, offsets, is_leaf,
+ index, offsets, n_core,
ULINT_UNDEFINED, &heap);
}
@@ -456,7 +458,7 @@ update_mbr:
cur2_rec = btr_cur_get_rec(cursor2);
offsets2 = rec_get_offsets(cur2_rec, index, NULL,
- is_leaf,
+ n_core,
ULINT_UNDEFINED, &heap);
/* If the cursor2 position is on a wrong rec, we
@@ -470,7 +472,7 @@ update_mbr:
while (!page_rec_is_supremum(cur2_rec)) {
offsets2 = rec_get_offsets(cur2_rec, index,
NULL,
- is_leaf,
+ n_core,
ULINT_UNDEFINED,
&heap);
cur2_pno = btr_node_ptr_get_child_page_no(
@@ -747,7 +749,8 @@ rtr_split_page_move_rec_list(
rec_move = static_cast<rtr_rec_move_t*>(mem_heap_alloc(
heap,
sizeof (*rec_move) * max_to_move));
- const bool is_leaf = page_is_leaf(page);
+ const ulint n_core = page_is_leaf(page)
+ ? index->n_core_fields : 0;
/* Insert the recs in group 2 to new page. */
for (cur_split_node = node_array;
@@ -757,10 +760,10 @@ rtr_split_page_move_rec_list(
block, cur_split_node->key);
offsets = rec_get_offsets(cur_split_node->key,
- index, offsets, is_leaf,
+ index, offsets, n_core,
ULINT_UNDEFINED, &heap);
- ut_ad(!is_leaf || cur_split_node->key != first_rec);
+ ut_ad(!n_core || cur_split_node->key != first_rec);
rec = page_cur_insert_rec_low(
&new_page_cursor,
@@ -792,7 +795,7 @@ rtr_split_page_move_rec_list(
same temp-table in parallel.
max_trx_id is ignored for temp tables because it not required
for MVCC. */
- if (is_leaf && !index->table->is_temporary()) {
+ if (n_core && !index->table->is_temporary()) {
page_update_max_trx_id(new_block, NULL,
page_get_max_trx_id(page),
mtr);
@@ -846,7 +849,7 @@ rtr_split_page_move_rec_list(
block, &page_cursor);
offsets = rec_get_offsets(
page_cur_get_rec(&page_cursor), index,
- offsets, is_leaf, ULINT_UNDEFINED,
+ offsets, n_core, ULINT_UNDEFINED,
&heap);
page_cur_delete_rec(&page_cursor,
index, offsets, mtr);
@@ -1049,6 +1052,9 @@ func_start:
/* Update the lock table */
lock_rtr_move_rec_list(new_block, block, rec_move, moved);
+ const ulint n_core = page_level
+ ? 0 : cursor->index->n_core_fields;
+
/* Delete recs in first group from the new page. */
for (cur_split_node = rtr_split_node_array;
cur_split_node < end_split_node - 1; ++cur_split_node) {
@@ -1067,7 +1073,7 @@ func_start:
*offsets = rec_get_offsets(
page_cur_get_rec(page_cursor),
- cursor->index, *offsets, !page_level,
+ cursor->index, *offsets, n_core,
ULINT_UNDEFINED, heap);
page_cur_delete_rec(page_cursor,
@@ -1084,7 +1090,7 @@ func_start:
block, page_cursor);
*offsets = rec_get_offsets(
page_cur_get_rec(page_cursor),
- cursor->index, *offsets, !page_level,
+ cursor->index, *offsets, n_core,
ULINT_UNDEFINED, heap);
page_cur_delete_rec(page_cursor,
cursor->index, *offsets, mtr);
@@ -1312,7 +1318,8 @@ rtr_page_copy_rec_list_end_no_locks(
rec_offs offsets_2[REC_OFFS_NORMAL_SIZE];
rec_offs* offsets2 = offsets_2;
ulint moved = 0;
- bool is_leaf = page_is_leaf(new_page);
+ const ulint n_core = page_is_leaf(new_page)
+ ? index->n_core_fields : 0;
rec_offs_init(offsets_1);
rec_offs_init(offsets_2);
@@ -1341,14 +1348,14 @@ rtr_page_copy_rec_list_end_no_locks(
cur_rec = page_rec_get_next(cur_rec);
}
- offsets1 = rec_get_offsets(cur1_rec, index, offsets1, is_leaf,
+ offsets1 = rec_get_offsets(cur1_rec, index, offsets1, n_core,
ULINT_UNDEFINED, &heap);
while (!page_rec_is_supremum(cur_rec)) {
ulint cur_matched_fields = 0;
int cmp;
offsets2 = rec_get_offsets(cur_rec, index, offsets2,
- is_leaf,
+ n_core,
ULINT_UNDEFINED, &heap);
cmp = cmp_rec_rec(cur1_rec, cur_rec,
offsets1, offsets2, index, false,
@@ -1360,7 +1367,7 @@ rtr_page_copy_rec_list_end_no_locks(
/* Skip small recs. */
page_cur_move_to_next(&page_cur);
cur_rec = page_cur_get_rec(&page_cur);
- } else if (is_leaf) {
+ } else if (n_core) {
if (rec_get_deleted_flag(cur1_rec,
dict_table_is_comp(index->table))) {
goto next;
@@ -1383,7 +1390,7 @@ rtr_page_copy_rec_list_end_no_locks(
cur_rec = page_cur_get_rec(&page_cur);
- offsets1 = rec_get_offsets(cur1_rec, index, offsets1, is_leaf,
+ offsets1 = rec_get_offsets(cur1_rec, index, offsets1, n_core,
ULINT_UNDEFINED, &heap);
ins_rec = page_cur_insert_rec_low(&page_cur, index,
@@ -1439,7 +1446,8 @@ rtr_page_copy_rec_list_start_no_locks(
rec_offs* offsets2 = offsets_2;
page_cur_t page_cur;
ulint moved = 0;
- bool is_leaf = page_is_leaf(buf_block_get_frame(block));
+ const ulint n_core = page_is_leaf(buf_block_get_frame(block))
+ ? index->n_core_fields : 0;
rec_offs_init(offsets_1);
rec_offs_init(offsets_2);
@@ -1459,14 +1467,14 @@ rtr_page_copy_rec_list_start_no_locks(
cur_rec = page_rec_get_next(cur_rec);
}
- offsets1 = rec_get_offsets(cur1_rec, index, offsets1, is_leaf,
+ offsets1 = rec_get_offsets(cur1_rec, index, offsets1, n_core,
ULINT_UNDEFINED, &heap);
while (!page_rec_is_supremum(cur_rec)) {
ulint cur_matched_fields = 0;
offsets2 = rec_get_offsets(cur_rec, index, offsets2,
- is_leaf,
+ n_core,
ULINT_UNDEFINED, &heap);
int cmp = cmp_rec_rec(cur1_rec, cur_rec,
offsets1, offsets2, index, false,
@@ -1479,7 +1487,7 @@ rtr_page_copy_rec_list_start_no_locks(
/* Skip small recs. */
page_cur_move_to_next(&page_cur);
cur_rec = page_cur_get_rec(&page_cur);
- } else if (is_leaf) {
+ } else if (n_core) {
if (rec_get_deleted_flag(
cur1_rec,
dict_table_is_comp(index->table))) {
@@ -1503,7 +1511,7 @@ rtr_page_copy_rec_list_start_no_locks(
cur_rec = page_cur_get_rec(&page_cur);
- offsets1 = rec_get_offsets(cur1_rec, index, offsets1, is_leaf,
+ offsets1 = rec_get_offsets(cur1_rec, index, offsets1, n_core,
ULINT_UNDEFINED, &heap);
ins_rec = page_cur_insert_rec_low(&page_cur, index,
@@ -1654,7 +1662,7 @@ rtr_check_same_block(
while (!page_rec_is_supremum(rec)) {
offsets = rec_get_offsets(
- rec, index, NULL, false, ULINT_UNDEFINED, &heap);
+ rec, index, NULL, 0, ULINT_UNDEFINED, &heap);
if (btr_node_ptr_get_child_page_no(rec, offsets) == page_no) {
btr_cur_position(index, rec, parentb, cursor);
diff --git a/storage/innobase/gis/gis0sea.cc b/storage/innobase/gis/gis0sea.cc
index 1d882d48aa9..f067d43d6a3 100644
--- a/storage/innobase/gis/gis0sea.cc
+++ b/storage/innobase/gis/gis0sea.cc
@@ -520,8 +520,7 @@ rtr_compare_cursor_rec(
rec = btr_cur_get_rec(cursor);
- offsets = rec_get_offsets(
- rec, index, NULL, false, ULINT_UNDEFINED, heap);
+ offsets = rec_get_offsets(rec, index, NULL, 0, ULINT_UNDEFINED, heap);
return(btr_node_ptr_get_child_page_no(rec, offsets) == page_no);
}
@@ -801,7 +800,8 @@ rtr_page_get_father_node_ptr(
user_rec = btr_cur_get_rec(cursor);
ut_a(page_rec_is_user_rec(user_rec));
- offsets = rec_get_offsets(user_rec, index, offsets, !level,
+ offsets = rec_get_offsets(user_rec, index, offsets,
+ level ? 0 : index->n_fields,
ULINT_UNDEFINED, &heap);
rtr_get_mbr_from_rec(user_rec, offsets, &mbr);
@@ -818,7 +818,7 @@ rtr_page_get_father_node_ptr(
node_ptr = btr_cur_get_rec(cursor);
ut_ad(!page_rec_is_comp(node_ptr)
|| rec_get_status(node_ptr) == REC_STATUS_NODE_PTR);
- offsets = rec_get_offsets(node_ptr, index, offsets, false,
+ offsets = rec_get_offsets(node_ptr, index, offsets, 0,
ULINT_UNDEFINED, &heap);
ulint child_page = btr_node_ptr_get_child_page_no(node_ptr, offsets);
@@ -836,13 +836,14 @@ rtr_page_get_father_node_ptr(
print_rec = page_rec_get_next(
page_get_infimum_rec(page_align(user_rec)));
offsets = rec_get_offsets(print_rec, index, offsets,
- page_rec_is_leaf(user_rec),
+ page_rec_is_leaf(user_rec)
+ ? index->n_fields : 0,
ULINT_UNDEFINED, &heap);
error << "; child ";
rec_print(error.m_oss, print_rec,
rec_get_info_bits(print_rec, rec_offs_comp(offsets)),
offsets);
- offsets = rec_get_offsets(node_ptr, index, offsets, false,
+ offsets = rec_get_offsets(node_ptr, index, offsets, 0,
ULINT_UNDEFINED, &heap);
error << "; parent ";
rec_print(error.m_oss, print_rec,
@@ -1266,10 +1267,12 @@ rtr_cur_restore_position(
heap = mem_heap_create(256);
offsets1 = rec_get_offsets(
- r_cursor->old_rec, index, NULL, !level,
+ r_cursor->old_rec, index, NULL,
+ level ? 0 : r_cursor->old_n_fields,
r_cursor->old_n_fields, &heap);
offsets2 = rec_get_offsets(
- rec, index, NULL, !level,
+ rec, index, NULL,
+ level ? 0 : r_cursor->old_n_fields,
r_cursor->old_n_fields, &heap);
comp = rec_offs_comp(offsets1);
@@ -1333,12 +1336,12 @@ search_again:
rec = btr_pcur_get_rec(r_cursor);
- offsets1 = rec_get_offsets(
- r_cursor->old_rec, index, NULL, !level,
- r_cursor->old_n_fields, &heap);
- offsets2 = rec_get_offsets(
- rec, index, NULL, !level,
- r_cursor->old_n_fields, &heap);
+ offsets1 = rec_get_offsets(r_cursor->old_rec, index, NULL,
+ level ? 0 : r_cursor->old_n_fields,
+ r_cursor->old_n_fields, &heap);
+ offsets2 = rec_get_offsets(rec, index, NULL,
+ level ? 0 : r_cursor->old_n_fields,
+ r_cursor->old_n_fields, &heap);
comp = rec_offs_comp(offsets1);
@@ -1674,7 +1677,7 @@ rtr_cur_search_with_match(
page = buf_block_get_frame(block);
const ulint level = btr_page_get_level(page);
- const bool is_leaf = !level;
+ const ulint n_core = level ? 0 : index->n_fields;
if (mode == PAGE_CUR_RTREE_LOCATE) {
ut_ad(level != 0);
@@ -1696,7 +1699,7 @@ rtr_cur_search_with_match(
ulint new_rec_size = rec_get_converted_size(index, tuple, 0);
- offsets = rec_get_offsets(rec, index, offsets, is_leaf,
+ offsets = rec_get_offsets(rec, index, offsets, n_core,
dtuple_get_n_fields_cmp(tuple),
&heap);
@@ -1717,7 +1720,7 @@ rtr_cur_search_with_match(
}
while (!page_rec_is_supremum(rec)) {
- if (!is_leaf) {
+ if (!n_core) {
switch (mode) {
case PAGE_CUR_CONTAIN:
case PAGE_CUR_INTERSECT:
@@ -1798,7 +1801,7 @@ rtr_cur_search_with_match(
to rtr_info->path for non-leaf nodes, or
rtr_info->matches for leaf nodes */
if (rtr_info && mode != PAGE_CUR_RTREE_INSERT) {
- if (!is_leaf) {
+ if (!n_core) {
uint32_t page_no;
node_seq_t new_seq;
bool is_loc;
@@ -1809,7 +1812,7 @@ rtr_cur_search_with_match(
== PAGE_CUR_RTREE_GET_FATHER);
offsets = rec_get_offsets(
- rec, index, offsets, false,
+ rec, index, offsets, 0,
ULINT_UNDEFINED, &heap);
page_no = btr_node_ptr_get_child_page_no(
@@ -1862,7 +1865,8 @@ rtr_cur_search_with_match(
/* Collect matched records on page */
offsets = rec_get_offsets(
- rec, index, offsets, true,
+ rec, index, offsets,
+ index->n_fields,
ULINT_UNDEFINED, &heap);
rtr_leaf_push_match_rec(
rec, rtr_info, offsets,
@@ -1885,7 +1889,7 @@ rtr_cur_search_with_match(
/* All records on page are searched */
if (page_rec_is_supremum(rec)) {
- if (!is_leaf) {
+ if (!n_core) {
if (!found) {
/* No match case, if it is for insertion,
then we select the record that result in
@@ -1894,7 +1898,7 @@ rtr_cur_search_with_match(
ut_ad(least_inc < DBL_MAX);
offsets = rec_get_offsets(
best_rec, index, offsets,
- false, ULINT_UNDEFINED, &heap);
+ 0, ULINT_UNDEFINED, &heap);
uint32_t child_no =
btr_node_ptr_get_child_page_no(
best_rec, offsets);
@@ -1946,11 +1950,11 @@ rtr_cur_search_with_match(
/* Verify the record to be positioned is the same
as the last record in matched_rec vector */
offsets2 = rec_get_offsets(test_rec.r_rec, index,
- offsets2, true,
+ offsets2, index->n_fields,
ULINT_UNDEFINED, &heap);
offsets = rec_get_offsets(last_match_rec, index,
- offsets, true,
+ offsets, index->n_fields,
ULINT_UNDEFINED, &heap);
ut_ad(cmp_rec_rec(test_rec.r_rec, last_match_rec,
@@ -1970,7 +1974,7 @@ rtr_cur_search_with_match(
mach_read_from_4(rec + DATA_MBR_LEN),
block, rec, 0);
- } else if (rtr_info && found && !is_leaf) {
+ } else if (rtr_info && found && !n_core) {
rec = last_match_rec;
}
@@ -1980,11 +1984,11 @@ rtr_cur_search_with_match(
#ifdef UNIV_DEBUG
/* Verify that we are positioned at the same child page as pushed in
the path stack */
- if (!is_leaf && (!page_rec_is_supremum(rec) || found)
+ if (!n_core && (!page_rec_is_supremum(rec) || found)
&& mode != PAGE_CUR_RTREE_INSERT) {
ulint page_no;
- offsets = rec_get_offsets(rec, index, offsets, false,
+ offsets = rec_get_offsets(rec, index, offsets, 0,
ULINT_UNDEFINED, &heap);
page_no = btr_node_ptr_get_child_page_no(rec, offsets);
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 7ffbe3fe374..b9f5984f3f4 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -8036,26 +8036,24 @@ wsrep_calc_row_hash(
dictionary */
row_prebuilt_t* prebuilt) /*!< in: InnoDB prebuilt struct */
{
- ulint len;
- const byte* ptr;
-
void *ctx = alloca(my_md5_context_size());
my_md5_init(ctx);
for (uint i = 0; i < table->s->fields; i++) {
byte null_byte=0;
byte true_byte=1;
+ unsigned is_unsigned;
const Field* field = table->field[i];
if (!field->stored_in_db()) {
continue;
}
- ptr = (const byte*) row + get_field_offset(table, field);
- len = field->pack_length();
-
- switch (prebuilt->table->cols[i].mtype) {
+ auto ptr = row + get_field_offset(table, field);
+ ulint len = field->pack_length();
+ switch (get_innobase_type_from_mysql_type(&is_unsigned,
+ field)) {
case DATA_BLOB:
ptr = row_mysql_read_blob_ref(&len, ptr, len);
diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
index 58e17cd3ead..298f8347053 100644
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@ -1023,13 +1023,6 @@ struct ha_innobase_inplace_ctx : public inplace_alter_handler_ctx
@return whether the table will be rebuilt */
bool need_rebuild () const { return(old_table != new_table); }
- /** Clear uncommmitted added indexes after a failed operation. */
- void clear_added_indexes()
- {
- for (ulint i= 0; i < num_to_add_index; i++)
- add_index[i]->detach_columns(true);
- }
-
/** Convert table-rebuilding ALTER to instant ALTER. */
void prepare_instant()
{
@@ -1127,6 +1120,42 @@ struct ha_innobase_inplace_ctx : public inplace_alter_handler_ctx
}
}
+ /** @return whether the given column is being added */
+ bool is_new_vcol(const dict_v_col_t &v_col) const
+ {
+ for (ulint i= 0; i < num_to_add_vcol; i++)
+ if (&add_vcol[i] == &v_col)
+ return true;
+ return false;
+ }
+
+ /** During rollback, make newly added indexes point to
+ newly added virtual columns. */
+ void clean_new_vcol_index()
+ {
+ ut_ad(old_table == new_table);
+ const dict_index_t *index= dict_table_get_first_index(old_table);
+ while ((index= dict_table_get_next_index(index)) != NULL)
+ {
+ if (!index->has_virtual() || index->is_committed())
+ continue;
+ ulint n_drop_new_vcol= index->get_new_n_vcol();
+ for (ulint i= 0; n_drop_new_vcol && i < index->n_fields; i++)
+ {
+ dict_col_t *col= index->fields[i].col;
+ /* Skip the non-virtual and old virtual columns */
+ if (!col->is_virtual())
+ continue;
+ dict_v_col_t *vcol= reinterpret_cast<dict_v_col_t*>(col);
+ if (!is_new_vcol(*vcol))
+ continue;
+
+ index->fields[i].col= &index->new_vcol_info->
+ add_drop_v_col(index->heap, vcol, --n_drop_new_vcol)->m_col;
+ }
+ }
+ }
+
private:
// Disable copying
ha_innobase_inplace_ctx(const ha_innobase_inplace_ctx&);
@@ -3731,9 +3760,11 @@ innobase_fts_check_doc_id_index(
for (index = dict_table_get_first_index(table);
index; index = dict_table_get_next_index(index)) {
+
/* Check if there exists a unique index with the name of
- FTS_DOC_ID_INDEX_NAME */
- if (innobase_strcasecmp(index->name, FTS_DOC_ID_INDEX_NAME)) {
+ FTS_DOC_ID_INDEX_NAME and ignore the corrupted index */
+ if (index->type & DICT_CORRUPT
+ || innobase_strcasecmp(index->name, FTS_DOC_ID_INDEX_NAME)) {
continue;
}
@@ -4041,7 +4072,7 @@ online_retry_drop_indexes_low(
ut_ad(table->get_ref_count() >= 1);
if (table->drop_aborted) {
- row_merge_drop_indexes(trx, table, TRUE);
+ row_merge_drop_indexes(trx, table, true);
}
}
@@ -5901,7 +5932,7 @@ add_all_virtual:
offsets = rec_get_offsets(
btr_pcur_get_rec(&pcur), index, offsets,
- true, ULINT_UNDEFINED, &offsets_heap);
+ index->n_core_fields, ULINT_UNDEFINED, &offsets_heap);
if (big_rec) {
if (err == DB_SUCCESS) {
err = btr_store_big_rec_extern_fields(
@@ -6812,7 +6843,7 @@ new_table_failed:
for (ulint a = 0; a < ctx->num_to_add_index; a++) {
dict_index_t* index = ctx->add_index[a];
- const bool has_new_v_col = index->has_new_v_col;
+ const ulint n_v_col = index->get_new_n_vcol();
index = create_index_dict(ctx->trx, index, add_v);
error = ctx->trx->error_state;
if (error != DB_SUCCESS) {
@@ -6842,7 +6873,9 @@ error_handling_drop_uncached_1:
goto error_handling_drop_uncached_1;
}
index->parser = index_defs[a].parser;
- index->has_new_v_col = has_new_v_col;
+ if (n_v_col) {
+ index->assign_new_v_col(n_v_col);
+ }
/* Note the id of the transaction that created this
index, we use it to restrict readers from accessing
this index, to ensure read consistency. */
@@ -6913,7 +6946,7 @@ error_handling_drop_uncached_1:
for (ulint a = 0; a < ctx->num_to_add_index; a++) {
dict_index_t* index = ctx->add_index[a];
- const bool has_new_v_col = index->has_new_v_col;
+ const ulint n_v_col = index->get_new_n_vcol();
DBUG_EXECUTE_IF(
"create_index_metadata_fail",
if (a + 1 == ctx->num_to_add_index) {
@@ -6945,7 +6978,9 @@ error_handling_drop_uncached:
}
index->parser = index_defs[a].parser;
- index->has_new_v_col = has_new_v_col;
+ if (n_v_col) {
+ index->assign_new_v_col(n_v_col);
+ }
/* Note the id of the transaction that created this
index, we use it to restrict readers from accessing
this index, to ensure read consistency. */
@@ -7172,7 +7207,7 @@ error_handled:
online_retry_drop_indexes_with_trx(user_table, ctx->trx);
} else {
ut_ad(!ctx->need_rebuild());
- row_merge_drop_indexes(ctx->trx, user_table, TRUE);
+ row_merge_drop_indexes(ctx->trx, user_table, true);
trx_commit_for_mysql(ctx->trx);
}
@@ -8532,7 +8567,6 @@ oom:
that we hold at most a shared lock on the table. */
m_prebuilt->trx->error_info = NULL;
ctx->trx->error_state = DB_SUCCESS;
- ctx->clear_added_indexes();
DBUG_RETURN(true);
}
@@ -8624,17 +8658,18 @@ temparary index prefix
@param table the TABLE
@param locked TRUE=table locked, FALSE=may need to do a lazy drop
@param trx the transaction
-*/
-static MY_ATTRIBUTE((nonnull))
+@param alter_trx transaction which takes S-lock on the table
+ while creating the index */
+static
void
innobase_rollback_sec_index(
-/*========================*/
- dict_table_t* user_table,
- const TABLE* table,
- ibool locked,
- trx_t* trx)
+ dict_table_t* user_table,
+ const TABLE* table,
+ bool locked,
+ trx_t* trx,
+ const trx_t* alter_trx=NULL)
{
- row_merge_drop_indexes(trx, user_table, locked);
+ row_merge_drop_indexes(trx, user_table, locked, alter_trx);
/* Free the table->fts only if there is no FTS_DOC_ID
in the table */
@@ -8762,7 +8797,12 @@ rollback_inplace_alter_table(
}
innobase_rollback_sec_index(
- prebuilt->table, table, FALSE, ctx->trx);
+ prebuilt->table, table,
+ (ha_alter_info->alter_info->requested_lock
+ == Alter_info::ALTER_TABLE_LOCK_EXCLUSIVE),
+ ctx->trx, prebuilt->trx);
+
+ ctx->clean_new_vcol_index();
}
trx_commit_for_mysql(ctx->trx);
diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc
index d28aca23de1..d357011bf22 100644
--- a/storage/innobase/ibuf/ibuf0ibuf.cc
+++ b/storage/innobase/ibuf/ibuf0ibuf.cc
@@ -3722,7 +3722,7 @@ dump:
row_ins_sec_index_entry_by_modify(BTR_MODIFY_LEAF). */
ut_ad(rec_get_deleted_flag(rec, page_is_comp(page)));
- offsets = rec_get_offsets(rec, index, NULL, true,
+ offsets = rec_get_offsets(rec, index, NULL, index->n_fields,
ULINT_UNDEFINED, &heap);
update = row_upd_build_sec_rec_difference_binary(
rec, index, offsets, entry, heap);
@@ -3882,7 +3882,8 @@ ibuf_delete(
ut_ad(ibuf_inside(mtr));
ut_ad(dtuple_check_typed(entry));
- ut_ad(!dict_index_is_spatial(index));
+ ut_ad(!index->is_spatial());
+ ut_ad(!index->is_clust());
low_match = page_cur_search(block, index, entry, &page_cur);
@@ -3901,8 +3902,8 @@ ibuf_delete(
rec_offs_init(offsets_);
- offsets = rec_get_offsets(
- rec, index, offsets, true, ULINT_UNDEFINED, &heap);
+ offsets = rec_get_offsets(rec, index, offsets, index->n_fields,
+ ULINT_UNDEFINED, &heap);
if (page_get_n_recs(page) <= 1
|| !(REC_INFO_DELETED_FLAG
diff --git a/storage/innobase/include/btr0bulk.h b/storage/innobase/include/btr0bulk.h
index 375b7b34fe4..943836f8759 100644
--- a/storage/innobase/include/btr0bulk.h
+++ b/storage/innobase/include/btr0bulk.h
@@ -314,6 +314,8 @@ public:
/** Re-latch all latches */
void latch();
+ table_name_t table_name() { return m_index->table->name; }
+
private:
/** Insert a tuple to a page in a level
@param[in] tuple tuple to insert
diff --git a/storage/innobase/include/btr0pcur.h b/storage/innobase/include/btr0pcur.h
index 745a2c969fc..312e51971bb 100644
--- a/storage/innobase/include/btr0pcur.h
+++ b/storage/innobase/include/btr0pcur.h
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2020, MariaDB Corporation.
+Copyright (c) 2017, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -477,8 +477,10 @@ struct btr_pcur_t{
/** if cursor position is stored, contains an initial segment of the
latest record cursor was positioned either on, before or after */
rec_t* old_rec;
+ /** btr_cur.index->n_core_fields when old_rec was copied */
+ uint16 old_n_core_fields;
/** number of fields in old_rec */
- ulint old_n_fields;
+ uint16 old_n_fields;
/** BTR_PCUR_ON, BTR_PCUR_BEFORE, or BTR_PCUR_AFTER, depending on
whether cursor was on, before, or after the old_rec record */
enum btr_pcur_pos_t rel_pos;
diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h
index 43d55b765ee..a7f04c3015e 100644
--- a/storage/innobase/include/dict0mem.h
+++ b/storage/innobase/include/dict0mem.h
@@ -790,6 +790,35 @@ struct dict_v_col_t{
}
};
+/** Data structure for newly added virtual column in a index.
+It is used only during rollback_inplace_alter_table() of
+addition of index depending on newly added virtual columns
+and uses index heap. Should be freed when index is being
+removed from cache. */
+struct dict_add_v_col_info
+{
+ ulint n_v_col;
+ dict_v_col_t *v_col;
+
+ /** Add the newly added virtual column while rollbacking
+ the index which contains new virtual columns
+ @param col virtual column to be duplicated
+ @param offset offset where to duplicate virtual column */
+ dict_v_col_t* add_drop_v_col(mem_heap_t *heap, dict_v_col_t *col,
+ ulint offset)
+ {
+ ut_ad(n_v_col);
+ ut_ad(offset < n_v_col);
+ if (!v_col)
+ v_col= static_cast<dict_v_col_t*>
+ (mem_heap_alloc(heap, n_v_col * sizeof *v_col));
+ new (&v_col[offset]) dict_v_col_t();
+ v_col[offset].m_col= col->m_col;
+ v_col[offset].v_pos= col->v_pos;
+ return &v_col[offset];
+ }
+};
+
/** Data structure for newly added virtual column in a table */
struct dict_add_v_col_t{
/** number of new virtual column */
@@ -1037,9 +1066,12 @@ struct dict_index_t {
dict_field_t* fields; /*!< array of field descriptions */
st_mysql_ftparser*
parser; /*!< fulltext parser plugin */
- bool has_new_v_col;
- /*!< whether it has a newly added virtual
- column in ALTER */
+
+ /** It just indicates whether newly added virtual column
+ during alter. It stores column in case of alter failure.
+ It should use heap from dict_index_t. It should be freed
+ while removing the index from table. */
+ dict_add_v_col_info* new_vcol_info;
UT_LIST_NODE_T(dict_index_t)
indexes;/*!< list of indexes of the table */
#ifdef BTR_CUR_ADAPT
@@ -1199,9 +1231,8 @@ public:
/** @return whether the index is corrupted */
inline bool is_corrupted() const;
- /** Detach the virtual columns from the index that is to be removed.
- @param whether to reset fields[].col */
- void detach_columns(bool clear= false)
+ /** Detach the virtual columns from the index that is to be removed. */
+ void detach_columns()
{
if (!has_virtual() || !cached)
return;
@@ -1211,8 +1242,6 @@ public:
if (!col || !col->is_virtual())
continue;
col->detach(*this);
- if (clear)
- fields[i].col= nullptr;
}
}
@@ -1275,6 +1304,23 @@ public:
bool
vers_history_row(const rec_t* rec, bool &history_row);
+ /** Assign the number of new column to be added as a part
+ of the index
+ @param n_vcol number of virtual columns to be added */
+ void assign_new_v_col(ulint n_vcol)
+ {
+ new_vcol_info= static_cast<dict_add_v_col_info*>
+ (mem_heap_zalloc(heap, sizeof *new_vcol_info));
+ new_vcol_info->n_v_col= n_vcol;
+ }
+
+ /* @return whether index has new virtual column */
+ bool has_new_v_col() const { return new_vcol_info; }
+
+ /* @return number of newly added virtual column */
+ ulint get_new_n_vcol() const
+ { return new_vcol_info ? new_vcol_info->n_v_col : 0; }
+
/** Reconstruct the clustered index fields. */
inline void reconstruct_fields();
@@ -2385,6 +2431,17 @@ public:
/** mysql_row_templ_t for base columns used for compute the virtual
columns */
dict_vcol_templ_t* vc_templ;
+
+ /* @return whether the table has any other transcation lock
+ other than the given transaction */
+ bool has_lock_other_than(const trx_t *trx) const
+ {
+ for (lock_t *lock= UT_LIST_GET_FIRST(locks); lock;
+ lock= UT_LIST_GET_NEXT(un_member.tab_lock.locks, lock))
+ if (lock->trx != trx)
+ return true;
+ return false;
+ }
};
inline void dict_index_t::set_modified(mtr_t& mtr) const
diff --git a/storage/innobase/include/gis0rtree.ic b/storage/innobase/include/gis0rtree.ic
index cb47c12da80..2564df7e0d6 100644
--- a/storage/innobase/include/gis0rtree.ic
+++ b/storage/innobase/include/gis0rtree.ic
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2014, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2020, MariaDB Corporation.
+Copyright (c) 2017, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -57,7 +57,8 @@ rtr_page_cal_mbr(
page = buf_block_get_frame(block);
rec = page_rec_get_next(page_get_infimum_rec(page));
- offsets = rec_get_offsets(rec, index, offsets, page_is_leaf(page),
+ offsets = rec_get_offsets(rec, index, offsets, page_is_leaf(page)
+ ? index->n_fields : 0,
ULINT_UNDEFINED, &heap);
do {
diff --git a/storage/innobase/include/page0cur.ic b/storage/innobase/include/page0cur.ic
index e8f7afcaf01..828be6840d2 100644
--- a/storage/innobase/include/page0cur.ic
+++ b/storage/innobase/include/page0cur.ic
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1994, 2014, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2015, 2020, MariaDB Corporation.
+Copyright (c) 2015, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -273,7 +273,8 @@ page_cur_tuple_insert(
index, tuple, n_ext);
*offsets = rec_get_offsets(rec, index, *offsets,
- page_is_leaf(cursor->block->frame),
+ page_is_leaf(cursor->block->frame)
+ ? index->n_core_fields : 0,
ULINT_UNDEFINED, heap);
ut_ad(size == rec_offs_size(*offsets));
diff --git a/storage/innobase/include/rem0rec.h b/storage/innobase/include/rem0rec.h
index cda0d38ba44..dbcff3e6fd6 100644
--- a/storage/innobase/include/rem0rec.h
+++ b/storage/innobase/include/rem0rec.h
@@ -466,7 +466,7 @@ rec_get_n_extern_new(
@param[in] index the index that the record belongs to
@param[in,out] offsets array comprising offsets[0] allocated elements,
or an array from rec_get_offsets(), or NULL
-@param[in] leaf whether this is a leaf-page record
+@param[in] n_core 0, or index->n_core_fields for leaf page
@param[in] n_fields maximum number of offsets to compute
(ULINT_UNDEFINED to compute all offsets)
@param[in,out] heap memory heap
@@ -476,7 +476,7 @@ rec_get_offsets_func(
const rec_t* rec,
const dict_index_t* index,
rec_offs* offsets,
- bool leaf,
+ ulint n_core,
ulint n_fields,
#ifdef UNIV_DEBUG
const char* file, /*!< in: file name where called */
@@ -1082,7 +1082,9 @@ rec_get_converted_size(
The fields are copied into the memory heap.
@param[out] tuple data tuple
@param[in] rec index record, or a copy thereof
-@param[in] is_leaf whether rec is a leaf page record
+@param[in] index index of rec
+@param[in] n_core index->n_core_fields at the time rec was
+ copied, or 0 if non-leaf page record
@param[in] n_fields number of fields to copy
@param[in,out] heap memory heap */
void
@@ -1090,7 +1092,7 @@ rec_copy_prefix_to_dtuple(
dtuple_t* tuple,
const rec_t* rec,
const dict_index_t* index,
- bool is_leaf,
+ ulint n_core,
ulint n_fields,
mem_heap_t* heap)
MY_ATTRIBUTE((nonnull));
diff --git a/storage/innobase/include/row0merge.h b/storage/innobase/include/row0merge.h
index d9410298c01..1d7f9bb145b 100644
--- a/storage/innobase/include/row0merge.h
+++ b/storage/innobase/include/row0merge.h
@@ -167,18 +167,20 @@ row_merge_drop_indexes_dict(
table_id_t table_id)/*!< in: table identifier */
MY_ATTRIBUTE((nonnull));
-/*********************************************************************//**
-Drop those indexes which were created before an error occurred.
+/** Drop indexes that were created before an error occurred.
The data dictionary must have been locked exclusively by the caller,
-because the transaction will not be committed. */
+because the transaction will not be committed.
+@param trx dictionary transaction
+@param table table containing the indexes
+@param locked True if table is locked,
+ false - may need to do lazy drop
+@param alter_trx Alter table transaction */
void
row_merge_drop_indexes(
-/*===================*/
- trx_t* trx, /*!< in/out: transaction */
- dict_table_t* table, /*!< in/out: table containing the indexes */
- ibool locked) /*!< in: TRUE=table locked,
- FALSE=may need to do a lazy drop */
- MY_ATTRIBUTE((nonnull));
+ trx_t* trx,
+ dict_table_t* table,
+ bool locked,
+ const trx_t* alter_trx=NULL);
/*********************************************************************//**
Drop all partially created indexes during crash recovery. */
diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc
index 62582e61b0b..5a047635577 100644
--- a/storage/innobase/lock/lock0lock.cc
+++ b/storage/innobase/lock/lock0lock.cc
@@ -3989,7 +3989,8 @@ static void lock_rec_print(FILE* file, const lock_t* lock, mtr_t& mtr)
ut_ad(!page_rec_is_metadata(rec));
offsets = rec_get_offsets(
- rec, lock->index, offsets, true,
+ rec, lock->index, offsets,
+ lock->index->n_core_fields,
ULINT_UNDEFINED, &heap);
putc(' ', file);
@@ -4497,8 +4498,8 @@ loop:
ut_ad(!lock_rec_get_nth_bit(lock, i)
|| page_rec_is_leaf(rec));
offsets = rec_get_offsets(rec, lock->index, offsets,
- true, ULINT_UNDEFINED,
- &heap);
+ lock->index->n_core_fields,
+ ULINT_UNDEFINED, &heap);
/* If this thread is holding the file space
latch (fil_space_t::latch), the following
@@ -4746,7 +4747,7 @@ lock_rec_insert_check_and_lock(
const rec_offs *offsets;
rec_offs_init(offsets_);
- offsets= rec_get_offsets(next_rec, index, offsets_, true,
+ offsets= rec_get_offsets(next_rec, index, offsets_, index->n_core_fields,
ULINT_UNDEFINED, &heap);
ut_ad(lock_rec_queue_validate(false, id, next_rec, index, offsets));
@@ -5072,7 +5073,8 @@ lock_sec_rec_modify_check_and_lock(
const rec_offs* offsets;
rec_offs_init(offsets_);
- offsets = rec_get_offsets(rec, index, offsets_, true,
+ offsets = rec_get_offsets(rec, index, offsets_,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
ut_ad(lock_rec_queue_validate(
@@ -5288,7 +5290,7 @@ lock_clust_rec_read_check_and_lock_alt(
rec_offs_init(offsets_);
ut_ad(page_rec_is_leaf(rec));
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
ULINT_UNDEFINED, &tmp_heap);
err = lock_clust_rec_read_check_and_lock(flags, block, rec, index,
offsets, mode, gap_mode, thr);
diff --git a/storage/innobase/page/page0cur.cc b/storage/innobase/page/page0cur.cc
index 5e751010f44..025d4b9b967 100644
--- a/storage/innobase/page/page0cur.cc
+++ b/storage/innobase/page/page0cur.cc
@@ -75,7 +75,7 @@ page_cur_try_search_shortcut(
ut_ad(page_is_leaf(page));
rec = page_header_get_ptr(page, PAGE_LAST_INSERT);
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
dtuple_get_n_fields(tuple), &heap);
ut_ad(rec);
@@ -90,7 +90,8 @@ page_cur_try_search_shortcut(
next_rec = page_rec_get_next_const(rec);
if (!page_rec_is_supremum(next_rec)) {
- offsets = rec_get_offsets(next_rec, index, offsets, true,
+ offsets = rec_get_offsets(next_rec, index, offsets,
+ index->n_core_fields,
dtuple_get_n_fields(tuple), &heap);
if (cmp_dtuple_rec_with_match(tuple, next_rec, offsets,
@@ -159,7 +160,7 @@ page_cur_try_search_shortcut_bytes(
ut_ad(page_is_leaf(page));
rec = page_header_get_ptr(page, PAGE_LAST_INSERT);
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
dtuple_get_n_fields(tuple), &heap);
ut_ad(rec);
@@ -180,7 +181,8 @@ page_cur_try_search_shortcut_bytes(
next_rec = page_rec_get_next_const(rec);
if (!page_rec_is_supremum(next_rec)) {
- offsets = rec_get_offsets(next_rec, index, offsets, true,
+ offsets = rec_get_offsets(next_rec, index, offsets,
+ index->n_core_fields,
dtuple_get_n_fields(tuple), &heap);
if (cmp_dtuple_rec_with_match_bytes(
@@ -321,14 +323,14 @@ page_cur_search_with_match(
#endif /* UNIV_ZIP_DEBUG */
ut_d(page_check_dir(page));
- const bool is_leaf = page_is_leaf(page);
+ const ulint n_core = page_is_leaf(page) ? index->n_core_fields : 0;
#ifdef BTR_CUR_HASH_ADAPT
- if (is_leaf
+ if (n_core
&& page_get_direction(page) == PAGE_RIGHT
&& page_header_get_offs(page, PAGE_LAST_INSERT)
&& mode == PAGE_CUR_LE
- && !dict_index_is_spatial(index)
+ && !index->is_spatial()
&& page_header_get_field(page, PAGE_N_DIRECTION) > 3
&& page_cur_try_search_shortcut(
block, index, tuple,
@@ -344,10 +346,10 @@ page_cur_search_with_match(
/* If the mode is for R-tree indexes, use the special MBR
related compare functions */
- if (dict_index_is_spatial(index) && mode > PAGE_CUR_LE) {
+ if (index->is_spatial() && mode > PAGE_CUR_LE) {
/* For leaf level insert, we still use the traditional
compare function for now */
- if (mode == PAGE_CUR_RTREE_INSERT && is_leaf) {
+ if (mode == PAGE_CUR_RTREE_INSERT && n_core) {
mode = PAGE_CUR_LE;
} else {
rtr_cur_search_with_match(
@@ -392,7 +394,7 @@ page_cur_search_with_match(
offsets = offsets_;
offsets = rec_get_offsets(
- mid_rec, index, offsets, is_leaf,
+ mid_rec, index, offsets, n_core,
dtuple_get_n_fields_cmp(tuple), &heap);
cmp = cmp_dtuple_rec_with_match(
@@ -446,7 +448,7 @@ up_slot_match:
offsets = offsets_;
offsets = rec_get_offsets(
- mid_rec, index, offsets, is_leaf,
+ mid_rec, index, offsets, n_core,
dtuple_get_n_fields_cmp(tuple), &heap);
cmp = cmp_dtuple_rec_with_match(
@@ -627,7 +629,7 @@ page_cur_search_with_match_bytes(
/* Perform binary search until the lower and upper limit directory
slots come to the distance 1 of each other */
- const bool is_leaf = page_is_leaf(page);
+ const ulint n_core = page_is_leaf(page) ? index->n_core_fields : 0;
while (up - low > 1) {
mid = (low + up) / 2;
@@ -639,7 +641,7 @@ page_cur_search_with_match_bytes(
up_matched_fields, up_matched_bytes);
offsets = rec_get_offsets(
- mid_rec, index, offsets_, is_leaf,
+ mid_rec, index, offsets_, n_core,
dtuple_get_n_fields_cmp(tuple), &heap);
cmp = cmp_dtuple_rec_with_match_bytes(
@@ -707,7 +709,7 @@ up_slot_match:
}
offsets = rec_get_offsets(
- mid_rec, index, offsets_, is_leaf,
+ mid_rec, index, offsets_, n_core,
dtuple_get_n_fields_cmp(tuple), &heap);
cmp = cmp_dtuple_rec_with_match_bytes(
@@ -1343,7 +1345,8 @@ page_cur_insert_rec_low(
rec_offs_init(foffsets_);
rec_offs *foffsets= rec_get_offsets(free_rec, index, foffsets_,
- page_is_leaf(block->frame),
+ page_is_leaf(block->frame)
+ ? index->n_core_fields : 0,
ULINT_UNDEFINED, &heap);
const ulint fextra_size= rec_offs_extra_size(foffsets);
insert_buf= free_rec - fextra_size;
@@ -1838,7 +1841,8 @@ page_cur_insert_rec_zip(
rec_offs *foffsets= rec_get_offsets(cursor->block->frame + free_rec, index,
foffsets_,
- page_is_leaf(cursor->block->frame),
+ page_is_leaf(cursor->block->frame)
+ ? index->n_core_fields : 0,
ULINT_UNDEFINED, &heap);
insert_buf= cursor->block->frame + free_rec -
rec_offs_extra_size(foffsets);
diff --git a/storage/innobase/page/page0page.cc b/storage/innobase/page/page0page.cc
index 5fe029d5b4d..9b83470e65c 100644
--- a/storage/innobase/page/page0page.cc
+++ b/storage/innobase/page/page0page.cc
@@ -2,7 +2,7 @@
Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc.
-Copyright (c) 2017, 2020, MariaDB Corporation.
+Copyright (c) 2017, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -482,7 +482,8 @@ page_copy_rec_list_end_no_locks(
ut_a(page_is_comp(new_page) == page_rec_is_comp(rec));
ut_a(mach_read_from_2(new_page + srv_page_size - 10) == (ulint)
(page_is_comp(new_page) ? PAGE_NEW_INFIMUM : PAGE_OLD_INFIMUM));
- const bool is_leaf = page_is_leaf(block->frame);
+ const ulint n_core = page_is_leaf(block->frame)
+ ? index->n_core_fields : 0;
page_cur_set_before_first(new_block, &cur2);
@@ -490,7 +491,7 @@ page_copy_rec_list_end_no_locks(
while (!page_cur_is_after_last(&cur1)) {
rec_t* ins_rec;
- offsets = rec_get_offsets(cur1.rec, index, offsets, is_leaf,
+ offsets = rec_get_offsets(cur1.rec, index, offsets, n_core,
ULINT_UNDEFINED, &heap);
ins_rec = page_cur_insert_rec_low(&cur2, index,
cur1.rec, offsets, mtr);
@@ -721,7 +722,7 @@ page_copy_rec_list_start(
page_cur_position(ret, new_block, &cur2);
- const bool is_leaf = page_rec_is_leaf(rec);
+ const ulint n_core = page_rec_is_leaf(rec) ? index->n_core_fields : 0;
/* Copy records from the original page to the new page */
if (index->is_spatial()) {
@@ -743,7 +744,7 @@ page_copy_rec_list_start(
} else {
while (page_cur_get_rec(&cur1) != rec) {
offsets = rec_get_offsets(cur1.rec, index, offsets,
- is_leaf,
+ n_core,
ULINT_UNDEFINED, &heap);
cur2.rec = page_cur_insert_rec_low(&cur2, index,
cur1.rec, offsets,
@@ -764,7 +765,7 @@ page_copy_rec_list_start(
same temp-table in parallel.
max_trx_id is ignored for temp tables because it not required
for MVCC. */
- if (is_leaf && dict_index_is_sec_or_ibuf(index)
+ if (n_core && dict_index_is_sec_or_ibuf(index)
&& !index->table->is_temporary()) {
page_update_max_trx_id(new_block,
new_page_zip,
@@ -884,10 +885,10 @@ page_delete_rec_list_end(
}
#endif
- /* The page gets invalid for optimistic searches */
+ /* The page becomes invalid for optimistic searches */
buf_block_modify_clock_inc(block);
- const bool is_leaf= page_is_leaf(block->frame);
+ const ulint n_core= page_is_leaf(block->frame) ? index->n_core_fields : 0;
mem_heap_t *heap= nullptr;
rec_offs offsets_[REC_OFFS_NORMAL_SIZE];
rec_offs *offsets= offsets_;
@@ -901,7 +902,7 @@ page_delete_rec_list_end(
{
page_cur_t cur;
page_cur_position(rec, block, &cur);
- offsets= rec_get_offsets(rec, index, offsets, is_leaf,
+ offsets= rec_get_offsets(rec, index, offsets, n_core,
ULINT_UNDEFINED, &heap);
rec= rec_get_next_ptr(rec, TRUE);
#ifdef UNIV_ZIP_DEBUG
@@ -932,7 +933,7 @@ page_delete_rec_list_end(
do
{
- offsets = rec_get_offsets(rec2, index, offsets, is_leaf,
+ offsets = rec_get_offsets(rec2, index, offsets, n_core,
ULINT_UNDEFINED, &heap);
ulint s= rec_offs_size(offsets);
ut_ad(ulint(rec2 - block->frame) + s - rec_offs_extra_size(offsets) <
@@ -1097,11 +1098,12 @@ page_delete_rec_list_start(
page_cur_set_before_first(block, &cur1);
page_cur_move_to_next(&cur1);
- const bool is_leaf = page_rec_is_leaf(rec);
+ const ulint n_core = page_rec_is_leaf(rec)
+ ? index->n_core_fields : 0;
while (page_cur_get_rec(&cur1) != rec) {
offsets = rec_get_offsets(page_cur_get_rec(&cur1), index,
- offsets, is_leaf,
+ offsets, n_core,
ULINT_UNDEFINED, &heap);
page_cur_delete_rec(&cur1, index, offsets, mtr);
}
@@ -2104,9 +2106,10 @@ wrong_page_type:
rec = page_get_infimum_rec(page);
+ const ulint n_core = page_is_leaf(page) ? index->n_core_fields : 0;
+
for (;;) {
- offsets = rec_get_offsets(rec, index, offsets,
- page_is_leaf(page),
+ offsets = rec_get_offsets(rec, index, offsets, n_core,
ULINT_UNDEFINED, &heap);
if (page_is_comp(page) && page_rec_is_user_rec(rec)
@@ -2352,8 +2355,7 @@ n_owned_zero:
rec = page_header_get_ptr(page, PAGE_FREE);
while (rec != NULL) {
- offsets = rec_get_offsets(rec, index, offsets,
- page_is_leaf(page),
+ offsets = rec_get_offsets(rec, index, offsets, n_core,
ULINT_UNDEFINED, &heap);
if (UNIV_UNLIKELY(!page_rec_validate(rec, offsets))) {
ret = FALSE;
diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc
index 198d83f3030..09ac48bce0f 100644
--- a/storage/innobase/page/page0zip.cc
+++ b/storage/innobase/page/page0zip.cc
@@ -903,7 +903,7 @@ page_zip_compress_node_ptrs(
do {
const rec_t* rec = *recs++;
- offsets = rec_get_offsets(rec, index, offsets, false,
+ offsets = rec_get_offsets(rec, index, offsets, 0,
ULINT_UNDEFINED, &heap);
/* Only leaf nodes may contain externally stored columns. */
ut_ad(!rec_offs_any_extern(offsets));
@@ -1152,7 +1152,7 @@ page_zip_compress_clust(
do {
const rec_t* rec = *recs++;
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_fields,
ULINT_UNDEFINED, &heap);
ut_ad(rec_offs_n_fields(offsets)
== dict_index_get_n_fields(index));
@@ -2027,7 +2027,7 @@ page_zip_apply_log(
sorted by address (indexed by
heap_no - PAGE_HEAP_NO_USER_LOW) */
ulint n_dense,/*!< in: size of recs[] */
- bool is_leaf,/*!< in: whether this is a leaf page */
+ ulint n_core, /*!< in: index->n_fields, or 0 for non-leaf */
ulint trx_id_col,/*!< in: column number of trx_id in the index,
or ULINT_UNDEFINED if none */
ulint heap_status,
@@ -2103,7 +2103,7 @@ page_zip_apply_log(
/* Clear the data bytes of the record. */
mem_heap_t* heap = NULL;
rec_offs* offs;
- offs = rec_get_offsets(rec, index, offsets, is_leaf,
+ offs = rec_get_offsets(rec, index, offsets, n_core,
ULINT_UNDEFINED, &heap);
memset(rec, 0, rec_offs_data_size(offs));
@@ -2121,7 +2121,7 @@ page_zip_apply_log(
This will be overwritten in page_zip_set_extra_bytes(),
called by page_zip_decompress_low(). */
ut_d(rec[-REC_NEW_INFO_BITS] = 0);
- rec_offs_make_valid(rec, index, is_leaf, offsets);
+ rec_offs_make_valid(rec, index, n_core != 0, offsets);
/* Copy the extra bytes (backwards). */
{
@@ -2301,7 +2301,7 @@ page_zip_decompress_node_ptrs(
}
/* Read the offsets. The status bits are needed here. */
- offsets = rec_get_offsets(rec, index, offsets, false,
+ offsets = rec_get_offsets(rec, index, offsets, 0,
ULINT_UNDEFINED, &heap);
/* Non-leaf nodes should not have any externally
@@ -2388,7 +2388,7 @@ zlib_done:
const byte* mod_log_ptr;
mod_log_ptr = page_zip_apply_log(d_stream->next_in,
d_stream->avail_in + 1,
- recs, n_dense, false,
+ recs, n_dense, 0,
ULINT_UNDEFINED, heap_status,
index, offsets);
@@ -2419,7 +2419,7 @@ zlib_done:
for (slot = 0; slot < n_dense; slot++) {
rec_t* rec = recs[slot];
- offsets = rec_get_offsets(rec, index, offsets, false,
+ offsets = rec_get_offsets(rec, index, offsets, 0,
ULINT_UNDEFINED, &heap);
/* Non-leaf nodes should not have any externally
stored columns. */
@@ -2541,7 +2541,8 @@ zlib_done:
const byte* mod_log_ptr;
mod_log_ptr = page_zip_apply_log(d_stream->next_in,
d_stream->avail_in + 1,
- recs, n_dense, true,
+ recs, n_dense,
+ index->n_fields,
ULINT_UNDEFINED, heap_status,
index, offsets);
@@ -2744,7 +2745,7 @@ page_zip_decompress_clust(
}
/* Read the offsets. The status bits are needed here. */
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_fields,
ULINT_UNDEFINED, &heap);
/* This is a leaf page in a clustered index. */
@@ -2871,7 +2872,8 @@ zlib_done:
const byte* mod_log_ptr;
mod_log_ptr = page_zip_apply_log(d_stream->next_in,
d_stream->avail_in + 1,
- recs, n_dense, true,
+ recs, n_dense,
+ index->n_fields,
trx_id_col, heap_status,
index, offsets);
@@ -2907,7 +2909,7 @@ zlib_done:
rec_t* rec = recs[slot];
bool exists = !page_zip_dir_find_free(
page_zip, page_offset(rec));
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_fields,
ULINT_UNDEFINED, &heap);
dst = rec_get_nth_field(rec, offsets,
@@ -3430,7 +3432,7 @@ page_zip_validate_low(
page + PAGE_NEW_INFIMUM, TRUE);
trec = page_rec_get_next_low(
temp_page + PAGE_NEW_INFIMUM, TRUE);
- const bool is_leaf = page_is_leaf(page);
+ const ulint n_core = page_is_leaf(page) ? index->n_fields : 0;
do {
if (page_offset(rec) != page_offset(trec)) {
@@ -3445,7 +3447,7 @@ page_zip_validate_low(
if (index) {
/* Compare the data. */
offsets = rec_get_offsets(
- rec, index, offsets, is_leaf,
+ rec, index, offsets, n_core,
ULINT_UNDEFINED, &heap);
if (memcmp(rec - rec_offs_extra_size(offsets),
diff --git a/storage/innobase/rem/rem0rec.cc b/storage/innobase/rem/rem0rec.cc
index aae621b6f56..419727b4d37 100644
--- a/storage/innobase/rem/rem0rec.cc
+++ b/storage/innobase/rem/rem0rec.cc
@@ -273,9 +273,9 @@ rec_init_offsets_comp_ordinary(
ulint n_fields = n_core;
ulint null_mask = 1;
- ut_ad(index->n_core_fields >= n_core);
ut_ad(n_core > 0);
- ut_ad(index->n_fields >= n_core);
+ ut_ad(index->n_core_fields >= n_core);
+ ut_ad(index->n_fields >= index->n_core_fields);
ut_ad(index->n_core_null_bytes <= UT_BITS_IN_BYTES(index->n_nullable));
ut_ad(format == REC_LEAF_TEMP || format == REC_LEAF_TEMP_INSTANT
|| dict_table_is_comp(index->table));
@@ -283,6 +283,11 @@ rec_init_offsets_comp_ordinary(
|| index->n_fields == rec_offs_n_fields(offsets));
ut_d(ulint n_null= 0);
+ const unsigned n_core_null_bytes = UNIV_UNLIKELY(index->n_core_fields
+ != n_core)
+ ? UT_BITS_IN_BYTES(unsigned(index->get_n_nullable(n_core)))
+ : index->n_core_null_bytes;
+
if (mblob) {
ut_ad(index->table->instant);
ut_ad(index->is_instant());
@@ -297,7 +302,7 @@ rec_init_offsets_comp_ordinary(
const ulint n_null_bytes = UT_BITS_IN_BYTES(n_nullable);
ut_d(n_null = n_nullable);
ut_ad(n_null <= index->n_nullable);
- ut_ad(n_null_bytes >= index->n_core_null_bytes
+ ut_ad(n_null_bytes >= n_core_null_bytes
|| n_core < index->n_core_fields);
lens = --nulls - n_null_bytes;
goto start;
@@ -314,10 +319,10 @@ rec_init_offsets_comp_ordinary(
case REC_LEAF_ORDINARY:
nulls -= REC_N_NEW_EXTRA_BYTES;
ordinary:
- lens = --nulls - index->n_core_null_bytes;
+ lens = --nulls - n_core_null_bytes;
- ut_d(n_null = std::min<uint>(index->n_core_null_bytes * 8U,
- index->n_nullable));
+ ut_d(n_null = std::min(n_core_null_bytes * 8U,
+ index->n_nullable));
break;
case REC_LEAF_INSTANT:
nulls -= REC_N_NEW_EXTRA_BYTES;
@@ -330,7 +335,7 @@ ordinary:
const ulint n_null_bytes = UT_BITS_IN_BYTES(n_nullable);
ut_d(n_null = n_nullable);
ut_ad(n_null <= index->n_nullable);
- ut_ad(n_null_bytes >= index->n_core_null_bytes
+ ut_ad(n_null_bytes >= n_core_null_bytes
|| n_core < index->n_core_fields);
lens = --nulls - n_null_bytes;
}
@@ -588,14 +593,14 @@ is (SQL_NULL), the field i is NULL. When the type of the offset at [i+1]
is (STORED_OFFPAGE), the field i is stored externally.
@param[in] rec record
@param[in] index the index that the record belongs in
-@param[in] leaf whether the record resides in a leaf page
+@param[in] n_core 0, or index->n_core_fields for leaf page
@param[in,out] offsets array of offsets, with valid rec_offs_n_fields() */
static
void
rec_init_offsets(
const rec_t* rec,
const dict_index_t* index,
- bool leaf,
+ ulint n_core,
rec_offs* offsets)
{
ulint i = 0;
@@ -610,6 +615,8 @@ rec_init_offsets(
|| index->in_instant_init);
ut_d(memcpy(&offsets[RECORD_OFFSET], &rec, sizeof(rec)));
ut_d(memcpy(&offsets[INDEX_OFFSET], &index, sizeof(index)));
+ ut_ad(index->n_fields >= n_core);
+ ut_ad(index->n_core_fields >= n_core);
if (dict_table_is_comp(index->table)) {
const byte* nulls;
@@ -628,23 +635,21 @@ rec_init_offsets(
rec_offs_base(offsets)[1] = 8;
return;
case REC_STATUS_NODE_PTR:
- ut_ad(!leaf);
+ ut_ad(!n_core);
n_node_ptr_field
= dict_index_get_n_unique_in_tree_nonleaf(
index);
break;
case REC_STATUS_INSTANT:
- ut_ad(leaf);
ut_ad(index->is_instant());
rec_init_offsets_comp_ordinary(rec, index, offsets,
- index->n_core_fields,
+ n_core,
NULL,
REC_LEAF_INSTANT);
return;
case REC_STATUS_ORDINARY:
- ut_ad(leaf);
rec_init_offsets_comp_ordinary(rec, index, offsets,
- index->n_core_fields,
+ n_core,
NULL,
REC_LEAF_ORDINARY);
return;
@@ -806,7 +811,7 @@ resolved:
@param[in] index the index that the record belongs to
@param[in,out] offsets array comprising offsets[0] allocated elements,
or an array from rec_get_offsets(), or NULL
-@param[in] leaf whether this is a leaf-page record
+@param[in] n_core 0, or index->n_core_fields for leaf page
@param[in] n_fields maximum number of offsets to compute
(ULINT_UNDEFINED to compute all offsets)
@param[in,out] heap memory heap
@@ -816,7 +821,7 @@ rec_get_offsets_func(
const rec_t* rec,
const dict_index_t* index,
rec_offs* offsets,
- bool leaf,
+ ulint n_core,
ulint n_fields,
#ifdef UNIV_DEBUG
const char* file, /*!< in: file name where called */
@@ -828,6 +833,15 @@ rec_get_offsets_func(
ulint size;
bool alter_metadata = false;
+ ut_ad(index->n_core_fields >= n_core);
+ /* This assertion was relaxed for the btr_cur_open_at_index_side()
+ call in btr_cur_instant_init_low(). We cannot invoke
+ index->is_instant(), because the same assertion would fail there
+ until btr_cur_instant_init_low() has invoked
+ dict_table_t::deserialise_columns(). */
+ ut_ad(index->n_fields >= index->n_core_fields
+ || index->in_instant_init);
+
if (dict_table_is_comp(index->table)) {
switch (UNIV_EXPECT(rec_get_status(rec),
REC_STATUS_ORDINARY)) {
@@ -835,14 +849,14 @@ rec_get_offsets_func(
alter_metadata = rec_is_alter_metadata(rec, true);
/* fall through */
case REC_STATUS_ORDINARY:
- ut_ad(leaf);
+ ut_ad(n_core);
n = dict_index_get_n_fields(index) + alter_metadata;
break;
case REC_STATUS_NODE_PTR:
/* Node pointer records consist of the
uniquely identifying fields of the record
followed by a child page number field. */
- ut_ad(!leaf);
+ ut_ad(!n_core);
n = dict_index_get_n_unique_in_tree_nonleaf(index) + 1;
break;
case REC_STATUS_INFIMUM:
@@ -871,19 +885,19 @@ rec_get_offsets_func(
>= PAGE_HEAP_NO_USER_LOW;
/* The infimum and supremum records carry 1 field. */
ut_ad(is_user_rec || n == 1);
- ut_ad(!is_user_rec || leaf || index->is_dummy
+ ut_ad(!is_user_rec || n_core || index->is_dummy
|| dict_index_is_ibuf(index)
|| n == n_fields /* dict_stats_analyze_index_level() */
|| n - 1
== dict_index_get_n_unique_in_tree_nonleaf(index));
- ut_ad(!is_user_rec || !leaf || index->is_dummy
+ ut_ad(!is_user_rec || !n_core || index->is_dummy
|| dict_index_is_ibuf(index)
|| n == n_fields /* btr_pcur_restore_position() */
|| (n + (index->id == DICT_INDEXES_ID)
- >= index->n_core_fields && n <= index->n_fields
+ >= n_core && n <= index->n_fields
+ unsigned(rec_is_alter_metadata(rec, false))));
- if (is_user_rec && leaf && n < index->n_fields) {
+ if (is_user_rec && n_core && n < index->n_fields) {
ut_ad(!index->is_dummy);
ut_ad(!dict_index_is_ibuf(index));
n = index->n_fields;
@@ -917,17 +931,17 @@ rec_get_offsets_func(
memcpy(&offsets[RECORD_OFFSET], &rec, sizeof rec);
memcpy(&offsets[INDEX_OFFSET], &index, sizeof index);
#endif /* UNIV_DEBUG */
- ut_ad(leaf);
+ ut_ad(n_core);
ut_ad(index->table->instant);
ut_ad(index->is_instant());
ut_ad(rec_offs_n_fields(offsets)
<= ulint(index->n_fields) + 1);
rec_init_offsets_comp_ordinary<true>(rec, index, offsets,
index->n_core_fields,
- NULL,
+ nullptr,
REC_LEAF_INSTANT);
} else {
- rec_init_offsets(rec, index, leaf, offsets);
+ rec_init_offsets(rec, index, n_core, offsets);
}
return offsets;
}
@@ -1850,7 +1864,9 @@ template void rec_convert_dtuple_to_temp<true>(
The fields are copied into the memory heap.
@param[out] tuple data tuple
@param[in] rec index record, or a copy thereof
-@param[in] is_leaf whether rec is a leaf page record
+@param[in] index index of rec
+@param[in] n_core index->n_core_fields at the time rec was
+ copied, or 0 if non-leaf page record
@param[in] n_fields number of fields to copy
@param[in,out] heap memory heap */
void
@@ -1858,7 +1874,7 @@ rec_copy_prefix_to_dtuple(
dtuple_t* tuple,
const rec_t* rec,
const dict_index_t* index,
- bool is_leaf,
+ ulint n_core,
ulint n_fields,
mem_heap_t* heap)
{
@@ -1866,10 +1882,11 @@ rec_copy_prefix_to_dtuple(
rec_offs* offsets = offsets_;
rec_offs_init(offsets_);
- ut_ad(is_leaf || n_fields - 1
+ ut_ad(n_core <= index->n_core_fields);
+ ut_ad(n_core || n_fields - 1
<= dict_index_get_n_unique_in_tree_nonleaf(index));
- offsets = rec_get_offsets(rec, index, offsets, is_leaf,
+ offsets = rec_get_offsets(rec, index, offsets, n_core,
n_fields, &heap);
ut_ad(rec_validate(rec, offsets));
@@ -2509,7 +2526,8 @@ rec_print(
rec_print_new(file, rec,
rec_get_offsets(rec, index, offsets_,
- page_rec_is_leaf(rec),
+ page_rec_is_leaf(rec)
+ ? index->n_core_fields : 0,
ULINT_UNDEFINED, &heap));
if (UNIV_LIKELY_NULL(heap)) {
mem_heap_free(heap);
@@ -2585,7 +2603,8 @@ operator<<(std::ostream& o, const rec_index_print& r)
{
mem_heap_t* heap = NULL;
rec_offs* offsets = rec_get_offsets(
- r.m_rec, r.m_index, NULL, page_rec_is_leaf(r.m_rec),
+ r.m_rec, r.m_index, NULL, page_rec_is_leaf(r.m_rec)
+ ? r.m_index->n_core_fields : 0,
ULINT_UNDEFINED, &heap);
rec_print(o, r.m_rec,
rec_get_info_bits(r.m_rec, rec_offs_comp(offsets)),
@@ -2624,7 +2643,7 @@ rec_get_trx_id(
rec_offs_init(offsets_);
rec_offs* offsets = offsets_;
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
index->db_trx_id() + 1, &heap);
trx_id = rec_get_nth_field(rec, offsets, index->db_trx_id(), &len);
@@ -2675,7 +2694,8 @@ wsrep_rec_get_foreign_key(
ut_ad(index_ref);
rec_offs_init(offsets_);
- offsets = rec_get_offsets(rec, index_for, offsets_, true,
+ offsets = rec_get_offsets(rec, index_for, offsets_,
+ index_for->n_core_fields,
ULINT_UNDEFINED, &heap);
ut_ad(rec_offs_validate(rec, NULL, offsets));
diff --git a/storage/innobase/row/row0ftsort.cc b/storage/innobase/row/row0ftsort.cc
index 891e9318da5..7c1488c82cb 100644
--- a/storage/innobase/row/row0ftsort.cc
+++ b/storage/innobase/row/row0ftsort.cc
@@ -910,7 +910,7 @@ loop:
<< " records, the sort queue has "
<< UT_LIST_GET_LEN(psort_info->fts_doc_list)
<< " records. But sort cannot get the next"
- " records";
+ " records during alter table " << table->name;
goto exit;
}
} else if (psort_info->state == FTS_PARENT_EXITING) {
@@ -1192,7 +1192,9 @@ row_merge_write_fts_word(
if (UNIV_UNLIKELY(error != DB_SUCCESS)) {
ib::error() << "Failed to write word to FTS auxiliary"
- " index table, error " << error;
+ " index table "
+ << ins_ctx->btr_bulk->table_name()
+ << ", error " << error;
ret = error;
}
diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc
index e1864fd27bc..3060ec05bc8 100644
--- a/storage/innobase/row/row0import.cc
+++ b/storage/innobase/row/row0import.cc
@@ -1839,7 +1839,8 @@ PageConverter::update_records(
if (deleted || clust_index) {
m_offsets = rec_get_offsets(
- rec, m_index->m_srv_index, m_offsets, true,
+ rec, m_index->m_srv_index, m_offsets,
+ m_index->m_srv_index->n_core_fields,
ULINT_UNDEFINED, &m_heap);
}
diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc
index 1caa9d88ca0..880554d76b4 100644
--- a/storage/innobase/row/row0ins.cc
+++ b/storage/innobase/row/row0ins.cc
@@ -885,7 +885,7 @@ row_ins_foreign_fill_virtual(
rec_offs offsets_[REC_OFFS_NORMAL_SIZE];
rec_offs_init(offsets_);
const rec_offs* offsets =
- rec_get_offsets(rec, index, offsets_, true,
+ rec_get_offsets(rec, index, offsets_, index->n_core_fields,
ULINT_UNDEFINED, &cascade->heap);
TABLE* mysql_table= NULL;
upd_t* update = cascade->update;
@@ -1199,7 +1199,8 @@ row_ins_foreign_check_on_constraint(
if (table->fts) {
doc_id = fts_get_doc_id_from_rec(
clust_rec, clust_index,
- rec_get_offsets(clust_rec, clust_index, NULL, true,
+ rec_get_offsets(clust_rec, clust_index, NULL,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, &tmp_heap));
}
@@ -1640,7 +1641,8 @@ row_ins_check_foreign_constraint(
continue;
}
- offsets = rec_get_offsets(rec, check_index, offsets, true,
+ offsets = rec_get_offsets(rec, check_index, offsets,
+ check_index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (page_rec_is_supremum(rec)) {
@@ -2124,7 +2126,8 @@ row_ins_scan_sec_index_for_duplicate(
continue;
}
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, &offsets_heap);
if (flags & BTR_NO_LOCKING_FLAG) {
@@ -2261,7 +2264,8 @@ row_ins_duplicate_error_in_clust_online(
ut_ad(!cursor->index->is_instant());
if (cursor->low_match >= n_uniq && !page_rec_is_infimum(rec)) {
- *offsets = rec_get_offsets(rec, cursor->index, *offsets, true,
+ *offsets = rec_get_offsets(rec, cursor->index, *offsets,
+ cursor->index->n_fields,
ULINT_UNDEFINED, heap);
err = row_ins_duplicate_online(n_uniq, entry, rec, *offsets);
if (err != DB_SUCCESS) {
@@ -2272,7 +2276,8 @@ row_ins_duplicate_error_in_clust_online(
rec = page_rec_get_next_const(btr_cur_get_rec(cursor));
if (cursor->up_match >= n_uniq && !page_rec_is_supremum(rec)) {
- *offsets = rec_get_offsets(rec, cursor->index, *offsets, true,
+ *offsets = rec_get_offsets(rec, cursor->index, *offsets,
+ cursor->index->n_fields,
ULINT_UNDEFINED, heap);
err = row_ins_duplicate_online(n_uniq, entry, rec, *offsets);
}
@@ -2328,7 +2333,7 @@ row_ins_duplicate_error_in_clust(
if (!page_rec_is_infimum(rec)) {
offsets = rec_get_offsets(rec, cursor->index, offsets,
- true,
+ cursor->index->n_core_fields,
ULINT_UNDEFINED, &heap);
/* We set a lock on the possible duplicate: this
@@ -2394,7 +2399,7 @@ duplicate:
if (!page_rec_is_supremum(rec)) {
offsets = rec_get_offsets(rec, cursor->index, offsets,
- true,
+ cursor->index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (trx->duplicates) {
@@ -2511,7 +2516,7 @@ row_ins_index_entry_big_rec(
btr_pcur_open(index, entry, PAGE_CUR_LE, BTR_MODIFY_TREE,
&pcur, &mtr);
rec = btr_pcur_get_rec(&pcur);
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
ULINT_UNDEFINED, heap);
DEBUG_SYNC_C_IF_THD(thd, "before_row_ins_extern");
@@ -3117,7 +3122,8 @@ row_ins_sec_index_entry_low(
prefix, we must convert the insert into a modify of an
existing record */
offsets = rec_get_offsets(
- btr_cur_get_rec(&cursor), index, offsets, true,
+ btr_cur_get_rec(&cursor), index, offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, &offsets_heap);
err = row_ins_sec_index_entry_by_modify(
diff --git a/storage/innobase/row/row0log.cc b/storage/innobase/row/row0log.cc
index d271092166f..610ac1ad2ae 100644
--- a/storage/innobase/row/row0log.cc
+++ b/storage/innobase/row/row0log.cc
@@ -1289,7 +1289,8 @@ row_log_table_get_pk(
if (!offsets) {
offsets = rec_get_offsets(
- rec, index, NULL, true,
+ rec, index, nullptr,
+ index->n_core_fields,
index->db_trx_id() + 1, heap);
}
@@ -1339,7 +1340,8 @@ row_log_table_get_pk(
}
if (!offsets) {
- offsets = rec_get_offsets(rec, index, NULL, true,
+ offsets = rec_get_offsets(rec, index, nullptr,
+ index->n_core_fields,
ULINT_UNDEFINED, heap);
}
@@ -2011,7 +2013,8 @@ all_done:
return(DB_SUCCESS);
}
- offsets = rec_get_offsets(btr_pcur_get_rec(&pcur), index, NULL, true,
+ offsets = rec_get_offsets(btr_pcur_get_rec(&pcur), index, nullptr,
+ index->n_core_fields,
ULINT_UNDEFINED, &offsets_heap);
#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
ut_a(!rec_offs_any_null_extern(btr_pcur_get_rec(&pcur), offsets));
@@ -2208,7 +2211,7 @@ func_exit_committed:
/* Prepare to update (or delete) the record. */
rec_offs* cur_offsets = rec_get_offsets(
- btr_pcur_get_rec(&pcur), index, NULL, true,
+ btr_pcur_get_rec(&pcur), index, nullptr, index->n_core_fields,
ULINT_UNDEFINED, &offsets_heap);
if (!log->same_pk) {
diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc
index b21b17be15f..1358617b0db 100644
--- a/storage/innobase/row/row0merge.cc
+++ b/storage/innobase/row/row0merge.cc
@@ -2043,7 +2043,8 @@ end_of_index:
rec = page_cur_get_rec(cur);
if (online) {
- offsets = rec_get_offsets(rec, clust_index, NULL, true,
+ offsets = rec_get_offsets(rec, clust_index, NULL,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, &row_heap);
rec_trx_id = row_get_rec_trx_id(rec, clust_index,
offsets);
@@ -2135,7 +2136,8 @@ end_of_index:
duplicate keys. */
continue;
} else {
- offsets = rec_get_offsets(rec, clust_index, NULL, true,
+ offsets = rec_get_offsets(rec, clust_index, NULL,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, &row_heap);
/* This is a locking ALTER TABLE.
@@ -3790,17 +3792,20 @@ row_merge_drop_indexes_dict(
trx->op_info = "";
}
-/*********************************************************************//**
-Drop indexes that were created before an error occurred.
+/** Drop indexes that were created before an error occurred.
The data dictionary must have been locked exclusively by the caller,
-because the transaction will not be committed. */
+because the transaction will not be committed.
+@param trx dictionary transaction
+@param table table containing the indexes
+@param locked True if table is locked,
+ false - may need to do lazy drop
+@param alter_trx Alter table transaction */
void
row_merge_drop_indexes(
-/*===================*/
- trx_t* trx, /*!< in/out: dictionary transaction */
- dict_table_t* table, /*!< in/out: table containing the indexes */
- ibool locked) /*!< in: TRUE=table locked,
- FALSE=may need to do a lazy drop */
+ trx_t* trx,
+ dict_table_t* table,
+ bool locked,
+ const trx_t* alter_trx)
{
dict_index_t* index;
dict_index_t* next_index;
@@ -3825,7 +3830,7 @@ row_merge_drop_indexes(
A concurrent purge will be prevented by dict_sys.latch. */
if (!locked && (table->get_ref_count() > 1
- || UT_LIST_GET_FIRST(table->locks))) {
+ || table->has_lock_other_than(alter_trx))) {
/* We will have to drop the indexes later, when the
table is guaranteed to be no longer in use. Mark the
indexes as incomplete and corrupted, so that other
@@ -4251,6 +4256,7 @@ row_merge_create_index(
dict_index_t* index;
ulint n_fields = index_def->n_fields;
ulint i;
+ ulint n_add_vcol = 0;
DBUG_ENTER("row_merge_create_index");
@@ -4275,7 +4281,7 @@ row_merge_create_index(
ut_ad(ifield->col_no >= table->n_v_def);
name = add_v->v_col_name[
ifield->col_no - table->n_v_def];
- index->has_new_v_col = true;
+ n_add_vcol++;
} else {
name = dict_table_get_v_col_name(
table, ifield->col_no);
@@ -4287,6 +4293,10 @@ row_merge_create_index(
dict_mem_index_add_field(index, name, ifield->prefix_len);
}
+ if (n_add_vcol) {
+ index->assign_new_v_col(n_add_vcol);
+ }
+
DBUG_RETURN(index);
}
diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc
index efdc47de0f9..cf979d03e0a 100644
--- a/storage/innobase/row/row0mysql.cc
+++ b/storage/innobase/row/row0mysql.cc
@@ -688,6 +688,7 @@ row_mysql_handle_errors(
dberr_t err;
DBUG_ENTER("row_mysql_handle_errors");
+ DEBUG_SYNC_C("row_mysql_handle_errors");
err = trx->error_state;
@@ -1773,12 +1774,11 @@ row_update_for_mysql(row_prebuilt_t* prebuilt)
clust_index = dict_table_get_first_index(table);
- if (prebuilt->pcur->btr_cur.index == clust_index) {
- btr_pcur_copy_stored_position(node->pcur, prebuilt->pcur);
- } else {
- btr_pcur_copy_stored_position(node->pcur,
- prebuilt->clust_pcur);
- }
+ btr_pcur_copy_stored_position(node->pcur,
+ prebuilt->pcur->btr_cur.index
+ == clust_index
+ ? prebuilt->pcur
+ : prebuilt->clust_pcur);
ut_a(node->pcur->rel_pos == BTR_PCUR_ON);
@@ -1981,7 +1981,8 @@ row_unlock_for_mysql(
rec_offs* offsets = offsets_;
rec_offs_init(offsets_);
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
rec_trx_id = row_get_rec_trx_id(rec, index, offsets);
@@ -4670,7 +4671,7 @@ func_exit:
rec = buf + mach_read_from_4(buf);
- offsets = rec_get_offsets(rec, index, offsets_, true,
+ offsets = rec_get_offsets(rec, index, offsets_, index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (prev_entry != NULL) {
diff --git a/storage/innobase/row/row0purge.cc b/storage/innobase/row/row0purge.cc
index 0fdc1763eb4..c0a898855b1 100644
--- a/storage/innobase/row/row0purge.cc
+++ b/storage/innobase/row/row0purge.cc
@@ -137,8 +137,9 @@ row_purge_remove_clust_if_poss_low(
rec_offs offsets_[REC_OFFS_NORMAL_SIZE];
rec_offs_init(offsets_);
mem_heap_t* heap = NULL;
- rec_offs* offsets = rec_get_offsets(
- rec, index, offsets_, true, ULINT_UNDEFINED, &heap);
+ rec_offs* offsets = rec_get_offsets(rec, index, offsets_,
+ index->n_core_fields,
+ ULINT_UNDEFINED, &heap);
bool success = true;
if (node->roll_ptr != row_get_rec_roll_ptr(rec, index, offsets)) {
@@ -615,7 +616,7 @@ row_purge_skip_uncommitted_virtual_index(
not support LOCK=NONE when adding an index on newly
added virtual column.*/
while (index != NULL && dict_index_has_virtual(index)
- && !index->is_committed() && index->has_new_v_col) {
+ && !index->is_committed() && index->has_new_v_col()) {
index = dict_table_get_next_index(index);
}
}
@@ -681,7 +682,8 @@ static void row_purge_reset_trx_id(purge_node_t* node, mtr_t* mtr)
rec_offs offsets_[REC_OFFS_HEADER_SIZE + MAX_REF_PARTS + 2];
rec_offs_init(offsets_);
rec_offs* offsets = rec_get_offsets(
- rec, index, offsets_, true, trx_id_pos + 2, &heap);
+ rec, index, offsets_, index->n_core_fields,
+ trx_id_pos + 2, &heap);
ut_ad(heap == NULL);
ut_ad(dict_index_get_nth_field(index, trx_id_pos)
@@ -1217,7 +1219,7 @@ purge_node_t::validate_pcur()
dict_index_t* clust_index = pcur.btr_cur.index;
rec_offs* offsets = rec_get_offsets(
- pcur.old_rec, clust_index, NULL, true,
+ pcur.old_rec, clust_index, NULL, pcur.old_n_core_fields,
pcur.old_n_fields, &heap);
/* Here we are comparing the purge ref record and the stored initial
diff --git a/storage/innobase/row/row0row.cc b/storage/innobase/row/row0row.cc
index 4c8eba9f4a4..19870906df8 100644
--- a/storage/innobase/row/row0row.cc
+++ b/storage/innobase/row/row0row.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2018, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2018, 2020, MariaDB Corporation.
+Copyright (c) 2018, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -440,7 +440,8 @@ row_build_low(
ut_ad(!col_map || col_table);
if (!offsets) {
- offsets = rec_get_offsets(rec, index, offsets_, true,
+ offsets = rec_get_offsets(rec, index, offsets_,
+ index->n_core_fields,
ULINT_UNDEFINED, &tmp_heap);
} else {
ut_ad(rec_offs_validate(rec, index, offsets));
@@ -1004,7 +1005,7 @@ row_build_row_ref(
ut_ad(heap != NULL);
ut_ad(!dict_index_is_clust(index));
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
ULINT_UNDEFINED, &tmp_heap);
/* Secondary indexes must not contain externally stored columns. */
ut_ad(!rec_offs_any_extern(offsets));
@@ -1113,7 +1114,8 @@ row_build_row_ref_in_tuple(
ut_ad(clust_index);
if (!offsets) {
- offsets = rec_get_offsets(rec, index, offsets_, true,
+ offsets = rec_get_offsets(rec, index, offsets_,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
} else {
ut_ad(rec_offs_validate(rec, index, offsets));
diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc
index e5e033857ec..bfe54e4cbe9 100644
--- a/storage/innobase/row/row0sel.cc
+++ b/storage/innobase/row/row0sel.cc
@@ -203,9 +203,11 @@ row_sel_sec_rec_is_for_clust_rec(
ib_vcol_row vc(heap);
clust_offs = rec_get_offsets(clust_rec, clust_index, clust_offs,
- true, ULINT_UNDEFINED, &heap);
+ clust_index->n_core_fields,
+ ULINT_UNDEFINED, &heap);
sec_offs = rec_get_offsets(sec_rec, sec_index, sec_offs,
- true, ULINT_UNDEFINED, &heap);
+ sec_index->n_fields,
+ ULINT_UNDEFINED, &heap);
n = dict_index_get_n_ordering_defined_by_user(sec_index);
@@ -927,7 +929,9 @@ row_sel_get_clust_rec(
offsets = rec_get_offsets(rec,
btr_pcur_get_btr_cur(&plan->pcur)->index,
- offsets, true, ULINT_UNDEFINED, &heap);
+ offsets,
+ btr_pcur_get_btr_cur(&plan->pcur)->index
+ ->n_core_fields, ULINT_UNDEFINED, &heap);
row_build_row_ref_fast(plan->clust_ref, plan->clust_map, rec, offsets);
@@ -962,7 +966,8 @@ row_sel_get_clust_rec(
goto err_exit;
}
- offsets = rec_get_offsets(clust_rec, index, offsets, true,
+ offsets = rec_get_offsets(clust_rec, index, offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (!node->read_view) {
@@ -1169,7 +1174,8 @@ re_scan:
rec = btr_pcur_get_rec(pcur);
my_offsets = offsets_;
- my_offsets = rec_get_offsets(rec, index, my_offsets, true,
+ my_offsets = rec_get_offsets(rec, index, my_offsets,
+ index->n_fields,
ULINT_UNDEFINED, &heap);
/* No match record */
@@ -1192,7 +1198,7 @@ re_scan:
rtr_rec_t* rtr_rec = &(*it);
my_offsets = rec_get_offsets(
- rtr_rec->r_rec, index, my_offsets, true,
+ rtr_rec->r_rec, index, my_offsets, index->n_fields,
ULINT_UNDEFINED, &heap);
err = lock_sec_rec_read_check_and_lock(
@@ -1508,7 +1514,7 @@ exhausted:
rec_offs offsets_[REC_OFFS_NORMAL_SIZE];
rec_offs* offsets = offsets_;
rec_offs_init(offsets_);
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (dict_index_is_clust(index)) {
@@ -1721,7 +1727,7 @@ rec_loop:
unsigned lock_type;
offsets = rec_get_offsets(next_rec, index, offsets,
- true,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
/* At READ UNCOMMITTED or READ COMMITTED
@@ -1780,7 +1786,8 @@ skip_lock:
/* Try to place a lock on the index record */
unsigned lock_type;
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
/* At READ UNCOMMITTED or READ COMMITTED isolation level,
@@ -1863,7 +1870,7 @@ skip_lock:
/* PHASE 3: Get previous version in a consistent read */
cons_read_requires_clust_rec = FALSE;
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (node->read_view) {
@@ -1893,7 +1900,8 @@ skip_lock:
exhausted. */
offsets = rec_get_offsets(
- rec, index, offsets, true,
+ rec, index, offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
/* Fetch the columns needed in
@@ -3193,7 +3201,8 @@ class Row_sel_get_clust_rec_for_mysql
ut_ad(rec_offs_validate(cached_clust_rec, index, offsets));
ut_ad(index->first_user_field() <= rec_offs_n_fields(offsets));
- ut_ad(vers_offs == rec_get_offsets(cached_old_vers, index, vers_offs, true,
+ ut_ad(vers_offs == rec_get_offsets(cached_old_vers, index, vers_offs,
+ index->n_core_fields,
index->db_trx_id(), &heap));
ut_ad(!heap);
for (auto n= index->db_trx_id(); n--; )
@@ -3379,7 +3388,8 @@ Row_sel_get_clust_rec_for_mysql::operator()(
goto func_exit;
}
- *offsets = rec_get_offsets(clust_rec, clust_index, *offsets, true,
+ *offsets = rec_get_offsets(clust_rec, clust_index, *offsets,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, offset_heap);
if (prebuilt->select_lock_type != LOCK_NONE) {
@@ -3450,7 +3460,8 @@ Row_sel_get_clust_rec_for_mysql::operator()(
ut_d(check_eq(clust_index, *offsets));
*offsets = rec_get_offsets(
old_vers, clust_index, *offsets,
- true, ULINT_UNDEFINED, offset_heap);
+ clust_index->n_core_fields,
+ ULINT_UNDEFINED, offset_heap);
}
}
@@ -3889,7 +3900,7 @@ exhausted:
/* This is a non-locking consistent read: if necessary, fetch
a previous version of the record */
- *offsets = rec_get_offsets(rec, index, *offsets, true,
+ *offsets = rec_get_offsets(rec, index, *offsets, index->n_core_fields,
ULINT_UNDEFINED, heap);
if (!row_sel_clust_sees(rec, *index, *offsets, trx->read_view)) {
@@ -4054,7 +4065,7 @@ row_sel_fill_vrow(
ut_ad(!index->is_instant());
ut_ad(page_rec_is_leaf(rec));
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
ULINT_UNDEFINED, &heap);
*vrow = dtuple_create_with_vcol(
@@ -4683,7 +4694,7 @@ wait_table_again:
const rec_t* next_rec = page_rec_get_next_const(rec);
offsets = rec_get_offsets(next_rec, index, offsets,
- true,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
err = sel_set_rec_lock(pcur,
next_rec, index, offsets,
@@ -4808,7 +4819,8 @@ rec_loop:
we do not lock gaps. Supremum record is really
a gap and therefore we do not set locks there. */
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
err = sel_set_rec_lock(pcur,
rec, index, offsets,
@@ -4910,7 +4922,7 @@ wrong_offs:
ut_ad(fil_page_index_page_check(btr_pcur_get_page(pcur)));
ut_ad(btr_page_get_index_id(btr_pcur_get_page(pcur)) == index->id);
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (UNIV_UNLIKELY(srv_force_recovery > 0)) {
@@ -5154,7 +5166,8 @@ no_gap_lock:
Do a normal locking read. */
offsets = rec_get_offsets(
- rec, index, offsets, true,
+ rec, index, offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
goto locks_ok;
case DB_DEADLOCK:
@@ -5555,7 +5568,7 @@ use_covering_index:
/* We used 'offsets' for the clust
rec, recalculate them for 'rec' */
offsets = rec_get_offsets(rec, index, offsets,
- true,
+ index->n_core_fields,
ULINT_UNDEFINED,
&heap);
result_rec = rec;
@@ -5995,7 +6008,7 @@ row_search_autoinc_read_column(
rec_offs_init(offsets_);
ut_ad(page_rec_is_leaf(rec));
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
col_no + 1, &heap);
if (rec_offs_nth_sql_null(offsets, col_no)) {
diff --git a/storage/innobase/row/row0uins.cc b/storage/innobase/row/row0uins.cc
index 0818a35c480..1a61a529e2c 100644
--- a/storage/innobase/row/row0uins.cc
+++ b/storage/innobase/row/row0uins.cc
@@ -120,7 +120,8 @@ row_undo_ins_remove_clust_rec(
if (online && dict_index_is_online_ddl(index)) {
mem_heap_t* heap = NULL;
const rec_offs* offsets = rec_get_offsets(
- rec, index, NULL, true, ULINT_UNDEFINED, &heap);
+ rec, index, NULL, index->n_core_fields,
+ ULINT_UNDEFINED, &heap);
row_log_table_delete(rec, index, offsets, NULL);
mem_heap_free(heap);
} else {
diff --git a/storage/innobase/row/row0umod.cc b/storage/innobase/row/row0umod.cc
index 462563de540..064a7ffd888 100644
--- a/storage/innobase/row/row0umod.cc
+++ b/storage/innobase/row/row0umod.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1997, 2017, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2020, MariaDB Corporation.
+Copyright (c) 2017, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -189,8 +189,9 @@ static ulint row_trx_id_offset(const rec_t* rec, const dict_index_t* index)
rec_offs_init(offsets_);
mem_heap_t* heap = NULL;
const ulint trx_id_pos = index->n_uniq ? index->n_uniq : 1;
- rec_offs* offsets = rec_get_offsets(rec, index, offsets_, true,
- trx_id_pos + 1, &heap);
+ rec_offs* offsets = rec_get_offsets(rec, index, offsets_,
+ index->n_core_fields,
+ trx_id_pos + 1, &heap);
ut_ad(!heap);
ulint len;
trx_id_offset = rec_get_nth_field_offs(
@@ -461,9 +462,9 @@ row_undo_mod_clust(
} else {
ut_ad(index->n_uniq <= MAX_REF_PARTS);
rec_offs_init(offsets_);
- offsets = rec_get_offsets(
- rec, index, offsets_, true, trx_id_pos + 2,
- &heap);
+ offsets = rec_get_offsets(rec, index, offsets_,
+ index->n_core_fields,
+ trx_id_pos + 2, &heap);
ulint len;
trx_id_offset = rec_get_nth_field_offs(
offsets, trx_id_pos, &len);
@@ -853,7 +854,8 @@ try_again:
offsets_heap = NULL;
offsets = rec_get_offsets(
btr_cur_get_rec(btr_cur),
- index, NULL, true, ULINT_UNDEFINED, &offsets_heap);
+ index, nullptr, index->n_core_fields, ULINT_UNDEFINED,
+ &offsets_heap);
update = row_upd_build_sec_rec_difference_binary(
btr_cur_get_rec(btr_cur), index, offsets, entry, heap);
if (upd_get_n_fields(update) == 0) {
diff --git a/storage/innobase/row/row0undo.cc b/storage/innobase/row/row0undo.cc
index 960d83d32ab..eb672eb0caa 100644
--- a/storage/innobase/row/row0undo.cc
+++ b/storage/innobase/row/row0undo.cc
@@ -187,7 +187,8 @@ row_undo_search_clust_to_pcur(
rec = btr_pcur_get_rec(&node->pcur);
- offsets = rec_get_offsets(rec, clust_index, offsets, true,
+ offsets = rec_get_offsets(rec, clust_index, offsets,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, &heap);
found = row_get_rec_roll_ptr(rec, clust_index, offsets)
diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc
index a625b24afa3..0a259726198 100644
--- a/storage/innobase/row/row0upd.cc
+++ b/storage/innobase/row/row0upd.cc
@@ -693,7 +693,8 @@ row_upd_build_difference_binary(
n_diff = 0;
if (!offsets) {
- offsets = rec_get_offsets(rec, index, offsets_, true,
+ offsets = rec_get_offsets(rec, index, offsets_,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
} else {
ut_ad(rec_offs_validate(rec, index, offsets));
@@ -1894,7 +1895,8 @@ row_upd_store_row(
rec = btr_pcur_get_rec(node->pcur);
- offsets = rec_get_offsets(rec, clust_index, offsets_, true,
+ offsets = rec_get_offsets(rec, clust_index, offsets_,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (dict_table_has_atomic_blobs(node->table)) {
@@ -2133,7 +2135,7 @@ row_upd_sec_index_entry(
&& !wsrep_thd_is_BF(trx->mysql_thd, FALSE)) {
rec_offs* offsets = rec_get_offsets(
- rec, index, NULL, true,
+ rec, index, NULL, index->n_core_fields,
ULINT_UNDEFINED, &heap);
err = wsrep_row_upd_check_foreign_constraints(
@@ -2176,12 +2178,9 @@ row_upd_sec_index_entry(
ut_ad(err == DB_SUCCESS);
if (referenced) {
-
- rec_offs* offsets;
-
- offsets = rec_get_offsets(
- rec, index, NULL, true, ULINT_UNDEFINED,
- &heap);
+ rec_offs* offsets = rec_get_offsets(
+ rec, index, NULL, index->n_core_fields,
+ ULINT_UNDEFINED, &heap);
/* NOTE that the following call loses
the position of pcur ! */
@@ -2432,7 +2431,8 @@ row_upd_clust_rec_by_insert(
we update the primary key. Delete-mark the old record
in the clustered index and prepare to insert a new entry. */
rec = btr_cur_get_rec(btr_cur);
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap);
ut_ad(page_rec_is_user_rec(rec));
@@ -2821,7 +2821,7 @@ row_upd_clust_step(
}
rec = btr_pcur_get_rec(pcur);
- offsets = rec_get_offsets(rec, index, offsets_, true,
+ offsets = rec_get_offsets(rec, index, offsets_, index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (!flags && !node->has_clust_rec_x_lock) {
diff --git a/storage/innobase/row/row0vers.cc b/storage/innobase/row/row0vers.cc
index c64a9d07131..210a09e637d 100644
--- a/storage/innobase/row/row0vers.cc
+++ b/storage/innobase/row/row0vers.cc
@@ -116,7 +116,8 @@ row_vers_impl_x_locked_low(
heap = mem_heap_create(1024);
clust_offsets = rec_get_offsets(clust_rec, clust_index, clust_offsets_,
- true, ULINT_UNDEFINED, &heap);
+ clust_index->n_core_fields,
+ ULINT_UNDEFINED, &heap);
trx_id = row_get_rec_trx_id(clust_rec, clust_index, clust_offsets);
if (trx_id == 0) {
@@ -239,7 +240,8 @@ not_locked:
}
clust_offsets = rec_get_offsets(
- prev_version, clust_index, clust_offsets_, true,
+ prev_version, clust_index, clust_offsets_,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, &heap);
vers_del = rec_get_deleted_flag(prev_version, comp);
@@ -553,7 +555,8 @@ row_vers_build_cur_vrow_low(
clust_offsets = rec_get_offsets(prev_version, clust_index,
NULL,
- true, ULINT_UNDEFINED, &heap);
+ clust_index->n_core_fields,
+ ULINT_UNDEFINED, &heap);
ulint entry_len = dict_index_get_n_fields(index);
@@ -694,7 +697,8 @@ row_vers_vc_matches_cluster(
clust_offsets = rec_get_offsets(prev_version, clust_index,
NULL,
- true, ULINT_UNDEFINED, &heap);
+ clust_index->n_core_fields,
+ ULINT_UNDEFINED, &heap);
ulint entry_len = dict_index_get_n_fields(index);
@@ -821,7 +825,8 @@ row_vers_build_cur_vrow(
index, roll_ptr, trx_id, v_heap, &cur_vrow, mtr);
}
- *clust_offsets = rec_get_offsets(rec, clust_index, NULL, true,
+ *clust_offsets = rec_get_offsets(rec, clust_index, NULL,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, &heap);
return(cur_vrow);
}
@@ -873,7 +878,8 @@ row_vers_old_has_index_entry(
comp = page_rec_is_comp(rec);
ut_ad(!dict_table_is_comp(index->table) == !comp);
heap = mem_heap_create(1024);
- clust_offsets = rec_get_offsets(rec, clust_index, NULL, true,
+ clust_offsets = rec_get_offsets(rec, clust_index, NULL,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (dict_index_has_virtual(index)) {
@@ -951,7 +957,8 @@ row_vers_old_has_index_entry(
}
}
clust_offsets = rec_get_offsets(rec, clust_index, NULL,
- true,
+ clust_index
+ ->n_core_fields,
ULINT_UNDEFINED, &heap);
} else {
@@ -1026,7 +1033,8 @@ unsafe_to_purge:
}
clust_offsets = rec_get_offsets(prev_version, clust_index,
- NULL, true,
+ NULL,
+ clust_index->n_core_fields,
ULINT_UNDEFINED, &heap);
if (dict_index_has_virtual(index)) {
@@ -1166,7 +1174,7 @@ row_vers_build_for_consistent_read(
*offsets = rec_get_offsets(
prev_version, index, *offsets,
- true, ULINT_UNDEFINED, offset_heap);
+ index->n_core_fields, ULINT_UNDEFINED, offset_heap);
#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
ut_a(!rec_offs_any_null_extern(prev_version, *offsets));
@@ -1281,11 +1289,10 @@ committed_version_trx:
semi-consistent read. */
version = rec;
- *offsets = rec_get_offsets(version,
- index, *offsets,
- true,
- ULINT_UNDEFINED,
- offset_heap);
+ *offsets = rec_get_offsets(
+ version, index, *offsets,
+ index->n_core_fields, ULINT_UNDEFINED,
+ offset_heap);
}
buf = static_cast<byte*>(
@@ -1328,7 +1335,8 @@ committed_version_trx:
}
version = prev_version;
- *offsets = rec_get_offsets(version, index, *offsets, true,
+ *offsets = rec_get_offsets(version, index, *offsets,
+ index->n_core_fields,
ULINT_UNDEFINED, offset_heap);
#if defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
ut_a(!rec_offs_any_null_extern(version, *offsets));
diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc
index 4ae427b767d..d1eaea3095e 100644
--- a/storage/innobase/srv/srv0start.cc
+++ b/storage/innobase/srv/srv0start.cc
@@ -1575,7 +1575,7 @@ file_checked:
to the data files and truncate or delete the log.
Unless --export is specified, no further change to
InnoDB files is needed. */
- ut_ad(!srv_force_recovery);
+ ut_ad(srv_force_recovery <= SRV_FORCE_IGNORE_CORRUPT);
ut_ad(recv_no_log_write);
err = fil_write_flushed_lsn(log_sys.get_lsn());
DBUG_ASSERT(!buf_pool.any_io_pending());
diff --git a/storage/innobase/trx/trx0i_s.cc b/storage/innobase/trx/trx0i_s.cc
index b79c1169d33..f40ac9fedbe 100644
--- a/storage/innobase/trx/trx0i_s.cc
+++ b/storage/innobase/trx/trx0i_s.cc
@@ -654,7 +654,8 @@ fill_lock_data(
ut_a(n_fields > 0);
heap = NULL;
- offsets = rec_get_offsets(rec, index, offsets, true, n_fields, &heap);
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
+ n_fields, &heap);
/* format and store the data */
diff --git a/storage/innobase/trx/trx0rec.cc b/storage/innobase/trx/trx0rec.cc
index 1e7dfbed032..683825559a3 100644
--- a/storage/innobase/trx/trx0rec.cc
+++ b/storage/innobase/trx/trx0rec.cc
@@ -2533,7 +2533,8 @@ trx_undo_prev_version_build(
rec_offs offsets_dbg[REC_OFFS_NORMAL_SIZE];
rec_offs_init(offsets_dbg);
ut_a(!rec_offs_any_null_extern(
- *old_vers, rec_get_offsets(*old_vers, index, offsets_dbg, true,
+ *old_vers, rec_get_offsets(*old_vers, index, offsets_dbg,
+ index->n_core_fields,
ULINT_UNDEFINED, &heap)));
#endif // defined UNIV_DEBUG || defined UNIV_BLOB_LIGHT_DEBUG
diff --git a/storage/innobase/trx/trx0sys.cc b/storage/innobase/trx/trx0sys.cc
index 551ff4b9f3d..6b7a9e98d46 100644
--- a/storage/innobase/trx/trx0sys.cc
+++ b/storage/innobase/trx/trx0sys.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2020, MariaDB Corporation.
+Copyright (c) 2017, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
diff --git a/storage/innobase/ut/ut0ut.cc b/storage/innobase/ut/ut0ut.cc
index b0738b899fb..b6ad91babe4 100644
--- a/storage/innobase/ut/ut0ut.cc
+++ b/storage/innobase/ut/ut0ut.cc
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1994, 2017, Oracle and/or its affiliates. All Rights Reserved.
-Copyright (c) 2017, 2020, MariaDB Corporation.
+Copyright (c) 2017, 2021, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -586,7 +586,7 @@ const char * dbug_print_rec(const rec_t* rec, dict_index_t* index)
rec_offs* offsets = offsets_;
rec_offs_init(offsets_);
mem_heap_t* tmp_heap = NULL;
- offsets = rec_get_offsets(rec, index, offsets, true,
+ offsets = rec_get_offsets(rec, index, offsets, index->n_core_fields,
ULINT_UNDEFINED, &tmp_heap);
rec_printer r(rec, offsets);
strmake(dbug_print_buf, r.str().c_str(), sizeof(dbug_print_buf) - 1);